Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions asyncgit/src/sync/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))?;
Expand Down
5 changes: 3 additions & 2 deletions asyncgit/src/sync/utils.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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)
}
Expand Down