Skip to content

Commit bd13567

Browse files
committed
Allow setting up git hooks from other worktrees
1 parent f498949 commit bd13567

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/bootstrap/setup.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::t;
22
use std::path::{Path, PathBuf};
3+
use std::process::Command;
34
use std::str::FromStr;
45
use std::{
56
env, fmt, fs,
@@ -155,10 +156,17 @@ simply delete the `pre-commit` file from .git/hooks."
155156

156157
Ok(if should_install {
157158
let src = src_path.join("src").join("etc").join("pre-commit.sh");
158-
let dst = src_path.join(".git").join("hooks").join("pre-commit");
159-
match fs::hard_link(src, dst) {
159+
let git = t!(Command::new("git").args(&["rev-parse", "--git-common-dir"]).output().map(
160+
|output| {
161+
assert!(output.status.success(), "failed to run `git`");
162+
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
163+
}
164+
));
165+
let dst = git.join("hooks").join("pre-commit");
166+
match fs::hard_link(src, &dst) {
160167
Err(e) => println!(
161-
"x.py encountered an error -- do you already have the git hook installed?\n{}",
168+
"error: could not create hook {}: do you already have the git hook installed?\n{}",
169+
dst.display(),
162170
e
163171
),
164172
Ok(_) => println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`"),

0 commit comments

Comments
 (0)