Skip to content

Commit

Permalink
Ignore commit message template if empty, Add support for BugTraq, #32
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Jun 8, 2017
1 parent bbc0e25 commit 9c7d8af
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 90 deletions.
8 changes: 7 additions & 1 deletion TGit/Commands/ContextMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ private void CommitContextCommand(object sender, EventArgs e)
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
ProcessHelper.StartTortoiseGitProc($"/command:commit /path:\"{currentFilePath}\" /logmsg:\"{GitHelper.GetCommitMessage(_generalOptions.CommitMessage, _dte)}\" /closeonend:{_generalOptions.CloseOnEnd}");
var commitMessage = GitHelper.GetCommitMessage(_generalOptions.CommitMessage, _dte);
var bugId = GitHelper.GetCommitMessage(_generalOptions.BugId, _dte);

ProcessHelper.StartTortoiseGitProc($"/command:commit /path:\"{currentFilePath}\" " +
$"{(string.IsNullOrEmpty(commitMessage) ? string.Empty : $"/logmsg:\"{commitMessage}\"")} " +
$"{(!string.IsNullOrEmpty(bugId) && !string.IsNullOrEmpty(EnvHelper.GitConfig.BugTraqMessage) ? $"/bugid:\"{bugId}\"" : string.Empty)} " +
$"/closeonend:{_generalOptions.CloseOnEnd}");
}
private void RevertContextCommand(object sender, EventArgs e)
{
Expand Down
58 changes: 29 additions & 29 deletions TGit/Commands/GitFlowMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void InitCommand(object sender, EventArgs e)
var flowDialog = new FlowDialog();
if (flowDialog.ShowDialog() != DialogResult.OK) return;

var versionTag = string.IsNullOrEmpty(flowDialog.FlowOptions.TagPrefix) ? "\"\"" : flowDialog.FlowOptions.TagPrefix;
var versionTag = string.IsNullOrEmpty(flowDialog.GitConfig.TagPrefix) ? "\"\"" : flowDialog.GitConfig.TagPrefix;

/* 1. Add GitFlow config options
* 2. Checkout develop branch (create if it doesn't exist, reset if it does)
Expand All @@ -78,20 +78,20 @@ private void InitCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"config --add gitflow.branch.master {flowDialog.FlowOptions.MasterBranch}") +
FormatCliCommand($"config --add gitflow.branch.develop {flowDialog.FlowOptions.DevelopBranch}") +
FormatCliCommand($"config --add gitflow.prefix.feature {flowDialog.FlowOptions.FeaturePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.release {flowDialog.FlowOptions.ReleasePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.hotfix {flowDialog.FlowOptions.HotfixPrefix}") +
FormatCliCommand($"config --add gitflow.branch.master {flowDialog.GitConfig.MasterBranch}") +
FormatCliCommand($"config --add gitflow.branch.develop {flowDialog.GitConfig.DevelopBranch}") +
FormatCliCommand($"config --add gitflow.prefix.feature {flowDialog.GitConfig.FeaturePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.release {flowDialog.GitConfig.ReleasePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.hotfix {flowDialog.GitConfig.HotfixPrefix}") +
FormatCliCommand($"config --add gitflow.prefix.versiontag {versionTag}") +
(GitHelper.RemoteBranchExists(flowDialog.FlowOptions.DevelopBranch) ?
(GitHelper.RemoteBranchExists(flowDialog.GitConfig.DevelopBranch) ?
"echo." :
FormatCliCommand($"checkout -b {flowDialog.FlowOptions.DevelopBranch}", false)),
FormatCliCommand($"checkout -b {flowDialog.GitConfig.DevelopBranch}", false)),
"Initializing GitFlow"
);
process.WaitForExit();

EnvHelper.GetFlowOptions();
EnvHelper.GetGitConfig();
EnvHelper.GetBranchName();
}

Expand All @@ -101,7 +101,7 @@ private void StartFeatureCommand(object sender, EventArgs e)
var featureName = Interaction.InputBox("Feature Name:", "Start New Feature");
if (string.IsNullOrEmpty(featureName)) return;

var flowOptions = GitHelper.GetFlowOptions();
var flowOptions = GitHelper.GetGitConfig();

/* 1. Switch to the develop branch
* 2. Pull latest changes on develop
Expand Down Expand Up @@ -144,7 +144,7 @@ private void FinishFeatureCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(EnvHelper.SolutionDir)) return;
var featureBranch = GitHelper.GetCurrentBranchName(false);
var featureName = GitHelper.GetCurrentBranchName(true);
EnvHelper.GetFlowOptions();
EnvHelper.GetGitConfig();

/* 1. Switch to the develop branch
* 2. Pull latest changes on develop
Expand All @@ -157,11 +157,11 @@ private void FinishFeatureCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand($"checkout {EnvHelper.GitConfig.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {featureBranch}", false),
$"Finishing feature {featureName}",
featureBranch, null, _options, FormatCliCommand($"push origin {EnvHelper.FlowOptions.DevelopBranch}")
featureBranch, null, _options, FormatCliCommand($"push origin {EnvHelper.GitConfig.DevelopBranch}")
);
}

Expand Down Expand Up @@ -200,7 +200,7 @@ private void StartReleaseCommand(object sender, EventArgs e)
var releaseVersion = Interaction.InputBox("Release Version:", "Start New Release");
if (string.IsNullOrEmpty(releaseVersion)) return;

var flowOptions = GitHelper.GetFlowOptions();
var flowOptions = GitHelper.GetGitConfig();

/* 1. Switch to the develop branch
* 2. Pull latest changes on develop
Expand All @@ -222,7 +222,7 @@ private void FinishReleaseCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(EnvHelper.SolutionDir)) return;
var releaseBranch = GitHelper.GetCurrentBranchName(false);
var releaseName = GitHelper.GetCurrentBranchName(true);
EnvHelper.GetFlowOptions();
EnvHelper.GetGitConfig();

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -241,18 +241,18 @@ private void FinishReleaseCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand($"checkout {EnvHelper.GitConfig.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {releaseBranch}") +
FormatCliCommand($"tag {EnvHelper.FlowOptions.TagPrefix}{releaseName}") +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand($"tag {EnvHelper.GitConfig.TagPrefix}{releaseName}") +
FormatCliCommand($"checkout {EnvHelper.GitConfig.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {releaseBranch}", false),
$"Finishing release {releaseName}",
releaseBranch, null, _options,
FormatCliCommand($"push origin {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.TagPrefix}{releaseName}")
FormatCliCommand($"push origin {EnvHelper.GitConfig.DevelopBranch}") +
FormatCliCommand($"push origin {EnvHelper.GitConfig.MasterBranch}") +
FormatCliCommand($"push origin {EnvHelper.GitConfig.TagPrefix}{releaseName}")
);
}

Expand All @@ -262,7 +262,7 @@ private void StartHotfixCommand(object sender, EventArgs e)
var hotfixVersion = Interaction.InputBox("Hotfix Version:", "Start New Hotfix");
if (string.IsNullOrEmpty(hotfixVersion)) return;

var flowOptions = GitHelper.GetFlowOptions();
var flowOptions = GitHelper.GetGitConfig();

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -284,7 +284,7 @@ private void FinishHotfixCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(EnvHelper.SolutionDir)) return;
var hotfixBranch = GitHelper.GetCurrentBranchName(false);
var hotfixName = GitHelper.GetCurrentBranchName(true);
EnvHelper.GetFlowOptions();
EnvHelper.GetGitConfig();

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -303,18 +303,18 @@ private void FinishHotfixCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand($"checkout {EnvHelper.GitConfig.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {hotfixBranch}") +
FormatCliCommand($"tag {EnvHelper.FlowOptions.TagPrefix}{hotfixName}") +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand($"tag {EnvHelper.GitConfig.TagPrefix}{hotfixName}") +
FormatCliCommand($"checkout {EnvHelper.GitConfig.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {hotfixBranch}", false),
$"Finishing hotfix {hotfixName}",
hotfixBranch, null, _options,
FormatCliCommand($"push origin {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.TagPrefix}{hotfixName}")
FormatCliCommand($"push origin {EnvHelper.GitConfig.DevelopBranch}") +
FormatCliCommand($"push origin {EnvHelper.GitConfig.MasterBranch}") +
FormatCliCommand($"push origin {EnvHelper.GitConfig.TagPrefix}{hotfixName}")
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions TGit/Commands/MainMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void AddCommands()

private void PreCommand()
{
EnvHelper.GetFlowOptions();
EnvHelper.GetGitConfig();
EnvHelper.GetBranchName();
EnvHelper.GetStash();
FileHelper.SaveAllFiles(_dte);
Expand All @@ -72,8 +72,13 @@ private void FetchCommand(object sender, EventArgs e)
private void CommitCommand(object sender, EventArgs e)
{
PreCommand();
var commitMessage = GitHelper.GetCommitMessage(_generalOptions.CommitMessage, _dte);
var bugId = GitHelper.GetCommitMessage(_generalOptions.BugId, _dte);
ProcessHelper.StartTortoiseGitProc(
$"/command:commit /path:\"{EnvHelper.SolutionDir}\" /logmsg:\"{GitHelper.GetCommitMessage(_generalOptions.CommitMessage, _dte)}\" /closeonend:{_generalOptions.CloseOnEnd}");
$"/command:commit /path:\"{EnvHelper.SolutionDir}\" " +
$"{(string.IsNullOrEmpty(commitMessage) ? string.Empty : $"/logmsg:\"{commitMessage}\"")} " +
$"{(!string.IsNullOrEmpty(bugId) && !string.IsNullOrEmpty(EnvHelper.GitConfig.BugTraqMessage) ? $"/bugid:\"{bugId}\"" : string.Empty)} " +
$"/closeonend:{_generalOptions.CloseOnEnd}");
}
private void PushCommand(object sender, EventArgs e)
{
Expand Down
4 changes: 2 additions & 2 deletions TGit/FlowDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SamirBoulema.TGit
{
public partial class FlowDialog : Form
{
public FlowOptions FlowOptions;
public GitConfig GitConfig;

public FlowDialog()
{
Expand All @@ -20,7 +20,7 @@ private void cancelButton_Click(object sender, EventArgs e)
private void okButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
FlowOptions = new FlowOptions
GitConfig = new GitConfig
{
DevelopBranch = developTextBox.Text,
MasterBranch = masterTextBox.Text,
Expand Down
11 changes: 8 additions & 3 deletions TGit/FlowOptions.cs → TGit/GitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

namespace SamirBoulema.TGit
{
public class FlowOptions
public class GitConfig
{
public string MasterBranch;
public string DevelopBranch;
public string FeaturePrefix;
public string ReleasePrefix;
public string HotfixPrefix;
public string TagPrefix;
public string BugTraqMessage;

public FlowOptions()
public GitConfig()
{

}

public FlowOptions(string input)
public GitConfig(string input)
{
MasterBranch = string.Empty;
DevelopBranch = string.Empty;
Expand Down Expand Up @@ -51,6 +52,10 @@ public FlowOptions(string input)
{
TagPrefix = line.Split(' ').Last();
}
else if (line.StartsWith("bugtraq.message"))
{
BugTraqMessage = line.Split(' ').Last();
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions TGit/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public static void ApplyStash_BeforeQueryStatus(object sender, EventArgs e)
public static void Feature_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow;
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(EnvHelper.FlowOptions.FeaturePrefix);
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(EnvHelper.GitConfig.FeaturePrefix);
}

public static void Hotfix_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow;
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(EnvHelper.FlowOptions.HotfixPrefix);
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(EnvHelper.GitConfig.HotfixPrefix);
}

public static void Release_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow;
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(EnvHelper.FlowOptions.ReleasePrefix);
((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(EnvHelper.GitConfig.ReleasePrefix);
}

public static void Solution_BeforeQueryStatus(object sender, EventArgs e)
Expand Down
40 changes: 11 additions & 29 deletions TGit/Helpers/EnvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,35 @@ namespace SamirBoulema.TGit.Helpers
{
public static class EnvHelper
{
public static FlowOptions FlowOptions;
public static GitConfig GitConfig;
public static bool IsGitFlow;
public static string BranchName;
public static string SolutionDir;
public static bool HasStash;
public static string TortoiseGitProc;
public static string Git;

public static void GetFlowOptions()
public static void GetGitConfig()
{
FlowOptions = GitHelper.GetFlowOptions();
IsGitFlow = !string.IsNullOrEmpty(FlowOptions.MasterBranch);
GitConfig = GitHelper.GetGitConfig();
IsGitFlow = !string.IsNullOrEmpty(GitConfig.MasterBranch);
}

public static void GetBranchName()
{
BranchName = GitHelper.GetCurrentBranchName(false);
}
public static void GetBranchName() => BranchName = GitHelper.GetCurrentBranchName(false);

public static void GetSolutionDir(DTE dte)
{
SolutionDir = FileHelper.GetSolutionDir(dte);
}
public static void GetSolutionDir(DTE dte) => SolutionDir = FileHelper.GetSolutionDir(dte);

public static void GetStash()
{
HasStash = ProcessHelper.StartProcessGit("stash list");
}
public static void GetStash() => HasStash = ProcessHelper.StartProcessGit("stash list");

public static void GetTortoiseGitProc()
{
TortoiseGitProc = FileHelper.GetTortoiseGitProc();
}
public static void GetTortoiseGitProc() => TortoiseGitProc = FileHelper.GetTortoiseGitProc();

public static void GetGit()
{
Git = FileHelper.GetMSysGit();
}
public static void GetGit() => Git = FileHelper.GetMSysGit();

public static bool HasSolutionDir()
{
return !string.IsNullOrEmpty(SolutionDir);
}
public static bool HasSolutionDir() => !string.IsNullOrEmpty(SolutionDir);

public static void Clear()
{
FlowOptions = null;
GitConfig = null;
IsGitFlow = false;
BranchName = string.Empty;
SolutionDir = string.Empty;
Expand Down
18 changes: 10 additions & 8 deletions TGit/Helpers/GitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public static class GitHelper
{
public static string GetCommitMessage(string commitMessageTemplate, DTE dte)
{
if (string.IsNullOrEmpty(commitMessageTemplate)) return string.Empty;

var commitMessage = commitMessageTemplate;
commitMessage = commitMessage.Replace("$(BranchName)", GetCurrentBranchName(false));
commitMessage = commitMessage.Replace("$(FeatureName)", GetCurrentBranchName(true));
Expand All @@ -29,17 +31,17 @@ public static string GetCurrentBranchName(bool trimPrefix)

if (branchName == null) return string.Empty;

if (branchName.StartsWith(EnvHelper.FlowOptions.FeaturePrefix) && trimPrefix)
if (branchName.StartsWith(EnvHelper.GitConfig.FeaturePrefix) && trimPrefix)
{
return branchName.Substring(EnvHelper.FlowOptions.FeaturePrefix.Length);
return branchName.Substring(EnvHelper.GitConfig.FeaturePrefix.Length);
}
if (branchName.StartsWith(EnvHelper.FlowOptions.ReleasePrefix) && trimPrefix)
if (branchName.StartsWith(EnvHelper.GitConfig.ReleasePrefix) && trimPrefix)
{
return branchName.Substring(EnvHelper.FlowOptions.ReleasePrefix.Length);
return branchName.Substring(EnvHelper.GitConfig.ReleasePrefix.Length);
}
if (branchName.StartsWith(EnvHelper.FlowOptions.HotfixPrefix) && trimPrefix)
if (branchName.StartsWith(EnvHelper.GitConfig.HotfixPrefix) && trimPrefix)
{
return branchName.Substring(EnvHelper.FlowOptions.HotfixPrefix.Length);
return branchName.Substring(EnvHelper.GitConfig.HotfixPrefix.Length);
}

return branchName;
Expand All @@ -54,9 +56,9 @@ public static string GetSshSetup()
return $"set GIT_SSH={FileHelper.GetTortoiseGitPlink()} && ";
}

public static FlowOptions GetFlowOptions()
public static GitConfig GetGitConfig()
{
return new FlowOptions(ProcessHelper.StartProcessGitResult("config --get-regexp gitflow"));
return new GitConfig(ProcessHelper.StartProcessGitResult("config --get-regexp gitflow"));
}

public static bool RemoteBranchExists(string branch)
Expand Down
Loading

0 comments on commit 9c7d8af

Please sign in to comment.