From 979c26e1aebee85e664899235d5fbc67ca26d6e8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 1 Mar 2021 21:29:40 +0300 Subject: Axe pre-commit --- docs/dev/README.md | 2 -- xtask/src/main.rs | 15 --------------- xtask/src/pre_commit.rs | 38 -------------------------------------- 3 files changed, 55 deletions(-) delete mode 100644 xtask/src/pre_commit.rs 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. 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 48c0d9920..84b17ce23 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 b57cf3ce2..000000000 --- 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(()) -} -- cgit v1.2.3