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 2
2
{
3
3
public interface IRepository
4
4
{
5
- string FullPath { get ; set ; }
6
- string GitDirForWatcher { get ; }
7
-
8
5
void RefreshBranches ( ) ;
9
6
void RefreshWorktrees ( ) ;
10
7
void RefreshTags ( ) ;
Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ namespace SourceGit.Models
8
8
{
9
9
public class Watcher : IDisposable
10
10
{
11
- public Watcher ( IRepository repo )
11
+ public Watcher ( IRepository repo , string fullpath , string gitDir )
12
12
{
13
13
_repo = repo ;
14
14
15
15
_wcWatcher = new FileSystemWatcher ( ) ;
16
- _wcWatcher . Path = _repo . FullPath ;
16
+ _wcWatcher . Path = fullpath ;
17
17
_wcWatcher . Filter = "*" ;
18
18
_wcWatcher . NotifyFilter = NotifyFilters . LastWrite | NotifyFilters . DirectoryName | NotifyFilters . FileName | NotifyFilters . Size | NotifyFilters . CreationTime ;
19
19
_wcWatcher . IncludeSubdirectories = true ;
@@ -24,7 +24,7 @@ public Watcher(IRepository repo)
24
24
_wcWatcher . EnableRaisingEvents = true ;
25
25
26
26
_repoWatcher = new FileSystemWatcher ( ) ;
27
- _repoWatcher . Path = _repo . GitDirForWatcher ;
27
+ _repoWatcher . Path = gitDir ;
28
28
_repoWatcher . Filter = "*" ;
29
29
_repoWatcher . NotifyFilter = NotifyFilters . LastWrite | NotifyFilters . DirectoryName | NotifyFilters . FileName ;
30
30
_repoWatcher . IncludeSubdirectories = true ;
Original file line number Diff line number Diff line change @@ -45,21 +45,6 @@ public string GitDir
45
45
set => SetProperty ( ref _gitDir , value ) ;
46
46
}
47
47
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
-
63
48
public Models . RepositorySettings Settings
64
49
{
65
50
get => _settings ;
@@ -472,7 +457,16 @@ public void Open()
472
457
473
458
try
474
459
{
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 ) ;
476
470
}
477
471
catch ( Exception ex )
478
472
{
You can’t perform that action at this time.
0 commit comments