|
1 |
| -use std::{borrow::Cow, ffi::OsStr, path::Path}; |
2 |
| - |
3 | 1 | use crate::{DOT_GIT_DIR, MODULES};
|
| 2 | +use std::{borrow::Cow, ffi::OsStr, path::Path}; |
4 | 3 |
|
5 | 4 | /// Returns true if the given `git_dir` seems to be a bare repository.
|
6 | 5 | ///
|
@@ -67,21 +66,30 @@ pub(crate) fn git_with_metadata(
|
67 | 66 |
|
68 | 67 | {
|
69 | 68 | // 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. |
73 | 69 | if !dot_git.join("HEAD").exists() {
|
74 | 70 | return Err(crate::is_git::Error::MissingHead);
|
75 | 71 | }
|
76 | 72 | // 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. |
78 | 74 | // In other words, it's important not to fail on detached heads here because we guessed the hash kind wrongly.
|
79 | 75 | 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 | + } |
85 | 93 | }
|
86 | 94 | }
|
87 | 95 |
|
|
0 commit comments