Skip to content

Commit

Permalink
Fix Null reference with BranchName
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Jun 18, 2018
1 parent d37ecf3 commit 9609f8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 4 additions & 5 deletions TGit/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell;
using System;
using System.ComponentModel.Design;

Expand Down Expand Up @@ -49,21 +48,21 @@ public static void Feature_BeforeQueryStatus(object sender, EventArgs e)
{
var gitConfig = GitHelper.GetGitConfig();
((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow();
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(gitConfig.FeaturePrefix);
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchNameStartsWith(gitConfig.FeaturePrefix);
}

public static void Hotfix_BeforeQueryStatus(object sender, EventArgs e)
{
var gitConfig = GitHelper.GetGitConfig();
((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow();
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(gitConfig.HotfixPrefix);
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchNameStartsWith(gitConfig.HotfixPrefix);
}

public static void Release_BeforeQueryStatus(object sender, EventArgs e)
{
var gitConfig = GitHelper.GetGitConfig();
((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow();
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(gitConfig.ReleasePrefix);
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchNameStartsWith(gitConfig.ReleasePrefix);
}

public static void Solution_BeforeQueryStatus(object sender, EventArgs e)
Expand Down
11 changes: 9 additions & 2 deletions TGit/Helpers/EnvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace SamirBoulema.TGit.Helpers
{
public static class EnvHelper
{
public static string BranchName;
private static string _solutionDir;
private static string _tortoiseGitProc;
private static string _git;
Expand Down Expand Up @@ -62,9 +61,17 @@ public static string GetGit()

public static bool HasSolutionDir(DTE dte = null) => !string.IsNullOrEmpty(GetSolutionDir(dte));

public static bool BranchNameStartsWith(string name, DTE dte = null)
{
if (dte == null)
{
dte = Dte;
}
return GitHelper.GetCurrentBranchName(false, dte).StartsWith(name);
}

public static void Clear()
{
BranchName = string.Empty;
_solutionDir = string.Empty;
_tortoiseGitProc = string.Empty;
_git = string.Empty;
Expand Down

0 comments on commit 9609f8e

Please sign in to comment.