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

Method add_path

atomic-cli/src/commands/add.rs:269–328  ·  view source on GitHub ↗

Add a single path to tracking.

(
        &self,
        repo: &Repository,
        path: &str,
        options: &TrackingOptions,
    )

Source from the content-addressed store, hash-verified

267
268 /// Add a single path to tracking.
269 fn add_path(
270 &self,
271 repo: &Repository,
272 path: &str,
273 options: &TrackingOptions,
274 ) -> CliResult<TrackingStats> {
275 // Convert to PathBuf for the repository API
276 let path_buf = PathBuf::from(path);
277
278 // Check if the path exists relative to repo root
279 let full_path = repo.root().join(&path_buf);
280 if !full_path.exists() {
281 return Err(CliError::FileNotFound { path: path_buf });
282 }
283
284 // Check if path is inside .atomic
285 if repo.is_internal_path(&path_buf) {
286 return Err(CliError::PathOutsideRepository { path: path_buf });
287 }
288
289 // Handle explicit directory tracking
290 if self.directory {
291 // Verify it's actually a directory
292 if !full_path.is_dir() {
293 return Err(CliError::InvalidArgument {
294 message: format!("--directory: path '{}' is not a directory", path),
295 });
296 }
297
298 // Use the dedicated directory tracking method
299 return repo
300 .add_directory(&path_buf, options.clone())
301 .map_err(|e| match e {
302 atomic_repository::RepositoryError::PathOutsideRepository { path } => {
303 CliError::PathOutsideRepository { path }
304 }
305 atomic_repository::RepositoryError::FileAlreadyTracked { path } => {
306 CliError::FileAlreadyTracked { path }
307 }
308 atomic_repository::RepositoryError::PathIgnored { path } => {
309 CliError::PathIgnored { path }
310 }
311 other => CliError::Internal(other.into()),
312 });
313 }
314
315 // Perform the standard add operation
316 repo.add(&path_buf, options.clone()).map_err(|e| match e {
317 atomic_repository::RepositoryError::PathOutsideRepository { path } => {
318 CliError::PathOutsideRepository { path }
319 }
320 atomic_repository::RepositoryError::FileAlreadyTracked { path } => {
321 CliError::FileAlreadyTracked { path }
322 }
323 atomic_repository::RepositoryError::PathIgnored { path } => {
324 CliError::PathIgnored { path }
325 }
326 other => CliError::Internal(other.into()),

Callers 1

runMethod · 0.45

Calls 7

is_internal_pathMethod · 0.80
is_dirMethod · 0.80
rootMethod · 0.45
existsMethod · 0.45
add_directoryMethod · 0.45
cloneMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected