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;
2
2
use std:: path:: { Path , PathBuf } ;
3
+ use std:: process:: Command ;
3
4
use std:: str:: FromStr ;
4
5
use std:: {
5
6
env, fmt, fs,
@@ -155,10 +156,17 @@ simply delete the `pre-commit` file from .git/hooks."
155
156
156
157
Ok ( if should_install {
157
158
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) {
160
167
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( ) ,
162
170
e
163
171
) ,
164
172
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