Skip to content

Commit 22443ad

Browse files
committed
Throw SourceControlException in one place rather than NullReferenceException to prevent crash. Disable commands for Source Control when they can't work.
1 parent 5d49b4e commit 22443ad

File tree

4 files changed

+138
-100
lines changed

4 files changed

+138
-100
lines changed

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.IO;
88
using System.Linq;
99
using System.Windows.Forms;
10-
using System.Windows.Input;
1110
using System.Windows.Media.Imaging;
1211
using Microsoft.Vbe.Interop;
1312
using Ninject;
@@ -68,10 +67,10 @@ public SourceControlViewViewModel(
6867
_wrapperFactory = wrapperFactory;
6968
_messageBox = messageBox;
7069

71-
_initRepoCommand = new DelegateCommand(_ => InitRepo());
72-
_openRepoCommand = new DelegateCommand(_ => OpenRepo());
73-
_cloneRepoCommand = new DelegateCommand(_ => ShowCloneRepoGrid());
74-
_publishRepoCommand = new DelegateCommand(_ => ShowPublishRepoGrid());
70+
_initRepoCommand = new DelegateCommand(_ => InitRepo(), _ => _vbe.VBProjects.Count != 0);
71+
_openRepoCommand = new DelegateCommand(_ => OpenRepo(), _ => _vbe.VBProjects.Count != 0);
72+
_cloneRepoCommand = new DelegateCommand(_ => ShowCloneRepoGrid(), _ => _vbe.VBProjects.Count != 0);
73+
_publishRepoCommand = new DelegateCommand(_ => ShowPublishRepoGrid(), _ => _vbe.VBProjects.Count != 0 && Provider != null);
7574
_refreshCommand = new DelegateCommand(_ => Refresh());
7675
_dismissErrorMessageCommand = new DelegateCommand(_ => DismissErrorMessage());
7776
_showFilePickerCommand = new DelegateCommand(_ => ShowFilePicker());

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public virtual void CreateBranch(string sourceBranch, string branch)
5656

5757
public virtual IRepository InitVBAProject(string directory)
5858
{
59+
if (Project == null)
60+
{
61+
throw new SourceControlException(SourceControlText.GitNotInit,
62+
new Exception(SourceControlText.NoProjectOpen));
63+
}
64+
5965
var projectName = GetProjectNameFromDirectory(directory);
6066
if (projectName != string.Empty && projectName != Project.Name)
6167
{

Rubberduck.SourceControl/SourceControlText.Designer.cs

Lines changed: 41 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)