diff options
Diffstat (limited to 'xtask/src/lib.rs')
-rw-r--r-- | xtask/src/lib.rs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index bfee2f9c8..7332a4072 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -83,19 +83,12 @@ pub fn install_rustfmt() -> Result<()> { | |||
83 | run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") | 83 | run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") |
84 | } | 84 | } |
85 | 85 | ||
86 | pub fn install_format_hook() -> Result<()> { | 86 | pub fn install_pre_commit_hook() -> Result<()> { |
87 | let result_path = Path::new(if cfg!(windows) { | 87 | let result_path = |
88 | "./.git/hooks/pre-commit.exe" | 88 | PathBuf::from(format!("./.git/hooks/pre-commit{}", std::env::consts::EXE_SUFFIX)); |
89 | } else { | ||
90 | "./.git/hooks/pre-commit" | ||
91 | }); | ||
92 | if !result_path.exists() { | 89 | if !result_path.exists() { |
93 | run("cargo build --package xtask --bin pre-commit", ".")?; | 90 | let me = std::env::current_exe()?; |
94 | if cfg!(windows) { | 91 | fs::copy(me, result_path)?; |
95 | fs::copy("./target/debug/pre-commit.exe", result_path)?; | ||
96 | } else { | ||
97 | fs::copy("./target/debug/pre-commit", result_path)?; | ||
98 | } | ||
99 | } else { | 92 | } else { |
100 | Err(IoError::new(ErrorKind::AlreadyExists, "Git hook already created"))?; | 93 | Err(IoError::new(ErrorKind::AlreadyExists, "Git hook already created"))?; |
101 | } | 94 | } |
@@ -150,6 +143,27 @@ pub fn run_fuzzer() -> Result<()> { | |||
150 | run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") | 143 | run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") |
151 | } | 144 | } |
152 | 145 | ||
146 | pub fn reformat_staged_files() -> Result<()> { | ||
147 | let root = project_root(); | ||
148 | let output = Command::new("git") | ||
149 | .arg("diff") | ||
150 | .arg("--diff-filter=MAR") | ||
151 | .arg("--name-only") | ||
152 | .arg("--cached") | ||
153 | .current_dir(&root) | ||
154 | .output()?; | ||
155 | if !output.status.success() { | ||
156 | anyhow::bail!( | ||
157 | "`git diff --diff-filter=MAR --name-only --cached` exited with {}", | ||
158 | output.status | ||
159 | ); | ||
160 | } | ||
161 | for line in String::from_utf8(output.stdout)?.lines() { | ||
162 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; | ||
163 | } | ||
164 | Ok(()) | ||
165 | } | ||
166 | |||
153 | fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> | 167 | fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> |
154 | where | 168 | where |
155 | F: FnMut(&mut Command), | 169 | F: FnMut(&mut Command), |