mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
fix: discover gix repo from workdir for linked worktrees
Linked worktrees use a .git file; discovering from gitpath alone can miss .git/info/exclude. Discover from the repository workdir instead. Fixes #2876 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8619c07f3f
commit
af5ac97181
2 changed files with 22 additions and 6 deletions
|
|
@ -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()))?;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue