Skip to content

Commit b017124

Browse files
authored
Merge pull request #2114 from Hosch250/sourceControlBugs
Source control bugs
2 parents 2b7711c + 6a32091 commit b017124

File tree

12 files changed

+239
-119
lines changed

12 files changed

+239
-119
lines changed

RetailCoder.VBE/UI/SourceControl/BranchesViewViewModel.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public string CurrentBranch
140140
}
141141
catch (SourceControlException ex)
142142
{
143-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
143+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
144144
}
145145
catch
146146
{
@@ -324,7 +324,7 @@ private void CreateBranchOk()
324324
}
325325
catch (SourceControlException ex)
326326
{
327-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
327+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
328328
}
329329
catch
330330
{
@@ -358,7 +358,7 @@ private void MergeBranchOk()
358358
}
359359
catch (SourceControlException ex)
360360
{
361-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
361+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
362362
Provider.NotifyExternalFileChanges = true;
363363
Provider.HandleVbeSinkEvents = true;
364364
return;
@@ -394,7 +394,7 @@ private void DeleteBranch(bool isBranchPublished)
394394
}
395395
catch (SourceControlException ex)
396396
{
397-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
397+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
398398
}
399399
catch
400400
{
@@ -422,7 +422,7 @@ private void PublishBranch()
422422
}
423423
catch (SourceControlException ex)
424424
{
425-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
425+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
426426
}
427427
catch
428428
{
@@ -443,7 +443,7 @@ private void UnpublishBranch()
443443
}
444444
catch (SourceControlException ex)
445445
{
446-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
446+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
447447
}
448448
catch
449449
{
@@ -531,12 +531,21 @@ public CommandBase UnpublishBranchToolbarButtonCommand
531531
}
532532

533533
public event EventHandler<ErrorEventArgs> ErrorThrown;
534-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
534+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
535535
{
536536
var handler = ErrorThrown;
537537
if (handler != null)
538538
{
539-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
539+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
540+
}
541+
}
542+
543+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
544+
{
545+
var handler = ErrorThrown;
546+
if (handler != null)
547+
{
548+
handler(this, new ErrorEventArgs(title, message, notificationType));
540549
}
541550
}
542551
}

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void UndoChanges(IFileStatusEntry fileStatusEntry)
158158
}
159159
catch (SourceControlException ex)
160160
{
161-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
161+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
162162
}
163163
catch
164164
{
@@ -213,7 +213,7 @@ private void Commit()
213213
}
214214
catch (SourceControlException ex)
215215
{
216-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
216+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
217217
}
218218
catch
219219
{
@@ -274,12 +274,21 @@ public CommandBase IncludeChangesToolbarButtonCommand
274274
}
275275

276276
public event EventHandler<ErrorEventArgs> ErrorThrown;
277-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
277+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
278278
{
279279
var handler = ErrorThrown;
280280
if (handler != null)
281281
{
282-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
282+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
283+
}
284+
}
285+
286+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
287+
{
288+
var handler = ErrorThrown;
289+
if (handler != null)
290+
{
291+
handler(this, new ErrorEventArgs(title, message, notificationType));
283292
}
284293
}
285294
}

RetailCoder.VBE/UI/SourceControl/IControlViewModel.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,34 @@
33

44
namespace Rubberduck.UI.SourceControl
55
{
6+
using System.Linq;
7+
68
public class ErrorEventArgs
79
{
8-
public readonly string Message;
10+
public readonly string Title;
911
public readonly string InnerMessage;
1012
public readonly NotificationType NotificationType;
1113

12-
public ErrorEventArgs(string message, string innerMessage, NotificationType notificationType)
14+
public ErrorEventArgs(string title, Exception innerException, NotificationType notificationType)
15+
{
16+
Title = title;
17+
InnerMessage = GetInnerExceptionMessage(innerException);
18+
NotificationType = notificationType;
19+
}
20+
21+
public ErrorEventArgs(string title, string message, NotificationType notificationType)
1322
{
14-
Message = message;
15-
InnerMessage = innerMessage;
23+
Title = title;
24+
InnerMessage = message;
1625
NotificationType = notificationType;
1726
}
27+
28+
private string GetInnerExceptionMessage(Exception ex)
29+
{
30+
return ex is AggregateException
31+
? string.Join(Environment.NewLine, ((AggregateException) ex).InnerExceptions.Select(s => s.Message))
32+
: ex.Message;
33+
}
1834
}
1935

2036
public interface IControlViewModel

RetailCoder.VBE/UI/SourceControl/SettingsViewViewModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,21 @@ public CommandBase ShowGitAttributesCommand
241241
}
242242

243243
public event EventHandler<ErrorEventArgs> ErrorThrown;
244-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
244+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
245245
{
246246
var handler = ErrorThrown;
247247
if (handler != null)
248248
{
249-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
249+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
250+
}
251+
}
252+
253+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
254+
{
255+
var handler = ErrorThrown;
256+
if (handler != null)
257+
{
258+
handler(this, new ErrorEventArgs(title, message, notificationType));
250259
}
251260
}
252261

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ private void ViewModel_ErrorThrown(object sender, ErrorEventArgs e)
586586
}
587587
else
588588
{
589-
Logger.Trace("Displaying {0} with title '{1}' and message '{2}'", e.NotificationType, e.Message, e.InnerMessage);
589+
Logger.Trace("Displaying {0} with title '{1}' and message '{2}'", e.NotificationType, e.Title, e.InnerMessage);
590590

591-
ErrorTitle = e.Message;
591+
ErrorTitle = e.Title;
592592
ErrorMessage = e.InnerMessage;
593593

594594
IconMappings.TryGetValue(e.NotificationType, out _errorIcon);
@@ -643,7 +643,7 @@ private void InitRepo()
643643
catch (SourceControlException ex)
644644
{
645645
ViewModel_ErrorThrown(this,
646-
new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
646+
new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
647647
}
648648
catch
649649
{
@@ -722,7 +722,7 @@ private void OpenRepo()
722722
catch (SourceControlException ex)
723723
{
724724
_sinks.IsEnabled = true;
725-
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
725+
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
726726
return;
727727
}
728728
catch
@@ -769,7 +769,7 @@ private void CloneRepo(SecureCredentials credentials = null)
769769
_isCloning = false;
770770
}
771771

772-
ViewModel_ErrorThrown(this, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
772+
ViewModel_ErrorThrown(this, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
773773
return;
774774
}
775775
catch
@@ -805,7 +805,7 @@ private void PublishRepo()
805805
}
806806
catch (SourceControlException ex)
807807
{
808-
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
808+
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
809809
}
810810
catch
811811
{
@@ -876,7 +876,7 @@ private void OpenRepoAssignedToProject()
876876
}
877877
catch (SourceControlException ex)
878878
{
879-
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
879+
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException, NotificationType.Error));
880880
Status = RubberduckUI.Offline;
881881

882882
_config.Repositories.Remove(_config.Repositories.FirstOrDefault(repo => repo.Id == _vbe.ActiveVBProject.HelpFile));

RetailCoder.VBE/UI/SourceControl/UnsyncedCommitsViewViewModel.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void FetchCommits()
115115
}
116116
catch (SourceControlException ex)
117117
{
118-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
118+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
119119
}
120120
catch
121121
{
@@ -136,7 +136,7 @@ private void PullCommits()
136136
}
137137
catch (SourceControlException ex)
138138
{
139-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
139+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
140140
}
141141
catch
142142
{
@@ -157,7 +157,7 @@ private void PushCommits()
157157
}
158158
catch (SourceControlException ex)
159159
{
160-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
160+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
161161
}
162162
catch
163163
{
@@ -179,7 +179,7 @@ private void SyncCommits()
179179
}
180180
catch (SourceControlException ex)
181181
{
182-
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
182+
RaiseErrorEvent(ex.Message, ex.InnerException, NotificationType.Error);
183183
}
184184
catch
185185
{
@@ -226,12 +226,21 @@ public CommandBase SyncCommitsCommand
226226
}
227227

228228
public event EventHandler<ErrorEventArgs> ErrorThrown;
229-
private void RaiseErrorEvent(string message, string innerMessage, NotificationType notificationType)
229+
private void RaiseErrorEvent(string message, Exception innerException, NotificationType notificationType)
230230
{
231231
var handler = ErrorThrown;
232232
if (handler != null)
233233
{
234-
handler(this, new ErrorEventArgs(message, innerMessage, notificationType));
234+
handler(this, new ErrorEventArgs(message, innerException, notificationType));
235+
}
236+
}
237+
238+
private void RaiseErrorEvent(string title, string message, NotificationType notificationType)
239+
{
240+
var handler = ErrorThrown;
241+
if (handler != null)
242+
{
243+
handler(this, new ErrorEventArgs(title, message, notificationType));
235244
}
236245
}
237246
}

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ public virtual void Checkout(string branch)
120120

