Skip to content

Commit 3353b9f

Browse files
committed
fix: repositories using ref-tables will be recognised.
1 parent db44c6e commit 3353b9f

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

gix-discover/src/is.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::{borrow::Cow, ffi::OsStr, path::Path};
2-
31
use crate::{DOT_GIT_DIR, MODULES};
2+
use std::{borrow::Cow, ffi::OsStr, path::Path};
43

54
/// Returns true if the given `git_dir` seems to be a bare repository.
65
///
@@ -67,21 +66,30 @@ pub(crate) fn git_with_metadata(
6766

6867
{
6968
// Fast-path: avoid doing the complete search if HEAD is already not there.
70-
// TODO(reftable): use a ref-store to lookup HEAD if ref-tables should be supported, or detect ref-tables beforehand.
71-
// Actually ref-tables still keep a specially marked `HEAD` around, so nothing might be needed here
72-
// Even though our head-check later would fail without supporting it.
7369
if !dot_git.join("HEAD").exists() {
7470
return Err(crate::is_git::Error::MissingHead);
7571
}
7672
// We expect to be able to parse any ref-hash, so we shouldn't have to know the repos hash here.
77-
// With ref-table, the has is probably stored as part of the ref-db itself, so we can handle it from there.
73+
// With ref-table, the hash is probably stored as part of the ref-db itself, so we can handle it from there.
7874
// In other words, it's important not to fail on detached heads here because we guessed the hash kind wrongly.
7975
let refs = gix_ref::file::Store::at(dot_git.as_ref().into(), Default::default());
80-
let head = refs.find_loose("HEAD")?;
81-
if head.name.as_bstr() != "HEAD" {
82-
return Err(crate::is_git::Error::MisplacedHead {
83-
name: head.name.into_inner(),
84-
});
76+
match refs.find_loose("HEAD") {
77+
Ok(head) => {
78+
if head.name.as_bstr() != "HEAD" {
79+
return Err(crate::is_git::Error::MisplacedHead {
80+
name: head.name.into_inner(),
81+
});
82+
}
83+
}
84+
Err(gix_ref::file::find::existing::Error::Find(gix_ref::file::find::Error::ReferenceCreation {
85+
source: _,
86+
relative_path,
87+
})) if relative_path == Path::new("HEAD") => {
88+
// It's fine as long as the reference is found is `HEAD`.
89+
}
90+
Err(err) => {
91+
return Err(err.into());
92+
}
8593
}
8694
}
8795

gix-discover/tests/discover/is_git/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ fn split_worktree_using_configuration() -> crate::Result {
133133

134134
#[test]
135135
fn reftable() -> crate::Result {
136-
let repo = gix_testtools::scripted_fixture_read_only("make_reftable_repo.sh")?.join("reftable-clone");
137-
let kind = gix_discover::is_git(&repo)?;
136+
let repo_path = gix_testtools::scripted_fixture_read_only("make_reftable_repo.sh")?.join("reftable-clone/.git");
137+
let kind = gix_discover::is_git(&repo_path)?;
138138
assert_eq!(kind, gix_discover::repository::Kind::WorkTree { linked_git_dir: None });
139139
Ok(())
140140
}

0 commit comments

Comments
 (0)