diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-01 18:30:46 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-01 18:30:46 +0000 |
commit | 9860a396035f61a5cc9265c1104a640547bded51 (patch) | |
tree | 0653d4a9a0c5cfed7f9016e21727f49dae7051a5 | |
parent | 5efb7f85eb24c7ad76136a7d81e8f8cffe213aa8 (diff) | |
parent | 979c26e1aebee85e664899235d5fbc67ca26d6e8 (diff) |
Merge #7832
7832: Axe pre-commit r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | docs/dev/README.md | 2 | ||||
-rw-r--r-- | xtask/src/main.rs | 15 | ||||
-rw-r--r-- | xtask/src/pre_commit.rs | 38 |
3 files changed, 0 insertions, 55 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md index d6fae5295..b91013f13 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -58,8 +58,6 @@ Use `env RUN_SLOW_TESTS=1 cargo test` to run the full suite. | |||
58 | 58 | ||
59 | We use bors-ng to enforce the [not rocket science](https://graydon2.dreamwidth.org/1597.html) rule. | 59 | We use bors-ng to enforce the [not rocket science](https://graydon2.dreamwidth.org/1597.html) rule. |
60 | 60 | ||
61 | You can run `cargo xtask install-pre-commit-hook` to install git-hook to run rustfmt on commit. | ||
62 | |||
63 | # Launching rust-analyzer | 61 | # Launching rust-analyzer |
64 | 62 | ||
65 | Debugging the language server can be tricky. | 63 | Debugging the language server can be tricky. |
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; | |||
15 | mod install; | 15 | mod install; |
16 | mod release; | 16 | mod release; |
17 | mod dist; | 17 | mod dist; |
18 | mod pre_commit; | ||
19 | mod metrics; | 18 | mod metrics; |
20 | mod pre_cache; | 19 | mod pre_cache; |
21 | 20 | ||
@@ -39,10 +38,6 @@ use crate::{ | |||
39 | }; | 38 | }; |
40 | 39 | ||
41 | fn main() -> Result<()> { | 40 | fn 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 | ||
166 | SUBCOMMANDS: | 153 | SUBCOMMANDS: |
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 | |||
3 | use std::{fs, path::PathBuf}; | ||
4 | |||
5 | use anyhow::{bail, Result}; | ||
6 | use xshell::cmd; | ||
7 | |||
8 | use 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`). | ||
12 | pub(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 | |||
26 | pub(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 | } | ||