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>)
| 325 | /// let repo = open_repository(Some(Path::new("/home/user/project")))?; |
| 326 | /// ``` |
| 327 | pub fn open_repository(path: Option<&Path>) -> CliResult<Repository> { |
| 328 | let repo_path = match path { |
| 329 | Some(p) => { |
| 330 | // If a path is provided, check if it's a repository or search from there |
| 331 | let dot_dir = p.join(DOT_DIR); |
| 332 | if dot_dir.is_dir() { |
| 333 | p.to_path_buf() |
| 334 | } else { |
| 335 | find_repository_root_from(p)? |
| 336 | } |
| 337 | } |
| 338 | None => find_repository_root()?, |
| 339 | }; |
| 340 | |
| 341 | Repository::open(&repo_path).map_err(CliError::from) |
| 342 | } |
| 343 | |
| 344 | /// Open a repository or return a user-friendly error. |
| 345 | /// |
no test coverage detected