File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 11use crate :: t;
22use std:: path:: { Path , PathBuf } ;
3+ use std:: process:: Command ;
34use std:: str:: FromStr ;
45use 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`" ) ,
You can’t perform that action at this time.
0 commit comments