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

Function remove_atomic_section

atomic-cli/src/commands/git/hooks.rs:190–223  ·  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

188/// Remove the atomic:git:begin..end section from a hook file.
189/// Returns Ok(true) if something was removed.
190fn 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.
226fn 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