Skip to content

Commit 86e19e4

Browse files
committed
prevented adding a new/duplicate Repository config entry everytime a repo is opened
1 parent a5931d0 commit 86e19e4

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private void InitRepo()
247247
var repo = _provider.InitVBAProject(folderPicker.SelectedPath);
248248
Provider = _providerFactory.CreateProvider(_vbe.ActiveVBProject, repo, _wrapperFactory);
249249

250-
AddRepoToConfig((Repository)repo);
250+
AddOrUpdateLocalPathConfig((Repository)repo);
251251
Status = RubberduckUI.Online;
252252
}
253253
}
@@ -267,10 +267,27 @@ private void SetChildPresenterSourceControlProviders(ISourceControlProvider prov
267267
}
268268
}
269269

270-
private void AddRepoToConfig(Repository repo)
270+
private void AddOrUpdateLocalPathConfig(Repository repo)
271271
{
272-
_config.Repositories.Add(repo);
273-
_configService.SaveConfiguration(_config);
272+
if (_config.Repositories.All(repository => repository.LocalLocation != repo.LocalLocation))
273+
{
274+
_config.Repositories.Add(repo);
275+
_configService.SaveConfiguration(_config);
276+
}
277+
else
278+
{
279+
var existing = _config.Repositories.Single(repository => repository.LocalLocation == repo.LocalLocation);
280+
if (string.IsNullOrEmpty(repo.RemoteLocation) && !string.IsNullOrEmpty(existing.RemoteLocation))
281+
{
282+
// config already has remote location and correct repository name - nothing to update
283+
return;
284+
}
285+
286+
existing.Name = repo.Name;
287+
existing.RemoteLocation = repo.RemoteLocation;
288+
289+
_configService.SaveConfiguration(_config);
290+
}
274291
}
275292

276293
private void OpenRepo()
@@ -295,7 +312,7 @@ private void OpenRepo()
295312
return;
296313
}
297314

298-
AddRepoToConfig(repo);
315+
AddOrUpdateLocalPathConfig(repo);
299316

300317
Status = RubberduckUI.Online;
301318
}
@@ -308,7 +325,7 @@ private void CloneRepo()
308325
_provider = _providerFactory.CreateProvider(_vbe.ActiveVBProject);
309326
var repo = _provider.Clone(RemotePath, LocalDirectory);
310327
Provider = _providerFactory.CreateProvider(_vbe.ActiveVBProject, repo, _wrapperFactory);
311-
AddRepoToConfig(new Repository
328+
AddOrUpdateLocalPathConfig(new Repository
312329
{
313330
Name = _vbe.ActiveVBProject.Name,
314331
LocalLocation = repo.LocalLocation,

0 commit comments

Comments
 (0)