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

Function open_repository

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

Open a repository, optionally at a specific path. If `path` is provided, opens the repository at that path. If `path` is `None`, searches upward from the current directory. # Arguments `path` - Optional path to the repository # Returns An open [`Repository`] handle. # Errors Returns an error if no repository is found or if the repository cannot be opened. # Example ```rust,ignore // Open

(path: Option<&Path>)

Source from the content-addressed store, hash-verified

340/// let repo = open_repository(Some(Path::new("/home/user/project")))?;
341/// ```
342pub fn open_repository(path: Option<&Path>) -> CliResult<Repository> {
343 let repo_path = match path {
344 Some(p) => {
345 // If a path is provided, check if it's a repository or search from there
346 let dot_dir = p.join(DOT_DIR);
347 if dot_dir.is_dir() {
348 p.to_path_buf()
349 } else {
350 find_repository_root_from(p)?
351 }
352 }
353 None => find_repository_root()?,
354 };
355
356 Repository::open(&repo_path).map_err(CliError::from)
357}
358
359/// Open a repository or return a user-friendly error.
360///

Callers 1

require_repositoryFunction · 0.85

Calls 3

find_repository_rootFunction · 0.85
is_dirMethod · 0.80

Tested by

no test coverage detected