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

Function ensure_git_shadow_excludes

atomic-cli/src/commands/git/import.rs:211–246  ·  view source on GitHub ↗
(git_dir: &Path)

Source from the content-addressed store, hash-verified

209}
210
211pub(crate) fn ensure_git_shadow_excludes(git_dir: &Path) -> CliResult<bool> {
212 let info_dir = git_dir.join("info");
213 std::fs::create_dir_all(&info_dir)?;
214
215 let exclude_path = info_dir.join("exclude");
216 let mut content = match std::fs::read_to_string(&exclude_path) {
217 Ok(content) => content,
218 Err(e) if e.kind() == ErrorKind::NotFound => String::new(),
219 Err(e) => return Err(e.into()),
220 };
221
222 let missing: Vec<&str> = GIT_SHADOW_EXCLUDE_PATTERNS
223 .iter()
224 .copied()
225 .filter(|pattern| !content.lines().any(|line| line.trim() == *pattern))
226 .collect();
227
228 if missing.is_empty() {
229 return Ok(false);
230 }
231
232 if !content.is_empty() && !content.ends_with('\n') {
233 content.push('\n');
234 }
235 if !content.is_empty() {
236 content.push('\n');
237 }
238 content.push_str("# Atomic local state (managed by atomic git import)\n");
239 for pattern in missing {
240 content.push_str(pattern);
241 content.push('\n');
242 }
243
244 std::fs::write(exclude_path, content)?;
245 Ok(true)
246}
247
248/// Read-only variant of [`ensure_git_shadow_excludes`]: reports whether the
249/// Git exclude file is missing any shadow-exclude pattern, without writing

Callers 2

stage_and_validate_treeFunction · 0.85
run_importMethod · 0.85

Calls 7

writeFunction · 0.50
kindMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
linesMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected