Skip to content

Commit

Permalink
git: Use open_from_env before discover
Browse files Browse the repository at this point in the history
This matches git behaviour
  • Loading branch information
iamkroot committed Oct 30, 2022
1 parent 4e23f8e commit 1c77814
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/fs/feature/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,23 @@ impl GitRepo {
/// Returns the original buffer if none is found.
fn discover(path: PathBuf) -> Result<Self, PathBuf> {
info!("Searching for Git repository above {:?}", path);
let repo = match git2::Repository::discover(&path) {
// Search with GIT_DIR env variable first if set
let repo = match git2::Repository::open_from_env() {
Ok(r) => r,
Err(e) => {
error!("Error discovering Git repositories: {:?}", e);
match git2::Repository::open_from_env() {
Ok(r) => r,
Err(e) => {
// anything other than NotFound implies GIT_DIR was set and we got actual error
if e.code() != git2::ErrorCode::NotFound {
error!("Error opening Git repo from env using GIT_DIR: {:?}", e);
// anything other than NotFound implies GIT_DIR was set and we got actual error
if e.code() != git2::ErrorCode::NotFound {
error!("Error opening Git repo from env using GIT_DIR: {:?}", e);
return Err(path);
} else {
// nothing found, search using discover
match git2::Repository::discover(&path) {
Ok(r) => r,
Err(e) => {
error!("Error discovering Git repositories: {:?}", e);
return Err(path);

}
return Err(path);
}
}
}
Expand Down

0 comments on commit 1c77814

Please sign in to comment.