refactor: use $GIT_COMMON_DIR instead of cut $GIT_DIR/worktrees (#1103)

This commit is contained in:
Gadfly 2025-03-17 15:56:13 +08:00 committed by GitHub
parent 265aaa1d67
commit cea8a90680
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 51 additions and 16 deletions

View file

@ -4,6 +4,7 @@
{
string FullPath { get; set; }
string GitDir { get; set; }
string GitCommonDir { get; set; }
void RefreshBranches();
void RefreshWorktrees();

View file

@ -24,11 +24,7 @@ namespace SourceGit.Models
_wcWatcher.EnableRaisingEvents = true;
// If this repository is a worktree repository, just watch the main repository's gitdir.
var gitDirNormalized = _repo.GitDir.Replace("\\", "/");
var worktreeIdx = gitDirNormalized.IndexOf(".git/worktrees/", StringComparison.Ordinal);
var repoWatchDir = _repo.GitDir;
if (worktreeIdx > 0)
repoWatchDir = _repo.GitDir.Substring(0, worktreeIdx + 4);
var repoWatchDir = _repo.GitCommonDir.Replace("\\", "/");
_repoWatcher = new FileSystemWatcher();
_repoWatcher.Path = repoWatchDir;