121121
public virtual void Undo(string filePath)
122122
{
123-
var componentName = Path.GetFileNameWithoutExtension(filePath);
124-
125123
if (File.Exists(filePath))
126124
{
127125
var component = Project.VBComponents.OfType<VBComponent>().FirstOrDefault(f => f.Name == filePath.Split('.')[0]);
@@ -142,6 +140,7 @@ public virtual IEnumerable<IFileStatusEntry> Status()
142140
{
143141
NotifyExternalFileChanges = false;
144142
Project.ExportSourceFiles(CurrentRepository.LocalLocation);
143+
Project.ImportDocumentTypeSourceFiles(CurrentRepository.LocalLocation);
145144
NotifyExternalFileChanges = true;
146145
return null;
147146
}

Rubberduck.VBEEditor/Extensions/VBComponentsExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ public static void ImportSourceFile(this VBComponents components, string filePat
4848
if (ext == VBComponentExtensions.DocClassExtension)
4949
{
5050
var component = components.Item(name);
51-
if (component != null)
52-
{
53-
component.CodeModule.Clear();
54-
component.CodeModule.AddFromString(codeString);
55-
}
51+
component.CodeModule.Clear();
52+
component.CodeModule.AddFromString(codeString);
5653
}
5754
else if (ext == VBComponentExtensions.FormExtension)
5855
{

Rubberduck.VBEEditor/Extensions/VbProjectExtensions.cs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,33 @@ public static void ImportSourceFiles(this VBProject project, string filePath)
103103
project.VBComponents.ImportSourceFile(file.FullName);
104104
}
105105
}
106-
106+
107+
108+
/// <summary>
109+
/// Imports all source code files from target directory into project.
110+
/// </summary>
111+
/// <remarks>
112+
/// Only files with extensions "cls", "bas, "frm", and "doccls" are imported.
113+
/// It is the callers responsibility to remove any existing components prior to importing.
114+
/// </remarks>
115+
/// <param name="project"></param>
116+
/// <param name="filePath">Directory path containing the source files.</param>
117+
public static void ImportDocumentTypeSourceFiles(this VBProject project, string filePath)
118+
{
119+
var dirInfo = new DirectoryInfo(filePath);
120+
121+
var files = dirInfo.EnumerateFiles()
122+
.Where(f => f.Extension == VBComponentExtensions.DocClassExtension);
123+
foreach (var file in files)
124+
{
125+
try
126+
{
127+
project.VBComponents.ImportSourceFile(file.FullName);
128+
}
129+
catch (IndexOutOfRangeException) { } // component didn't exist
130+
}
131+
}
132+
107133
public static void LoadAllComponents(this VBProject project, string filePath)
108134
{
109135
var dirInfo = new DirectoryInfo(filePath);
@@ -127,7 +153,14 @@ public static void LoadAllComponents(this VBProject project, string filePath)
127153
var file = files.SingleOrDefault(f => f.Name == name + f.Extension);
128154
if (file != null)
129155
{
130-
project.VBComponents.ImportSourceFile(file.FullName);
156+
try
157+
{
158+
project.VBComponents.ImportSourceFile(file.FullName);
159+
}
160+
catch (IndexOutOfRangeException)
161+
{
162+
exceptions.Add(new IndexOutOfRangeException(string.Format(VBEEditorText.NonexistentComponentErrorText, Path.GetFileNameWithoutExtension(file.FullName))));
163+
}
131164
}
132165
}
133166
catch (Exception ex)
@@ -142,7 +175,14 @@ public static void LoadAllComponents(this VBProject project, string filePath)
142175
{
143176
if (project.VBComponents.OfType<VBComponent>().All(v => v.Name + file.Extension != file.Name))
144177
{
145-
project.VBComponents.ImportSourceFile(file.FullName);
178+
try
179+
{
180+
project.VBComponents.ImportSourceFile(file.FullName);
181+
}
182+
catch (IndexOutOfRangeException)
183+
{
184+
exceptions.Add(new IndexOutOfRangeException(string.Format(VBEEditorText.NonexistentComponentErrorText, Path.GetFileNameWithoutExtension(file.FullName))));
185+
}
146186
}
147187
}
148188
catch (Exception ex)

0 commit comments

Comments
 (0)