about summary refs log tree commit diff
path: root/clippy_dev/src/setup/git_hook.rs
diff options
context:
space:
mode:
authorxFrednet <xFrednet@gmail.com>2021-06-23 19:04:09 +0200
committerflip1995 <philipp.krones@embecosm.com>2021-06-25 11:17:00 +0200
commit8e969cdcefefe6792537dac11855bc5f91904f0b (patch)
tree5674719c69bbd8d38d52efd4076b17701f862cca /clippy_dev/src/setup/git_hook.rs
parentf0fa3636536f3843fee2315fc062aa022479fdee (diff)
downloadrust-8e969cdcefefe6792537dac11855bc5f91904f0b.tar.gz
rust-8e969cdcefefe6792537dac11855bc5f91904f0b.zip
Updated several clippy_dev messages and types (PR suggestions)
Co-authored-by: Philipp Krones <hello@philkrones.com>
Diffstat (limited to 'clippy_dev/src/setup/git_hook.rs')
-rw-r--r--clippy_dev/src/setup/git_hook.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/clippy_dev/src/setup/git_hook.rs b/clippy_dev/src/setup/git_hook.rs
index beb07a073fe..f27b69a195b 100644
--- a/clippy_dev/src/setup/git_hook.rs
+++ b/clippy_dev/src/setup/git_hook.rs
@@ -10,7 +10,7 @@ const HOOK_SOURCE_FILE: &str = "util/etc/pre-commit.sh";
 const HOOK_TARGET_FILE: &str = ".git/hooks/pre-commit";
 
 pub fn install_hook(force_override: bool) {
-    if check_precondition(force_override).is_err() {
+    if !check_precondition(force_override) {
         return;
     }
 
@@ -25,52 +25,55 @@ pub fn install_hook(force_override: bool) {
     // include the `execute` permission.
     match fs::copy(HOOK_SOURCE_FILE, HOOK_TARGET_FILE) {
         Ok(_) => {
-            println!("note: the hook can be removed with `cargo dev remove git-hook`");
-            println!("Git hook successfully installed :)");
+            println!("info: the hook can be removed with `cargo dev remove git-hook`");
+            println!("git hook successfully installed");
         },
-        Err(err) => println!(
+        Err(err) => eprintln!(
             "error: unable to copy `{}` to `{}` ({})",
             HOOK_SOURCE_FILE, HOOK_TARGET_FILE, err
         ),
     }
 }
 
-fn check_precondition(force_override: bool) -> Result<(), ()> {
+fn check_precondition(force_override: bool) -> bool {
     // Make sure that we can find the git repository
     let git_path = Path::new(REPO_GIT_DIR);
     if !git_path.exists() || !git_path.is_dir() {
-        println!("error: clippy_dev was unable to find the `.git` directory");
-        return Err(());
+        eprintln!("error: clippy_dev was unable to find the `.git` directory");
+        return false;
     }
 
     // Make sure that we don't override an existing hook by accident
     let path = Path::new(HOOK_TARGET_FILE);
     if path.exists() {
-        if force_override || super::ask_yes_no_question("Do you want to override the existing pre-commit hook it?") {
+        if force_override {
             return delete_git_hook_file(path);
         }
-        return Err(());
+
+        eprintln!("error: there is already a pre-commit hook installed");
+        println!("info: use the `--force-override` flag to override the existing hook");
+        return false;
     }
 
-    Ok(())
+    true
 }
 
 pub fn remove_hook() {
     let path = Path::new(HOOK_TARGET_FILE);
     if path.exists() {
-        if delete_git_hook_file(path).is_ok() {
-            println!("Git hook successfully removed :)");
+        if delete_git_hook_file(path) {
+            println!("git hook successfully removed");
         }
     } else {
-        println!("No pre-commit hook was found. You're good to go :)");
+        println!("no pre-commit hook was found");
     }
 }
 
-fn delete_git_hook_file(path: &Path) -> Result<(), ()> {
-    if fs::remove_file(path).is_err() {
-        println!("error: unable to delete existing pre-commit git hook");
-        Err(())
+fn delete_git_hook_file(path: &Path) -> bool {
+    if let Err(err) = fs::remove_file(path) {
+        eprintln!("error: unable to delete existing pre-commit git hook ({})", err);
+        false
     } else {
-        Ok(())
+        true
     }
 }