Skip to content

Commit 24907f3

Browse files
authored
Rollup merge of #77778 - jyn514:git-hook, r=mark-simulacrum
[x.py setup] Allow setting up git hooks from other worktrees Closes #77684 r? @caass
2 parents b09ef11 + bd13567 commit 24907f3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/bootstrap/setup.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{t, VERSION};
22
use std::fmt::Write as _;
33
use std::path::{Path, PathBuf};
4+
use std::process::Command;
45
use std::str::FromStr;
56
use std::{
67
env, fmt, fs,
@@ -196,10 +197,17 @@ simply delete the `pre-commit` file from .git/hooks."
196197

197198
Ok(if should_install {
198199
let src = src_path.join("src").join("etc").join("pre-commit.sh");
199-
let dst = src_path.join(".git").join("hooks").join("pre-commit");
200-
match fs::hard_link(src, dst) {
200+
let git = t!(Command::new("git").args(&["rev-parse", "--git-common-dir"]).output().map(
201+
|output| {
202+
assert!(output.status.success(), "failed to run `git`");
203+
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
204+
}
205+
));
206+
let dst = git.join("hooks").join("pre-commit");
207+
match fs::hard_link(src, &dst) {
201208
Err(e) => println!(
202-
"x.py encountered an error -- do you already have the git hook installed?\n{}",
209+
"error: could not create hook {}: do you already have the git hook installed?\n{}",
210+
dst.display(),
203211
e
204212
),
205213
Ok(_) => println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`"),

0 commit comments

Comments
 (0)