File tree Expand file tree Collapse file tree 3 files changed +13
-22
lines changed
Expand file tree Collapse file tree 3 files changed +13
-22
lines changed Original file line number Diff line number Diff line change 22{
33 public interface IRepository
44 {
5- string FullPath { get ; set ; }
6- string GitDirForWatcher { get ; }
7-
85 void RefreshBranches ( ) ;
96 void RefreshWorktrees ( ) ;
107 void RefreshTags ( ) ;
Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ namespace SourceGit.Models
88{
99 public class Watcher : IDisposable
1010 {
11- public Watcher ( IRepository repo )
11+ public Watcher ( IRepository repo , string fullpath , string gitDir )
1212 {
1313 _repo = repo ;
1414
1515 _wcWatcher = new FileSystemWatcher ( ) ;
16- _wcWatcher . Path = _repo . FullPath ;
16+ _wcWatcher . Path = fullpath ;
1717 _wcWatcher . Filter = "*" ;
1818 _wcWatcher . NotifyFilter = NotifyFilters . LastWrite | NotifyFilters . DirectoryName | NotifyFilters . FileName | NotifyFilters . Size | NotifyFilters . CreationTime ;
1919 _wcWatcher . IncludeSubdirectories = true ;
@@ -24,7 +24,7 @@ public Watcher(IRepository repo)
2424 _wcWatcher . EnableRaisingEvents = true ;
2525
2626 _repoWatcher = new FileSystemWatcher ( ) ;
27- _repoWatcher . Path = _repo . GitDirForWatcher ;
27+ _repoWatcher . Path = gitDir ;
2828 _repoWatcher . Filter = "*" ;
2929 _repoWatcher . NotifyFilter = NotifyFilters . LastWrite | NotifyFilters . DirectoryName | NotifyFilters . FileName ;
3030 _repoWatcher . IncludeSubdirectories = true ;
Original file line number Diff line number Diff line change @@ -45,21 +45,6 @@ public string GitDir
4545 set => SetProperty ( ref _gitDir , value ) ;
4646 }
4747
48- public string GitDirForWatcher
49- {
50- get
51- {
52- // Only try to get `$GIT_COMMON_DIR` if this repository looks like a worktree.
53- if ( _gitDir . Replace ( "\\ " , "/" ) . IndexOf ( ".git/worktrees/" , StringComparison . Ordinal ) > 0 )
54- {
55- var commonDir = new Commands . QueryGitCommonDir ( _fullpath ) . Result ( ) ;
56- return string . IsNullOrEmpty ( commonDir ) ? _gitDir : commonDir ;
57- }
58-
59- return _gitDir ;
60- }
61- }
62-
6348 public Models . RepositorySettings Settings
6449 {
6550 get => _settings ;
@@ -472,7 +457,16 @@ public void Open()
472457
473458 try
474459 {
475- _watcher = new Models . Watcher ( this ) ;
460+ // For worktrees, we need to watch the $GIT_COMMON_DIR instead of the $GIT_DIR.
461+ var gitDirForWatcher = _gitDir ;
462+ if ( _gitDir . Replace ( "\\ " , "/" ) . IndexOf ( ".git/worktrees/" , StringComparison . Ordinal ) > 0 )
463+ {
464+ var commonDir = new Commands . QueryGitCommonDir ( _fullpath ) . Result ( ) ;
465+ if ( ! string . IsNullOrEmpty ( commonDir ) )
466+ gitDirForWatcher = commonDir ;
467+ }
468+
469+ _watcher = new Models . Watcher ( this , _fullpath , gitDirForWatcher ) ;
476470 }
477471 catch ( Exception ex )
478472 {
You can’t perform that action at this time.
0 commit comments