about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2020-10-20 12:11:00 +0900
committerGitHub <noreply@github.com>2020-10-20 12:11:00 +0900
commit24907f3507de7ce5d6908e3003e06a7f0b1a2ab6 (patch)
tree353a3ff9f47df8d90008bd95aa458a6826248d6a
parentb09ef114bbd5f057803fc99f0b78a01e7c1138fa (diff)
parentbd135674814d74ca6fca3ab79d778ecaaeb02cf5 (diff)
downloadrust-24907f3507de7ce5d6908e3003e06a7f0b1a2ab6.tar.gz
rust-24907f3507de7ce5d6908e3003e06a7f0b1a2ab6.zip
Rollup merge of #77778 - jyn514:git-hook, r=mark-simulacrum
[x.py setup] Allow setting up git hooks from other worktrees

Closes https://github.com/rust-lang/rust/issues/77684
r? @caass
-rw-r--r--src/bootstrap/setup.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/bootstrap/setup.rs b/src/bootstrap/setup.rs
index a281061ace1..c6e1c99564c 100644
--- a/src/bootstrap/setup.rs
+++ b/src/bootstrap/setup.rs
@@ -1,6 +1,7 @@
 use crate::{t, VERSION};
 use std::fmt::Write as _;
 use std::path::{Path, PathBuf};
+use std::process::Command;
 use std::str::FromStr;
 use std::{
     env, fmt, fs,
@@ -196,10 +197,17 @@ simply delete the `pre-commit` file from .git/hooks."
 
     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`"),