Repository navigation
diff: pair identical names first with --ignore-file-name-case #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -818,6 +818,64 @@ fn directory_name_matching() -> Result<(), Box<dyn std::error::Error>> { | |
| Ok(()) | ||
| } | ||
|
|
||
| // Among names differing only by case, the one that is the same on both sides | ||
| // is the counterpart, whichever sorts first. | ||
| #[test] | ||
| fn ignore_file_name_case_prefers_exact_match() -> Result<(), Box<dyn std::error::Error>> { | ||
| let tmp_dir = tempdir()?; | ||
| let dir = tmp_dir.path(); | ||
| std::fs::create_dir(dir.join("one"))?; | ||
| std::fs::create_dir(dir.join("two"))?; | ||
| std::fs::write(dir.join("one/f"), "same\n")?; | ||
| std::fs::write(dir.join("two/f"), "same\n")?; | ||
| std::fs::write(dir.join("two/F"), "other\n")?; | ||
| if std::fs::read_dir(dir.join("two"))?.count() != 2 { | ||
| // The file system is not case-sensitive. | ||
| return Ok(()); | ||
| } | ||
|
|
||
| for (from, to, only_in) in [("one", "two", "two"), ("two", "one", "two")] { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you run the GNU testsuite against this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had not, sorry. I ran the whole suite now, on this branch and on its base commit: 19 pass / 10 fail / 4 skip on both, with the same failures. Of the tests that use |
||
| let mut cmd = cargo_bin_cmd!("diffutils"); | ||
| cmd.current_dir(dir).arg("diff").arg("-r"); | ||
| cmd.arg("--ignore-file-name-case").arg(from).arg(to); | ||
| cmd.assert() | ||
| .code(predicate::eq(1)) | ||
| .stdout(format!("Only in {only_in}: F\n")); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn ignore_file_name_case_reports_unpaired_after_pairs() -> Result<(), Box<dyn std::error::Error>> { | ||
| let tmp_dir = tempdir()?; | ||
| let dir = tmp_dir.path(); | ||
| std::fs::create_dir(dir.join("one"))?; | ||
| std::fs::create_dir(dir.join("two"))?; | ||
| std::fs::write(dir.join("one/B"), "1\n")?; | ||
| std::fs::write(dir.join("one/b"), "1\n")?; | ||
| std::fs::write(dir.join("two/b"), "2\n")?; | ||
| std::fs::write(dir.join("one/c"), "1\n")?; | ||
| std::fs::write(dir.join("two/C"), "2\n")?; | ||
| std::fs::write(dir.join("two/c"), "2\n")?; | ||
| if std::fs::read_dir(dir.join("one"))?.count() != 3 { | ||
| // The file system is not case-sensitive. | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let mut cmd = cargo_bin_cmd!("diffutils"); | ||
| cmd.current_dir(dir).arg("diff").arg("-r"); | ||
| cmd.arg("--ignore-file-name-case").arg("one").arg("two"); | ||
| cmd.assert().code(predicate::eq(1)).stdout(concat!( | ||
| "diff -r --ignore-file-name-case one/b two/b\n", | ||
| "1c1\n< 1\n---\n> 2\n", | ||
| "Only in one: B\n", | ||
| "diff -r --ignore-file-name-case one/c two/c\n", | ||
| "1c1\n< 1\n---\n> 2\n", | ||
| "Only in two: C\n", | ||
| )); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(unix)] | ||
| #[test] | ||
| fn no_dereference() -> Result<(), Box<dyn std::error::Error>> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a group the "Only in" for the
toside now comes after all the pairs, not in sort orderwith one/a and two/{A,a} we print the diff of a before "Only in two: A", is that what GNU does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes for that case: GNU diff 3.12 prints the diff of
aand thenOnly in two: A, whichever ofA/ais created first. But checking a few more layouts showed thefromside was wrong: withone/{B,b}andtwo/b, GNU prints thebdiff beforeOnly in one: B, and I printed it after. GNU puts the unpaired names of a group after its pairs on both sides, so I changed that in 328168d and added a test with both sides.