aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/main.rs15
-rw-r--r--xtask/src/pre_commit.rs38
2 files changed, 0 insertions, 53 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 48c0d9920..84b17ce23 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -15,7 +15,6 @@ mod tidy;
15mod install; 15mod install;
16mod release; 16mod release;
17mod dist; 17mod dist;
18mod pre_commit;
19mod metrics; 18mod metrics;
20mod pre_cache; 19mod pre_cache;
21 20
@@ -39,10 +38,6 @@ use crate::{
39}; 38};
40 39
41fn main() -> Result<()> { 40fn main() -> Result<()> {
42 if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) {
43 return pre_commit::run_hook();
44 }
45
46 let _d = pushd(project_root())?; 41 let _d = pushd(project_root())?;
47 42
48 let mut args = Arguments::from_env(); 43 let mut args = Arguments::from_env();
@@ -103,14 +98,6 @@ FLAGS:
103 finish_args(args)?; 98 finish_args(args)?;
104 CodegenCmd { features }.run() 99 CodegenCmd { features }.run()
105 } 100 }
106 "format" => {
107 finish_args(args)?;
108 run_rustfmt(Mode::Overwrite)
109 }
110 "install-pre-commit-hook" => {
111 finish_args(args)?;
112 pre_commit::install_hook()
113 }
114 "lint" => { 101 "lint" => {
115 finish_args(args)?; 102 finish_args(args)?;
116 run_clippy() 103 run_clippy()
@@ -164,8 +151,6 @@ USAGE:
164 cargo xtask <SUBCOMMAND> 151 cargo xtask <SUBCOMMAND>
165 152
166SUBCOMMANDS: 153SUBCOMMANDS:
167 format
168 install-pre-commit-hook
169 fuzz-tests 154 fuzz-tests
170 codegen 155 codegen
171 install 156 install
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}