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:172–207  ·  view source on GitHub ↗
(git_dir: &Path)

Source from the content-addressed store, hash-verified

170}
171
172pub(crate) fn ensure_git_shadow_excludes(git_dir: &Path) -> CliResult<bool> {
173 let info_dir = git_dir.join("info");
174 std::fs::create_dir_all(&info_dir)?;
175
176 let exclude_path = info_dir.join("exclude");
177 let mut content = match std::fs::read_to_string(&exclude_path) {
178 Ok(content) => content,
179 Err(e) if e.kind() == ErrorKind::NotFound => String::new(),
180 Err(e) => return Err(e.into()),
181 };
182
183 let missing: Vec<&str> = GIT_SHADOW_EXCLUDE_PATTERNS
184 .iter()
185 .copied()
186 .filter(|pattern| !content.lines().any(|line| line.trim() == *pattern))
187 .collect();
188
189 if missing.is_empty() {
190 return Ok(false);
191 }
192
193 if !content.is_empty() && !content.ends_with('\n') {
194 content.push('\n');
195 }
196 if !content.is_empty() {
197 content.push('\n');
198 }
199 content.push_str("# Atomic local state (managed by atomic git import)\n");
200 for pattern in missing {
201 content.push_str(pattern);
202 content.push('\n');
203 }
204
205 std::fs::write(exclude_path, content)?;
206 Ok(true)
207}
208
209impl Import {
210 /// Import a single branch into an Atomic view using parallel processing.

Callers 2

stage_and_validate_treeFunction · 0.85
runMethod · 0.85

Calls 6

writeFunction · 0.85
kindMethod · 0.45
iterMethod · 0.45
linesMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected