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

Function find_repository_root_from

atomic-cli/src/commands/mod.rs:277–306  ·  view source on GitHub ↗

Find the repository root starting from a specific path. Like [`find_repository_root`], but starts from the given path instead of the current working directory. # Arguments `start_path` - The path to start searching from # Returns The path to the repository root. # Errors Returns [`CliError::RepositoryNotFound`] if no `.atomic` directory is found. # Example ```rust,ignore let repo_root = f

(start_path: &Path)

Source from the content-addressed store, hash-verified

275/// let repo_root = find_repository_root_from("/home/user/project/src")?;
276/// ```
277pub fn find_repository_root_from(start_path: &Path) -> CliResult<PathBuf> {
278 let mut current = start_path.to_path_buf();
279
280 // Canonicalize if possible to handle symlinks correctly
281 if let Ok(canonical) = current.canonicalize() {
282 current = canonical;
283 }
284
285 loop {
286 let dot_dir = current.join(DOT_DIR);
287 if dot_dir.is_dir() {
288 return Ok(current);
289 }
290
291 // A sandbox working tree has no `.atomic/` of its own — it carries a
292 // pointer to the canonical graph. Treat the sandbox root as a valid
293 // repository root; `Repository::open*` resolves the pointer.
294 if current.join(SANDBOX_POINTER).is_file() {
295 return Ok(current);
296 }
297
298 // Move to parent directory
299 if !current.pop() {
300 // Reached the root without finding a repository
301 return Err(CliError::RepositoryNotFound {
302 searched_path: start_path.to_path_buf(),
303 });
304 }
305 }
306}
307
308/// Open a repository, optionally at a specific path.
309///

Callers 6

find_repository_rootFunction · 0.85
open_repositoryFunction · 0.85
runMethod · 0.85

Calls 2

is_dirMethod · 0.80
is_fileMethod · 0.45