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

Method add

atomic-repository/src/repository/tracking.rs:167–251  ·  view source on GitHub ↗

Add a file or directory to tracking. This registers the file with the repository so it will be included in future changes. Adding a file does NOT create a change - you need to call `record()` for that. # Arguments `working_copy` - Identity of the physical working copy being inspected `path` - Path to the file or directory (relative to repository root) `options` - Options controlling the add ope

(
        &self,
        working_copy: WorkingCopyId,
        path: P,
        options: TrackingOptions,
    )

Source from the content-addressed store, hash-verified

165 /// repo.add(working_copy, "src/", TrackingOptions::non_recursive())?;
166 /// ```
167 pub fn add<P: AsRef<Path>>(
168 &self,
169 working_copy: WorkingCopyId,
170 path: P,
171 options: TrackingOptions,
172 ) -> Result<TrackingStats, RepositoryError> {
173 self.validate_working_copy(working_copy)?;
174 let path = path.as_ref();
175 let mut stats = TrackingStats::new();
176
177 // Load ignore rules
178 let rules = self.load_ignore_rules();
179
180 // Check for internal paths and ignore patterns
181 let abs_path = self.root.join(path);
182 let is_dir = abs_path.is_dir();
183 if should_ignore_with_rules(path, true, is_dir, Some(&rules)) {
184 return Err(RepositoryError::PathIgnored {
185 path: path.to_path_buf(),
186 });
187 }
188
189 // Collect files to add (respecting ignore rules)
190 let files = collect_files_for_tracking_with_rules(&self.root, path, &options, Some(&rules))
191 .map_err(|e| RepositoryError::Database(e.to_string()))?;
192
193 if files.is_empty() {
194 return Ok(stats);
195 }
196
197 // Don't modify if dry run
198 if options.dry_run {
199 for file_path in files {
200 // Only count files, not directories (directories are implicitly tracked)
201 let abs_path = self.root.join(&file_path);
202 if !abs_path.is_dir() {
203 stats.files_added += 1;
204 }
205 }
206 return Ok(stats);
207 }
208
209 // Add to tracking
210 let mut txn = self
211 .pristine
212 .write_txn()
213 .map_err(|e| RepositoryError::Database(e.to_string()))?;
214
215 for file_path in files {
216 // Normalize path with repo root to handle absolute paths correctly
217 // (e.g., on macOS where /tmp -> /private/tmp)
218 let normalized = normalize_path_with_root(&file_path, Some(&self.root));
219 let abs_path = self.root.join(&file_path);
220
221 // Skip directories - they are implicitly tracked through their contents
222 if abs_path.is_dir() {
223 continue;
224 }

Calls 15

should_ignore_with_rulesFunction · 0.85
normalize_path_with_rootFunction · 0.85
is_trackedFunction · 0.85
add_to_treeFunction · 0.85
cancel_pending_untracksFunction · 0.85
validate_working_copyMethod · 0.80
as_refMethod · 0.80
load_ignore_rulesMethod · 0.80
is_dirMethod · 0.80
write_txnMethod · 0.80
skipMethod · 0.80