]> git.lizzy.rs Git - rust.git/commitdiff
Ignore untracked paths when running `rustfmt` on repository.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Thu, 27 Feb 2020 20:52:09 +0000 (15:52 -0500)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Thu, 27 Feb 2020 20:52:09 +0000 (15:52 -0500)
src/bootstrap/format.rs

index 6e5e3fe07e7467065abd36bbef79a49863ce1c33..a4acb14ee4b149fdf141441764a8f8a4985dbadc 100644 (file)
@@ -1,7 +1,7 @@
 //! Runs rustfmt on the repository.
 
 use crate::Build;
-use build_helper::t;
+use build_helper::{output, t};
 use ignore::WalkBuilder;
 use std::path::Path;
 use std::process::Command;
@@ -53,6 +53,17 @@ pub fn format(build: &Build, check: bool) {
     for ignore in rustfmt_config.ignore {
         ignore_fmt.add(&format!("!{}", ignore)).expect(&ignore);
     }
+    let untracked_paths_output = output(
+        Command::new("git").arg("status").arg("--porcelain").arg("--untracked-files=normal"),
+    );
+    let untracked_paths = untracked_paths_output
+        .lines()
+        .filter(|entry| entry.starts_with("??"))
+        .map(|entry| entry.split(" ").nth(1).expect("every git status entry should list a path"));
+    for untracked_path in untracked_paths {
+        eprintln!("skip untracked path {} during rustfmt invocations", untracked_path);
+        ignore_fmt.add(&format!("!{}", untracked_path)).expect(&untracked_path);
+    }
     let ignore_fmt = ignore_fmt.build().unwrap();
 
     let rustfmt_path = build.config.initial_rustfmt.as_ref().unwrap_or_else(|| {