This commit is contained in:
吴杨帆 2026-05-17 16:39:00 +08:00 committed by GitHub
commit 308e86a27b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 6 deletions

View file

@ -68,11 +68,26 @@ pub fn repo(repo_path: &RepoPath) -> Result<Repository> {
Ok(repo)
}
/// Path to pass to `gix::discover` so linked worktrees resolve `info/exclude` correctly.
pub(crate) fn repo_discover_path(repo_path: &RepoPath) -> Result<PathBuf> {
if let Some(workdir) = repo_path.workdir() {
return Ok(workdir.to_path_buf());
}
let git_repo = repo(repo_path)?;
git_repo
.workdir()
.ok_or(crate::error::Error::NoWorkDir)
.map(|path| path.to_path_buf())
}
pub fn gix_repo(repo_path: &RepoPath) -> Result<gix::Repository> {
let mut repo: gix::Repository = gix::ThreadSafeRepository::discover_with_environment_overrides(
repo_path.gitpath(),
)
.map(Into::into)?;
let discover_path = repo_discover_path(repo_path)?;
let mut repo: gix::Repository =
gix::ThreadSafeRepository::discover_with_environment_overrides(
&discover_path,
)
.map(Into::into)?;
if let Some(workdir) = repo_path.workdir() {
repo.set_workdir(Some(workdir.into()))?;

View file

@ -1,7 +1,8 @@
//! sync git api (various methods)
use super::{
repository::repo, CommitId, RepoPath, ShowUntrackedFilesConfig,
repository::{repo, repo_discover_path},
CommitId, RepoPath, ShowUntrackedFilesConfig,
};
use crate::{
error::{Error, Result},
@ -35,7 +36,7 @@ pub fn repo_open_error(repo_path: &RepoPath) -> Option<String> {
}
gix::ThreadSafeRepository::discover_with_environment_overrides(
repo_path.gitpath(),
repo_discover_path(repo_path).ok()?,
)
.map_or_else(|e| Some(e.to_string()), |_| None)
}