Install hooks into .git/hooks/.
()
| 90 | |
| 91 | /// Install hooks into .git/hooks/. |
| 92 | fn install_hooks() -> CliResult<()> { |
| 93 | let hooks_dir = find_hooks_dir()?; |
| 94 | fs::create_dir_all(&hooks_dir).map_err(|e| CliError::GitError { |
| 95 | message: format!("Failed to create hooks directory: {}", e), |
| 96 | })?; |
| 97 | |
| 98 | let mut installed = 0; |
| 99 | let mut skipped = 0; |
| 100 | |
| 101 | for hook_name in HOOK_NAMES { |
| 102 | let hook_path = hooks_dir.join(hook_name); |
| 103 | match install_single_hook(&hook_path, hook_name) { |
| 104 | Ok(true) => installed += 1, |
| 105 | Ok(false) => skipped += 1, |
| 106 | Err(e) => { |
| 107 | print_warning(&format!("Failed to install {}: {}", hook_name, e)); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if installed > 0 { |
| 113 | print_info(&format!( |
| 114 | "Installed {} hook(s). {} already present.", |
| 115 | installed, skipped |
| 116 | )); |
| 117 | } else if skipped > 0 { |
| 118 | print_info("All hooks already installed."); |
| 119 | } |
| 120 | |
| 121 | Ok(()) |
| 122 | } |
| 123 | |
| 124 | /// Install a single hook. Returns Ok(true) if newly installed, Ok(false) if already present. |
| 125 | fn install_single_hook(path: &Path, _name: &str) -> Result<bool, std::io::Error> { |
no test coverage detected