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

Function find_repository_root_from

atomic-cli/src/commands/mod.rs:275–304  ·  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

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

Calls 2

is_dirMethod · 0.80
is_fileMethod · 0.45