diff --git a/docs/dev/README.md b/docs/dev/README.md index d6fae52959..b91013f137 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. We use bors-ng to enforce the [not rocket science](https://graydon2.dreamwidth.org/1597.html) rule. -You can run `cargo xtask install-pre-commit-hook` to install git-hook to run rustfmt on commit. - # Launching rust-analyzer Debugging the language server can be tricky. diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 48c0d99206..84b17ce230 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -15,7 +15,6 @@ mod tidy; mod install; mod release; mod dist; -mod pre_commit; mod metrics; mod pre_cache; @@ -39,10 +38,6 @@ use crate::{ }; fn main() -> Result<()> { - if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) { - return pre_commit::run_hook(); - } - let _d = pushd(project_root())?; let mut args = Arguments::from_env(); @@ -103,14 +98,6 @@ FLAGS: finish_args(args)?; CodegenCmd { features }.run() } - "format" => { - finish_args(args)?; - run_rustfmt(Mode::Overwrite) - } - "install-pre-commit-hook" => { - finish_args(args)?; - pre_commit::install_hook() - } "lint" => { finish_args(args)?; run_clippy() @@ -164,8 +151,6 @@ USAGE: cargo xtask SUBCOMMANDS: - format - install-pre-commit-hook fuzz-tests codegen install diff --git a/xtask/src/pre_commit.rs b/xtask/src/pre_commit.rs deleted file mode 100644 index b57cf3ce2b..0000000000 --- a/xtask/src/pre_commit.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! pre-commit hook for code formatting. - -use std::{fs, path::PathBuf}; - -use anyhow::{bail, Result}; -use xshell::cmd; - -use crate::{project_root, run_rustfmt, Mode}; - -// FIXME: if there are changed `.ts` files, also reformat TypeScript (by -// shelling out to `npm fmt`). -pub(crate) fn run_hook() -> Result<()> { - run_rustfmt(Mode::Overwrite)?; - - let diff = cmd!("git diff --diff-filter=MAR --name-only --cached").read()?; - - let root = project_root(); - for line in diff.lines() { - let file = root.join(line); - cmd!("git update-index --add {file}").run()?; - } - - Ok(()) -} - -pub(crate) fn install_hook() -> Result<()> { - let hook_path: PathBuf = - format!("./.git/hooks/pre-commit{}", std::env::consts::EXE_SUFFIX).into(); - - if hook_path.exists() { - bail!("Git hook already created"); - } - - let me = std::env::current_exe()?; - fs::copy(me, hook_path)?; - - Ok(()) -}