Remove the atomic:git:begin..end section from a hook file. Returns Ok(true) if something was removed.
(path: &Path)
| 188 | /// Remove the atomic:git:begin..end section from a hook file. |
| 189 | /// Returns Ok(true) if something was removed. |
| 190 | fn remove_atomic_section(path: &Path) -> Result<bool, std::io::Error> { |
| 191 | let content = fs::read_to_string(path)?; |
| 192 | if !content.contains(MARKER_BEGIN) { |
| 193 | return Ok(false); |
| 194 | } |
| 195 | |
| 196 | let mut result = String::new(); |
| 197 | let mut in_section = false; |
| 198 | |
| 199 | for line in content.lines() { |
| 200 | if line.trim() == MARKER_BEGIN { |
| 201 | in_section = true; |
| 202 | continue; |
| 203 | } |
| 204 | if line.trim() == MARKER_END { |
| 205 | in_section = false; |
| 206 | continue; |
| 207 | } |
| 208 | if !in_section { |
| 209 | result.push_str(line); |
| 210 | result.push('\n'); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // Clean up: if only the shebang remains, delete the file |
| 215 | let trimmed = result.trim(); |
| 216 | if trimmed.is_empty() || trimmed == "#!/bin/sh" { |
| 217 | fs::remove_file(path)?; |
| 218 | } else { |
| 219 | fs::write(path, &result)?; |
| 220 | } |
| 221 | |
| 222 | Ok(true) |
| 223 | } |
| 224 | |
| 225 | /// Show hook installation status. |
| 226 | fn show_status() -> CliResult<()> { |