aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/pre_commit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/pre_commit.rs')
-rw-r--r--xtask/src/pre_commit.rs38
1 files changed, 0 insertions, 38 deletions
diff --git a/xtask/src/pre_commit.rs b/xtask/src/pre_commit.rs
deleted file mode 100644
index b57cf3ce2..000000000
--- a/xtask/src/pre_commit.rs
+++ /dev/null
@@ -1,38 +0,0 @@
1//! pre-commit hook for code formatting.
2
3use std::{fs, path::PathBuf};
4
5use anyhow::{bail, Result};
6use xshell::cmd;
7
8use crate::{project_root, run_rustfmt, Mode};
9
10// FIXME: if there are changed `.ts` files, also reformat TypeScript (by
11// shelling out to `npm fmt`).
12pub(crate) fn run_hook() -> Result<()> {
13 run_rustfmt(Mode::Overwrite)?;
14
15 let diff = cmd!("git diff --diff-filter=MAR --name-only --cached").read()?;
16
17 let root = project_root();
18 for line in diff.lines() {
19 let file = root.join(line);
20 cmd!("git update-index --add {file}").run()?;
21 }
22
23 Ok(())
24}
25
26pub(crate) fn install_hook() -> Result<()> {
27 let hook_path: PathBuf =
28 format!("./.git/hooks/pre-commit{}", std::env::consts::EXE_SUFFIX).into();
29
30 if hook_path.exists() {
31 bail!("Git hook already created");
32 }
33
34 let me = std::env::current_exe()?;
35 fs::copy(me, hook_path)?;
36
37 Ok(())
38}