Remove the atomic:git:begin..end section from a hook file. Returns Ok(true) if something was removed.
(path: &Path)
| 209 | /// Remove the atomic:git:begin..end section from a hook file. |
| 210 | /// Returns Ok(true) if something was removed. |
| 211 | fn remove_atomic_section(path: &Path) -> Result<bool, std::io::Error> { |
| 212 | let content = fs::read_to_string(path)?; |
| 213 | if !content.contains(MARKER_BEGIN) { |
| 214 | return Ok(false); |
| 215 | } |
| 216 | |
| 217 | let mut result = String::new(); |
| 218 | let mut in_section = false; |
| 219 | |
| 220 | for line in content.lines() { |
| 221 | if line.trim() == MARKER_BEGIN { |
| 222 | in_section = true; |
| 223 | continue; |
| 224 | } |
| 225 | if line.trim() == MARKER_END { |
| 226 | in_section = false; |
| 227 | continue; |
| 228 | } |
| 229 | if !in_section { |
| 230 | result.push_str(line); |
| 231 | result.push('\n'); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // Clean up: if only the shebang remains, delete the file |
| 236 | let trimmed = result.trim(); |
| 237 | if trimmed.is_empty() || trimmed == "#!/bin/sh" { |
| 238 | fs::remove_file(path)?; |
| 239 | } else { |
| 240 | fs::write(path, &result)?; |
| 241 | } |
| 242 | |
| 243 | Ok(true) |
| 244 | } |
| 245 | |
| 246 | /// Show hook installation status. |
| 247 | fn show_status() -> CliResult<()> { |