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 --- xtask/src/main.rs | 15 --------------- xtask/src/pre_commit.rs | 38 -------------------------------------- 2 files changed, 53 deletions(-) delete mode 100644 xtask/src/pre_commit.rs (limited to 'xtask') 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