@@ -46,8 +46,12 @@ pub fn setup(src_path: &Path, include_name: &str) {
4646 _ => return ,
4747 } ;
4848
49+ println ! ( ) ;
50+
4951 t ! ( install_git_hook_maybe( src_path) ) ;
5052
53+ println ! ( ) ;
54+
5155 println ! ( "To get started, try one of the following commands:" ) ;
5256 for cmd in suggestions {
5357 println ! ( "- `x.py {}`" , cmd) ;
@@ -102,10 +106,10 @@ simply delete the `pre-commit` file from .git/hooks."
102106 let should_install = loop {
103107 print ! ( "Would you like to install the git hook?: [y/N] " ) ;
104108 io:: stdout ( ) . flush ( ) ?;
109+ input. clear ( ) ;
105110 io:: stdin ( ) . read_line ( & mut input) ?;
106111 break match input. trim ( ) . to_lowercase ( ) . as_str ( ) {
107112 "y" | "yes" => true ,
108- // is this the right way to check for "entered nothing"?
109113 "n" | "no" | "" => false ,
110114 _ => {
111115 println ! ( "error: unrecognized option '{}'" , input. trim( ) ) ;
@@ -115,14 +119,17 @@ simply delete the `pre-commit` file from .git/hooks."
115119 } ;
116120 } ;
117121
118- if should_install {
119- let src = src_path. join ( "/etc/pre-commit.rs" ) ;
120- let dst = src_path. join ( "/.git/hooks/pre-commit" ) ;
121- fs:: hard_link ( src, dst) ?;
122- println ! ( "Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`" ) ;
122+ Ok ( if should_install {
123+ let src = src_path. join ( "src" ) . join ( "etc" ) . join ( "pre-commit.sh" ) ;
124+ let dst = src_path. join ( ".git" ) . join ( "hooks" ) . join ( "pre-commit" ) ;
125+ match fs:: hard_link ( src, dst) {
126+ Err ( e) => println ! (
127+ "x.py encountered an error -- do you already have the git hook installed?\n {}" ,
128+ e
129+ ) ,
130+ Ok ( _) => println ! ( "Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`" ) ,
131+ } ;
123132 } else {
124133 println ! ( "Ok, skipping installation!" ) ;
125- } ;
126-
127- Ok ( ( ) )
134+ } )
128135}
0 commit comments