mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
enhance: if current repository is a worktree of another repository, watch the gitdir to it's main repository's gitdir (#86)
This commit is contained in:
parent
9ae926db9f
commit
1fe050ed0b
1 changed files with 9 additions and 3 deletions
|
@ -35,8 +35,15 @@ namespace SourceGit.Models
|
||||||
_wcWatcher.Deleted += OnWorkingCopyChanged;
|
_wcWatcher.Deleted += OnWorkingCopyChanged;
|
||||||
_wcWatcher.EnableRaisingEvents = true;
|
_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/");
|
||||||
|
var repoWatchDir = _repo.GitDir;
|
||||||
|
if (worktreeIdx > 0)
|
||||||
|
repoWatchDir = _repo.GitDir.Substring(0, worktreeIdx + 4);
|
||||||
|
|
||||||
_repoWatcher = new FileSystemWatcher();
|
_repoWatcher = new FileSystemWatcher();
|
||||||
_repoWatcher.Path = _repo.GitDir;
|
_repoWatcher.Path = repoWatchDir;
|
||||||
_repoWatcher.Filter = "*";
|
_repoWatcher.Filter = "*";
|
||||||
_repoWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName;
|
_repoWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName;
|
||||||
_repoWatcher.IncludeSubdirectories = true;
|
_repoWatcher.IncludeSubdirectories = true;
|
||||||
|
@ -173,8 +180,7 @@ namespace SourceGit.Models
|
||||||
}
|
}
|
||||||
else if (name.Equals("HEAD", StringComparison.Ordinal) ||
|
else if (name.Equals("HEAD", StringComparison.Ordinal) ||
|
||||||
name.StartsWith("refs/heads/", StringComparison.Ordinal) ||
|
name.StartsWith("refs/heads/", StringComparison.Ordinal) ||
|
||||||
name.StartsWith("refs/remotes/", StringComparison.Ordinal) ||
|
name.StartsWith("refs/remotes/", StringComparison.Ordinal))
|
||||||
name.StartsWith("worktrees/", StringComparison.Ordinal))
|
|
||||||
{
|
{
|
||||||
_updateBranch = DateTime.Now.AddSeconds(.5).ToFileTime();
|
_updateBranch = DateTime.Now.AddSeconds(.5).ToFileTime();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue