mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 09:53:04 +03:00
Allow setting up git hooks from other worktrees
This commit is contained in:
+11
-3
@@ -1,5 +1,6 @@
|
||||
use crate::t;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::{
|
||||
env, fmt, fs,
|
||||
@@ -155,10 +156,17 @@ fn install_git_hook_maybe(src_path: &Path) -> io::Result<()> {
|
||||
|
||||
Ok(if should_install {
|
||||
let src = src_path.join("src").join("etc").join("pre-commit.sh");
|
||||
let dst = src_path.join(".git").join("hooks").join("pre-commit");
|
||||
match fs::hard_link(src, dst) {
|
||||
let git = t!(Command::new("git").args(&["rev-parse", "--git-common-dir"]).output().map(
|
||||
|output| {
|
||||
assert!(output.status.success(), "failed to run `git`");
|
||||
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
|
||||
}
|
||||
));
|
||||
let dst = git.join("hooks").join("pre-commit");
|
||||
match fs::hard_link(src, &dst) {
|
||||
Err(e) => println!(
|
||||
"x.py encountered an error -- do you already have the git hook installed?\n{}",
|
||||
"error: could not create hook {}: do you already have the git hook installed?\n{}",
|
||||
dst.display(),
|
||||
e
|
||||
),
|
||||
Ok(_) => println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`"),
|
||||
|
||||
Reference in New Issue
Block a user