File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: { t, VERSION } ;
2
2
use std:: fmt:: Write as _;
3
3
use std:: path:: { Path , PathBuf } ;
4
+ use std:: process:: Command ;
4
5
use std:: str:: FromStr ;
5
6
use std:: {
6
7
env, fmt, fs,
@@ -196,10 +197,17 @@ simply delete the `pre-commit` file from .git/hooks."
196
197
197
198
Ok ( if should_install {
198
199
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) {
201
208
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( ) ,
203
211
e
204
212
) ,
205
213
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