Skip to content

Commit 7ad4a9f

Browse files
committed
Merge pull request #1750 from Hosch250/SourceControlTweaks
Source control tweaks
2 parents cf807b8 + f630d32 commit 7ad4a9f

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

RetailCoder.VBE/App.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent>
325325
return;
326326
}
327327

328+
_panelVM.RemoveComponent(e.Item);
329+
328330
_logger.Debug("Component '{0}' was removed.", e.Item.Name);
329331
_parser.State.ClearStateCache(e.Item, true);
330332
}
@@ -351,6 +353,8 @@ async void sink_ComponentAdded(object sender, DispatcherEventArgs<VBComponent> e
351353
return;
352354
}
353355

356+
_panelVM.AddComponent(e.Item);
357+
354358
_logger.Debug("Component '{0}' was added.", e.Item.Name);
355359
_parser.State.OnParseRequested(sender, e.Item);
356360
}

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ public void SetTab(SourceControlTab tab)
9090
SelectedItem = TabItems.First(t => t.ViewModel.Tab == tab);
9191
}
9292

93+
public void AddComponent(VBComponent component)
94+
{
95+
if (Provider == null) { return; }
96+
97+
var fileStatus = Provider.Status().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == component.Name);
98+
if (fileStatus != null)
99+
{
100+
Provider.AddFile(fileStatus.FilePath);
101+
}
102+
}
103+
104+
public void RemoveComponent(VBComponent component)
105+
{
106+
if (Provider == null) { return; }
107+
108+
var fileStatus = Provider.Status().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == component.Name);
109+
if (fileStatus != null)
110+
{
111+
Provider.RemoveFile(fileStatus.FilePath, true);
112+
}
113+
}
114+
93115
private static readonly IDictionary<NotificationType, BitmapImage> IconMappings =
94116
new Dictionary<NotificationType, BitmapImage>
95117
{
@@ -469,6 +491,9 @@ private void OpenRepoAssignedToProject()
469491
{
470492
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
471493
Status = RubberduckUI.Offline;
494+
495+
_config.Repositories.Remove(_config.Repositories.FirstOrDefault(repo => repo.Id == _vbe.ActiveVBProject.HelpFile));
496+
_configService.Save(_config);
472497
}
473498

474499
OnOpenRepoCompleted();
@@ -497,12 +522,10 @@ private bool ValidRepoExists()
497522
}
498523

499524
var possibleRepos = _config.Repositories.Where(repo => repo.Id == _vbe.ActiveVBProject.HelpFile);
500-
501525
var possibleCount = possibleRepos.Count();
502526

503527
//todo: if none are found, prompt user to create one
504-
//todo: more than one are found, prompt for correct one
505-
return possibleCount != 0 && possibleCount <= 1;
528+
return possibleCount == 1;
506529
}
507530

508531
private void ShowFilePicker()

Rubberduck.SourceControl/GitProvider.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,15 @@ public override void AddFile(string filePath)
437437
}
438438

439439
/// <summary>
440-
/// Removes file from staging area, but leaves the file in the working directory.
440+
/// Removes file from staging area.
441441
/// </summary>
442442
/// <param name="filePath"></param>
443-
public override void RemoveFile(string filePath)
443+
/// <param name="removeFromWorkingDirectory"></param>
444+
public override void RemoveFile(string filePath, bool removeFromWorkingDirectory)
444445
{
445446
try
446447
{
447-
_repo.Remove(filePath, false);
448+
_repo.Remove(filePath, removeFromWorkingDirectory);
448449
}
449450
catch (LibGit2SharpException ex)
450451
{
@@ -457,7 +458,8 @@ public override IEnumerable<IFileStatusEntry> Status()
457458
try
458459
{
459460
base.Status();
460-
return _repo.RetrieveStatus().Select(item => new FileStatusEntry(item));
461+
return _repo.RetrieveStatus(new StatusOptions {IncludeUnaltered = true})
462+
.Select(item => new FileStatusEntry(item));
461463
}
462464
catch (LibGit2SharpException ex)
463465
{

Rubberduck.SourceControl/ISourceControlProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public interface ISourceControlProvider
112112
/// Removes file from tracking.
113113
/// </summary>
114114
/// <param name="filePath"></param>
115-
void RemoveFile(string filePath);
115+
void RemoveFile(string filePath, bool removeFromWorkingDirectory);
116116

117117
/// <summary>
118118
/// Returns a collection of file status entries.

Rubberduck.SourceControl/Interop/ISourceControlProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public interface ISourceControlProvider
7575

7676
[DispId(16)]
7777
[Description("Removes file from tracking.")]
78-
void RemoveFile(string filePath);
78+
void RemoveFile(string filePath, bool removeFromWorkingDirectory);
7979

8080
[DispId(17)]
8181
[Description("Returns a collection of file status entries.\n Semantically the same as calling $git status.")]

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected SourceControlProviderBase(VBProject project, IRepository repository, I
3535
public abstract void Push();
3636
public abstract void Fetch(string remoteName);
3737
public abstract void AddFile(string filePath);
38-
public abstract void RemoveFile(string filePath);
38+
public abstract void RemoveFile(string filePath, bool removeFromWorkingDirectory);
3939
public abstract void CreateBranch(string branch);
4040
public abstract void DeleteBranch(string branch);
4141
public abstract IRepository Init(string directory, bool bare = false);

0 commit comments

Comments
 (0)