Skip to content

[x.py setup] Allow setting up git hooks from other worktrees #77778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -155,10 +156,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`"),
Expand Down