diff options
Diffstat (limited to 'xtask/src/pre_commit.rs')
-rw-r--r-- | xtask/src/pre_commit.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/xtask/src/pre_commit.rs b/xtask/src/pre_commit.rs index 056f34acf..8f2dbea19 100644 --- a/xtask/src/pre_commit.rs +++ b/xtask/src/pre_commit.rs | |||
@@ -3,19 +3,21 @@ | |||
3 | use std::{fs, path::PathBuf}; | 3 | use std::{fs, path::PathBuf}; |
4 | 4 | ||
5 | use anyhow::{bail, Result}; | 5 | use anyhow::{bail, Result}; |
6 | use xshell::cmd; | ||
6 | 7 | ||
7 | use crate::{not_bash::run, project_root, run_rustfmt, Mode}; | 8 | use crate::{project_root, run_rustfmt, Mode}; |
8 | 9 | ||
9 | // FIXME: if there are changed `.ts` files, also reformat TypeScript (by | 10 | // FIXME: if there are changed `.ts` files, also reformat TypeScript (by |
10 | // shelling out to `npm fmt`). | 11 | // shelling out to `npm fmt`). |
11 | pub fn run_hook() -> Result<()> { | 12 | pub fn run_hook() -> Result<()> { |
12 | run_rustfmt(Mode::Overwrite)?; | 13 | run_rustfmt(Mode::Overwrite)?; |
13 | 14 | ||
14 | let diff = run!("git diff --diff-filter=MAR --name-only --cached")?; | 15 | let diff = cmd!("git diff --diff-filter=MAR --name-only --cached").read()?; |
15 | 16 | ||
16 | let root = project_root(); | 17 | let root = project_root(); |
17 | for line in diff.lines() { | 18 | for line in diff.lines() { |
18 | run!("git update-index --add {}", root.join(line).display())?; | 19 | let file = root.join(line); |
20 | cmd!("git update-index --add {file}").run()?; | ||
19 | } | 21 | } |
20 | 22 | ||
21 | Ok(()) | 23 | Ok(()) |