Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Improve cwd to search parents
Fintan Halpenny committed 2 years ago
commit c82344496bb53a3c1151d3bea617e7bbaa4c920e
parent 7e3c7a7ae08e7fde67c26596a6771a0a9d7786f3
1 file changed +16 -1
modified 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))