diff --git a/radicle/src/rad.rs b/radicle/src/rad.rs index bbd8b05c..92af9d39 100644 --- a/radicle/src/rad.rs +++ b/radicle/src/rad.rs @@ -269,8 +269,23 @@ pub fn remove_remote(repo: &git2::Repository) -> Result<(), RemoteError> { } /// Get the Id of project in current working directory +/// +/// It will atempt to search parent directories if `path` did not find +/// a git repository. +/// +/// # Safety +/// +/// This function should only perform read operations since we do not +/// want to modify the wrong repository in the case that it found a +/// Git repository that is not a Radicle repository. pub fn cwd() -> Result<(git2::Repository, Id), RemoteError> { - let repo = git2::Repository::open(Path::new("."))?; + let mut flags = git2::RepositoryOpenFlags::empty(); + // Allow to search upwards. + flags.set(git2::RepositoryOpenFlags::NO_SEARCH, false); + // Allow to use `GIT_DIR` env. + flags.set(git2::RepositoryOpenFlags::FROM_ENV, true); + let ceilings: &[&str] = &[]; + let repo = git2::Repository::open_ext(Path::new("."), flags, ceilings)?; let (_, id) = remote(&repo)?; Ok((repo, id))