Skip to content

Commit

Permalink
Fix a bug in x.py fmt that prevents some files being formatted.
Browse files Browse the repository at this point in the history
If you have a file in the repository root with the same name as a file
somewhere within a directory, the latter currently won't get formatted.

I have experienced this multiple times and not understood what was
happening; I finally figured out the problem today. This commit fixes
the problem.
  • Loading branch information
nnethercote committed Mar 3, 2022
1 parent 2f8d1a8 commit fc142eb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/bootstrap/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
});
for untracked_path in untracked_paths {
eprintln!("skip untracked path {} during rustfmt invocations", untracked_path);
ignore_fmt.add(&format!("!{}", untracked_path)).expect(&untracked_path);
// The leading `/` makes it an exact match against the
// repository root, rather than a glob. Without that, if you
// have `foo.rs` in the repository root it will also match
// against anything like `compiler/rustc_foo/src/foo.rs`,
// preventing the latter from being formatted.
ignore_fmt.add(&format!("!/{}", untracked_path)).expect(&untracked_path);
}
} else {
eprintln!("Not in git tree. Skipping git-aware format checks");
Expand Down

0 comments on commit fc142eb

Please sign in to comment.