Install hooks into .git/hooks/.
()
| 106 | |
| 107 | /// Install hooks into .git/hooks/. |
| 108 | fn install_hooks() -> CliResult<()> { |
| 109 | let hooks_dir = find_hooks_dir()?; |
| 110 | fs::create_dir_all(&hooks_dir).map_err(|e| CliError::GitError { |
| 111 | message: format!("Failed to create hooks directory: {}", e), |
| 112 | })?; |
| 113 | |
| 114 | let mut installed = 0; |
| 115 | let mut skipped = 0; |
| 116 | |
| 117 | for hook_name in HOOK_NAMES { |
| 118 | let hook_path = hooks_dir.join(hook_name); |
| 119 | match install_single_hook(&hook_path, hook_name) { |
| 120 | Ok(true) => installed += 1, |
| 121 | Ok(false) => skipped += 1, |
| 122 | Err(e) => { |
| 123 | print_warning(&format!("Failed to install {}: {}", hook_name, e)); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if installed > 0 { |
| 129 | print_info(&format!( |
| 130 | "Installed {} hook(s). {} already present.", |
| 131 | installed, skipped |
| 132 | )); |
| 133 | } else if skipped > 0 { |
| 134 | print_info("All hooks already installed."); |
| 135 | } |
| 136 | |
| 137 | Ok(()) |
| 138 | } |
| 139 | |
| 140 | /// Install a single hook. Returns Ok(true) if newly installed, Ok(false) if already present. |
| 141 | fn install_single_hook(path: &Path, _name: &str) -> Result<bool, std::io::Error> { |
no test coverage detected