Axe pre-commit

This commit is contained in:
Aleksey Kladov 2021-03-01 21:29:40 +03:00
parent 5efb7f85eb
commit 979c26e1ae
3 changed files with 0 additions and 55 deletions

View file

@ -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.

View file

@ -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 <SUBCOMMAND>
SUBCOMMANDS:
format
install-pre-commit-hook
fuzz-tests
codegen
install

View file

@ -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(())
}