]> git.lizzy.rs Git - rust.git/commitdiff
Make changes based on @jyn514's comments
authorCassandra Fridkin <cass@swag.lgbt>
Tue, 6 Oct 2020 02:00:43 +0000 (22:00 -0400)
committerCassandra Fridkin <cass@swag.lgbt>
Tue, 6 Oct 2020 02:00:43 +0000 (22:00 -0400)
src/bootstrap/setup.rs

index f5ec1d6d247d7481b3e90a20a10a1c2a2777dfb7..cbf53dae8060860300345f267304fa0061fc0fcd 100644 (file)
@@ -46,8 +46,12 @@ pub fn setup(src_path: &Path, include_name: &str) {
         _ => return,
     };
 
+    println!();
+
     t!(install_git_hook_maybe(src_path));
 
+    println!();
+
     println!("To get started, try one of the following commands:");
     for cmd in suggestions {
         println!("- `x.py {}`", cmd);
@@ -102,10 +106,10 @@ fn install_git_hook_maybe(src_path: &Path) -> io::Result<()> {
     let should_install = loop {
         print!("Would you like to install the git hook?: [y/N] ");
         io::stdout().flush()?;
+        input.clear();
         io::stdin().read_line(&mut input)?;
         break match input.trim().to_lowercase().as_str() {
             "y" | "yes" => true,
-            // is this the right way to check for "entered nothing"?
             "n" | "no" | "" => false,
             _ => {
                 println!("error: unrecognized option '{}'", input.trim());
@@ -115,14 +119,17 @@ fn install_git_hook_maybe(src_path: &Path) -> io::Result<()> {
         };
     };
 
-    if should_install {
-        let src = src_path.join("/etc/pre-commit.rs");
-        let dst = src_path.join("/.git/hooks/pre-commit");
-        fs::hard_link(src, dst)?;
-        println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`");
+    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) {
+            Err(e) => println!(
+                "x.py encountered an error -- do you already have the git hook installed?\n{}",
+                e
+            ),
+            Ok(_) => println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`"),
+        };
     } else {
         println!("Ok, skipping installation!");
-    };
-
-    Ok(())
+    })
 }