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