Skip to content

Commit ebe0e61

Browse files
committed
feature: support to enable --squash and --push option while finishing git-flow branches (#1290)
Signed-off-by: leo <[email protected]>
1 parent e8bf58f commit ebe0e61

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

src/Commands/GitFlow.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Text;
34

45
using Avalonia.Threading;
56

@@ -134,7 +135,7 @@ public static bool Start(string repo, string type, string name, Models.ICommandL
134135
return start.Exec();
135136
}
136137

137-
public static bool Finish(string repo, string type, string name, bool keepBranch, Models.ICommandLog log)
138+
public static bool Finish(string repo, string type, string name, bool squash, bool push, bool keepBranch, Models.ICommandLog log)
138139
{
139140
if (!SUPPORTED_BRANCH_TYPES.Contains(type))
140141
{
@@ -146,11 +147,22 @@ public static bool Finish(string repo, string type, string name, bool keepBranch
146147
return false;
147148
}
148149

149-
var option = keepBranch ? "-k" : string.Empty;
150+
var builder = new StringBuilder();
151+
builder.Append("flow ");
152+
builder.Append(type);
153+
builder.Append(" finish ");
154+
if (squash)
155+
builder.Append("--squash ");
156+
if (push)
157+
builder.Append("--push ");
158+
if (keepBranch)
159+
builder.Append("-k ");
160+
builder.Append(name);
161+
150162
var finish = new Command();
151163
finish.WorkingDirectory = repo;
152164
finish.Context = repo;
153-
finish.Args = $"flow {type} finish {option} {name}";
165+
finish.Args = builder.ToString();
154166
finish.Log = log;
155167
return finish.Exec();
156168
}

src/Resources/Locales/en_US.axaml

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@
323323
<x:String x:Key="Text.GitFlow.FinishHotfix" xml:space="preserve">FLOW - Finish Hotfix</x:String>
324324
<x:String x:Key="Text.GitFlow.FinishRelease" xml:space="preserve">FLOW - Finish Release</x:String>
325325
<x:String x:Key="Text.GitFlow.FinishTarget" xml:space="preserve">Target:</x:String>
326+
<x:String x:Key="Text.GitFlow.FinishWithPush" xml:space="preserve">Push to remote(s) after performing finish</x:String>
327+
<x:String x:Key="Text.GitFlow.FinishWithSquash" xml:space="preserve">Squash during merge</x:String>
326328
<x:String x:Key="Text.GitFlow.Hotfix" xml:space="preserve">Hotfix:</x:String>
327329
<x:String x:Key="Text.GitFlow.HotfixPrefix" xml:space="preserve">Hotfix Prefix:</x:String>
328330
<x:String x:Key="Text.GitFlow.Init" xml:space="preserve">Initialize Git-Flow</x:String>

src/Resources/Locales/zh_CN.axaml

+2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@
327327
<x:String x:Key="Text.GitFlow.FinishHotfix" xml:space="preserve">结束修复分支</x:String>
328328
<x:String x:Key="Text.GitFlow.FinishRelease" xml:space="preserve">结束版本分支</x:String>
329329
<x:String x:Key="Text.GitFlow.FinishTarget" xml:space="preserve">目标分支 :</x:String>
330+
<x:String x:Key="Text.GitFlow.FinishWithPush" xml:space="preserve">完成后自动推送</x:String>
331+
<x:String x:Key="Text.GitFlow.FinishWithSquash" xml:space="preserve">压缩变更为单一提交后合并分支</x:String>
330332
<x:String x:Key="Text.GitFlow.Hotfix" xml:space="preserve">修复分支 :</x:String>
331333
<x:String x:Key="Text.GitFlow.HotfixPrefix" xml:space="preserve">修复分支名前缀 :</x:String>
332334
<x:String x:Key="Text.GitFlow.Init" xml:space="preserve">初始化GIT工作流</x:String>

src/Resources/Locales/zh_TW.axaml

+2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@
327327
<x:String x:Key="Text.GitFlow.FinishHotfix" xml:space="preserve">完成修復分支</x:String>
328328
<x:String x:Key="Text.GitFlow.FinishRelease" xml:space="preserve">完成發行分支</x:String>
329329
<x:String x:Key="Text.GitFlow.FinishTarget" xml:space="preserve">目標分支:</x:String>
330+
<x:String x:Key="Text.GitFlow.FinishWithPush" xml:space="preserve">完成後自動推送</x:String>
331+
<x:String x:Key="Text.GitFlow.FinishWithSquash" xml:space="preserve">壓縮為單一提交後合併</x:String>
330332
<x:String x:Key="Text.GitFlow.Hotfix" xml:space="preserve">修復分支:</x:String>
331333
<x:String x:Key="Text.GitFlow.HotfixPrefix" xml:space="preserve">修復分支前置詞:</x:String>
332334
<x:String x:Key="Text.GitFlow.Init" xml:space="preserve">初始化 Git 工作流</x:String>

src/ViewModels/GitFlowFinish.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ public Models.Branch Branch
1313
public bool IsRelease => _type == "release";
1414
public bool IsHotfix => _type == "hotfix";
1515

16+
public bool Squash
17+
{
18+
get;
19+
set;
20+
} = false;
21+
22+
public bool AutoPush
23+
{
24+
get;
25+
set;
26+
} = false;
27+
1628
public bool KeepBranch
1729
{
1830
get;
@@ -39,7 +51,7 @@ public override Task<bool> Sure()
3951

4052
return Task.Run(() =>
4153
{
42-
var succ = Commands.GitFlow.Finish(_repo.FullPath, _type, name, KeepBranch, log);
54+
var succ = Commands.GitFlow.Finish(_repo.FullPath, _type, name, Squash, AutoPush, KeepBranch, log);
4355
log.Complete();
4456
CallUIThread(() => _repo.SetWatcherEnabled(true));
4557
return succ;

src/Views/GitFlowFinish.axaml

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Classes="bold"
2020
Text="{DynamicResource Text.GitFlow.FinishHotfix}"
2121
IsVisible="{Binding IsHotfix}"/>
22-
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="150,*">
22+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32" ColumnDefinitions="150,*">
2323
<TextBlock Grid.Row="0" Grid.Column="0"
2424
HorizontalAlignment="Right" VerticalAlignment="Center"
2525
Margin="0,0,8,0"
@@ -30,8 +30,19 @@
3030
</StackPanel>
3131

3232
<CheckBox Grid.Row="1" Grid.Column="1"
33+
Content="{DynamicResource Text.GitFlow.FinishWithSquash}"
34+
IsChecked="{Binding Squash, Mode=TwoWay}"
35+
ToolTip.Tip="--squash"/>
36+
37+
<CheckBox Grid.Row="2" Grid.Column="1"
38+
Content="{DynamicResource Text.GitFlow.FinishWithPush}"
39+
IsChecked="{Binding AutoPush, Mode=TwoWay}"
40+
ToolTip.Tip="--push"/>
41+
42+
<CheckBox Grid.Row="3" Grid.Column="1"
3343
Content="{DynamicResource Text.GitFlow.KeepBranchAfterFinish}"
34-
IsChecked="{Binding KeepBranch, Mode=TwoWay}"/>
44+
IsChecked="{Binding KeepBranch, Mode=TwoWay}"
45+
ToolTip.Tip="-k"/>
3546
</Grid>
3647
</StackPanel>
3748
</UserControl>

0 commit comments

Comments
 (0)