Skip to content

Commit 4c9e44f

Browse files
authored
Rollup merge of #69527 - pnkfelix:issue-69291-dont-run-rustfmt-on-untracked-paths, r=Mark-Simulacrum
Ignore untracked paths when running `rustfmt` on repository. This is a step towards resolving #69291 (It might be the only step necessary at the moment; I'm not yet sure.)
2 parents 0291b6a + cac4eee commit 4c9e44f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/bootstrap/format.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Runs rustfmt on the repository.
22
33
use crate::Build;
4-
use build_helper::t;
4+
use build_helper::{output, t};
55
use ignore::WalkBuilder;
66
use std::path::Path;
77
use std::process::Command;
@@ -53,6 +53,17 @@ pub fn format(build: &Build, check: bool) {
5353
for ignore in rustfmt_config.ignore {
5454
ignore_fmt.add(&format!("!{}", ignore)).expect(&ignore);
5555
}
56+
let untracked_paths_output = output(
57+
Command::new("git").arg("status").arg("--porcelain").arg("--untracked-files=normal"),
58+
);
59+
let untracked_paths = untracked_paths_output
60+
.lines()
61+
.filter(|entry| entry.starts_with("??"))
62+
.map(|entry| entry.split(" ").nth(1).expect("every git status entry should list a path"));
63+
for untracked_path in untracked_paths {
64+
eprintln!("skip untracked path {} during rustfmt invocations", untracked_path);
65+
ignore_fmt.add(&format!("!{}", untracked_path)).expect(&untracked_path);
66+
}
5667
let ignore_fmt = ignore_fmt.build().unwrap();
5768

5869
let rustfmt_path = build.config.initial_rustfmt.as_ref().unwrap_or_else(|| {

0 commit comments

Comments
 (0)