1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
3
using System . Linq ;
5
4
using System . Threading ;
6
5
using System . Threading . Tasks ;
@@ -11,21 +10,13 @@ interface IRepositoryManager : IDisposable
11
10
{
12
11
event Action OnActiveBranchChanged ;
13
12
event Action OnActiveRemoteChanged ;
14
- event Action OnRemoteBranchListChanged ;
13
+ event Action < bool > OnIsBusyChanged ;
15
14
event Action OnLocalBranchListChanged ;
16
- event Action < GitStatus > OnStatusUpdated ;
17
15
event Action OnHeadChanged ;
18
- event Action < bool > OnIsBusyChanged ;
19
- event Action OnRemoteOrTrackingChanged ;
16
+ event Action < GitStatus > OnStatusUpdated ;
20
17
event Action < IEnumerable < GitLock > > OnLocksUpdated ;
21
- Dictionary < string , ConfigBranch > LocalBranches { get ; }
22
- Dictionary < string , Dictionary < string , ConfigBranch > > RemoteBranches { get ; }
23
- IRepository Repository { get ; }
24
- IGitConfig Config { get ; }
25
- ConfigBranch ? ActiveBranch { get ; }
26
- ConfigRemote ? ActiveRemote { get ; }
27
- IGitClient GitClient { get ; }
28
- bool IsBusy { get ; }
18
+ event Action OnRemoteBranchListChanged ;
19
+ event Action OnRemoteOrTrackingChanged ;
29
20
Task Initialize ( ) ;
30
21
void Start ( ) ;
31
22
void Stop ( ) ;
@@ -44,6 +35,14 @@ interface IRepositoryManager : IDisposable
44
35
ITask ListLocks ( bool local ) ;
45
36
ITask LockFile ( string file ) ;
46
37
ITask UnlockFile ( string file , bool force ) ;
38
+ Dictionary < string , ConfigBranch > LocalBranches { get ; }
39
+ Dictionary < string , Dictionary < string , ConfigBranch > > RemoteBranches { get ; }
40
+ IRepository Repository { get ; }
41
+ IGitConfig Config { get ; }
42
+ ConfigBranch ? ActiveBranch { get ; }
43
+ ConfigRemote ? ActiveRemote { get ; }
44
+ IGitClient GitClient { get ; }
45
+ bool IsBusy { get ; }
47
46
}
48
47
49
48
interface IRepositoryPathConfiguration
@@ -91,17 +90,17 @@ public RepositoryPathConfiguration(NPath repositoryPath)
91
90
92
91
class RepositoryManagerFactory
93
92
{
94
- public RepositoryManager CreateRepositoryManager ( IPlatform platform , ITaskManager taskManager , IUsageTracker usageTracker ,
95
- IGitClient gitClient , NPath repositoryRoot )
93
+ public RepositoryManager CreateRepositoryManager ( IPlatform platform , ITaskManager taskManager ,
94
+ IUsageTracker usageTracker , IGitClient gitClient , NPath repositoryRoot )
96
95
{
97
96
var repositoryPathConfiguration = new RepositoryPathConfiguration ( repositoryRoot ) ;
98
97
string filePath = repositoryPathConfiguration . DotGitConfig ;
99
98
var gitConfig = new GitConfig ( filePath ) ;
100
99
101
100
var repositoryWatcher = new RepositoryWatcher ( platform , repositoryPathConfiguration , taskManager . Token ) ;
102
101
103
- return new RepositoryManager ( platform , taskManager , usageTracker , gitConfig , repositoryWatcher ,
104
- gitClient , repositoryPathConfiguration , taskManager . Token ) ;
102
+ return new RepositoryManager ( platform , taskManager , usageTracker , gitConfig , repositoryWatcher , gitClient ,
103
+ repositoryPathConfiguration , taskManager . Token ) ;
105
104
}
106
105
}
107
106
@@ -110,34 +109,34 @@ class RepositoryManager : IRepositoryManager
110
109
private readonly Dictionary < string , ConfigBranch > branches = new Dictionary < string , ConfigBranch > ( ) ;
111
110
private readonly CancellationToken cancellationToken ;
112
111
private readonly IGitConfig config ;
112
+ private readonly IGitClient gitClient ;
113
113
private readonly IPlatform platform ;
114
+ private readonly IRepositoryPathConfiguration repositoryPaths ;
114
115
private readonly ITaskManager taskManager ;
115
116
private readonly IUsageTracker usageTracker ;
116
- private IRepository repository ;
117
- private readonly IRepositoryPathConfiguration repositoryPaths ;
118
- private readonly IGitClient gitClient ;
119
117
private readonly IRepositoryWatcher watcher ;
120
118
121
119
private ConfigBranch ? activeBranch ;
122
120
private ConfigRemote ? activeRemote ;
123
121
private string head ;
124
122
private bool isBusy ;
123
+ private IEnumerable < GitLock > locks ;
125
124
private Dictionary < string , Dictionary < string , ConfigBranch > > remoteBranches = new Dictionary < string , Dictionary < string , ConfigBranch > > ( ) ;
126
125
private Dictionary < string , ConfigRemote > remotes ;
127
- private IEnumerable < GitLock > locks ;
126
+ private IRepository repository ;
128
127
129
128
public event Action OnActiveBranchChanged ;
130
129
public event Action OnActiveRemoteChanged ;
131
- public event Action OnRemoteBranchListChanged ;
132
- public event Action OnLocalBranchListChanged ;
133
- public event Action < GitStatus > OnStatusUpdated ;
134
130
public event Action OnHeadChanged ;
135
131
public event Action < bool > OnIsBusyChanged ;
136
- public event Action OnRemoteOrTrackingChanged ;
132
+ public event Action OnLocalBranchListChanged ;
137
133
public event Action < IEnumerable < GitLock > > OnLocksUpdated ;
134
+ public event Action OnRemoteBranchListChanged ;
135
+ public event Action OnRemoteOrTrackingChanged ;
136
+ public event Action < GitStatus > OnStatusUpdated ;
138
137
139
- public RepositoryManager ( IPlatform platform , ITaskManager taskManager , IUsageTracker usageTracker , IGitConfig gitConfig ,
140
- IRepositoryWatcher repositoryWatcher , IGitClient gitClient ,
138
+ public RepositoryManager ( IPlatform platform , ITaskManager taskManager , IUsageTracker usageTracker ,
139
+ IGitConfig gitConfig , IRepositoryWatcher repositoryWatcher , IGitClient gitClient ,
141
140
IRepositoryPathConfiguration repositoryPaths , CancellationToken cancellationToken )
142
141
{
143
142
this . repositoryPaths = repositoryPaths ;
@@ -163,9 +162,11 @@ public RepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTra
163
162
164
163
var remote = config . GetRemote ( "origin" ) ;
165
164
if ( ! remote . HasValue )
165
+ {
166
166
remote = config . GetRemotes ( )
167
- . Where ( x => HostAddress . Create ( new UriString ( x . Url ) . ToRepositoryUri ( ) ) . IsGitHubDotCom ( ) )
168
- . FirstOrDefault ( ) ;
167
+ . Where ( x => HostAddress . Create ( new UriString ( x . Url ) . ToRepositoryUri ( ) ) . IsGitHubDotCom ( ) )
168
+ . FirstOrDefault ( ) ;
169
+ }
169
170
UriString cloneUrl = "" ;
170
171
if ( remote . Value . Url != null )
171
172
{
@@ -398,8 +399,7 @@ private void Watcher_OnHeadChanged(string contents)
398
399
}
399
400
400
401
private void Watcher_OnIndexChanged ( )
401
- {
402
- }
402
+ { }
403
403
404
404
private void Watcher_OnLocalBranchCreated ( string name )
405
405
{
@@ -436,6 +436,7 @@ private async Task<IRepository> InitializeRepository()
436
436
{
437
437
throw new InvalidOperationException ( "No user configured" ) ;
438
438
}
439
+
439
440
user . Email = res ;
440
441
repository . User = user ;
441
442
return repository ;
@@ -599,6 +600,7 @@ private void RemoveRemoteBranch(string remote, string name)
599
600
}
600
601
601
602
private bool disposed ;
603
+
602
604
private void Dispose ( bool disposing )
603
605
{
604
606
if ( disposed ) return ;
@@ -628,7 +630,8 @@ public ConfigBranch? ActiveBranch
628
630
get { return activeBranch ; }
629
631
private set
630
632
{
631
- if ( activeBranch . HasValue != value . HasValue || ( activeBranch . HasValue && ! activeBranch . Value . Equals ( value . Value ) ) )
633
+ if ( activeBranch . HasValue != value . HasValue ||
634
+ activeBranch . HasValue && ! activeBranch . Value . Equals ( value . Value ) )
632
635
{
633
636
activeBranch = value ;
634
637
Logger . Trace ( "OnActiveBranchChanged: {0}" , value ? . ToString ( ) ?? "NULL" ) ;
@@ -642,7 +645,8 @@ public ConfigRemote? ActiveRemote
642
645
get { return activeRemote ; }
643
646
private set
644
647
{
645
- if ( activeRemote . HasValue != value . HasValue || ( activeRemote . HasValue && ! activeRemote . Value . Equals ( value . Value ) ) )
648
+ if ( activeRemote . HasValue != value . HasValue ||
649
+ activeRemote . HasValue && ! activeRemote . Value . Equals ( value . Value ) )
646
650
{
647
651
activeRemote = value ;
648
652
Logger . Trace ( "OnActiveRemoteChanged: {0}" , value ? . ToString ( ) ?? "NULL" ) ;
0 commit comments