diff --git a/src/Models/IRepository.cs b/src/Models/IRepository.cs index 9283266e..0224d81f 100644 --- a/src/Models/IRepository.cs +++ b/src/Models/IRepository.cs @@ -2,9 +2,6 @@ { public interface IRepository { - string FullPath { get; set; } - string GitDirForWatcher { get; } - void RefreshBranches(); void RefreshWorktrees(); void RefreshTags(); diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index d419363a..3ccecad4 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -8,12 +8,12 @@ namespace SourceGit.Models { public class Watcher : IDisposable { - public Watcher(IRepository repo) + public Watcher(IRepository repo, string fullpath, string gitDir) { _repo = repo; _wcWatcher = new FileSystemWatcher(); - _wcWatcher.Path = _repo.FullPath; + _wcWatcher.Path = fullpath; _wcWatcher.Filter = "*"; _wcWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.CreationTime; _wcWatcher.IncludeSubdirectories = true; @@ -24,7 +24,7 @@ namespace SourceGit.Models _wcWatcher.EnableRaisingEvents = true; _repoWatcher = new FileSystemWatcher(); - _repoWatcher.Path = _repo.GitDirForWatcher; + _repoWatcher.Path = gitDir; _repoWatcher.Filter = "*"; _repoWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName; _repoWatcher.IncludeSubdirectories = true; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 85665634..4f2f3ca3 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -45,21 +45,6 @@ namespace SourceGit.ViewModels set => SetProperty(ref _gitDir, value); } - public string GitDirForWatcher - { - get - { - // Only try to get `$GIT_COMMON_DIR` if this repository looks like a worktree. - if (_gitDir.Replace("\\", "/").IndexOf(".git/worktrees/", StringComparison.Ordinal) > 0) - { - var commonDir = new Commands.QueryGitCommonDir(_fullpath).Result(); - return string.IsNullOrEmpty(commonDir) ? _gitDir : commonDir; - } - - return _gitDir; - } - } - public Models.RepositorySettings Settings { get => _settings; @@ -472,7 +457,16 @@ namespace SourceGit.ViewModels try { - _watcher = new Models.Watcher(this); + // For worktrees, we need to watch the $GIT_COMMON_DIR instead of the $GIT_DIR. + var gitDirForWatcher = _gitDir; + if (_gitDir.Replace("\\", "/").IndexOf(".git/worktrees/", StringComparison.Ordinal) > 0) + { + var commonDir = new Commands.QueryGitCommonDir(_fullpath).Result(); + if (!string.IsNullOrEmpty(commonDir)) + gitDirForWatcher = commonDir; + } + + _watcher = new Models.Watcher(this, _fullpath, gitDirForWatcher); } catch (Exception ex) {