MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / remove_atomic_section

Function remove_atomic_section

atomic-cli/src/commands/git/hooks.rs:211–244  ·  view source on GitHub ↗

Remove the atomic:git:begin..end section from a hook file. Returns Ok(true) if something was removed.

(path: &Path)

Source from the content-addressed store, hash-verified

209/// Remove the atomic:git:begin..end section from a hook file.
210/// Returns Ok(true) if something was removed.
211fn 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.
247fn show_status() -> CliResult<()> {

Callers 2

uninstall_hooksFunction · 0.85

Calls 5

writeFunction · 0.85
containsMethod · 0.45
linesMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by 1