feature: support to enable --squash and --push option while finishing git-flow branches (#1290)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-09 10:47:36 +08:00
parent e8bf58f6c3
commit ebe0e61367
No known key found for this signature in database
6 changed files with 47 additions and 6 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using Avalonia.Threading;
@ -134,7 +135,7 @@ namespace SourceGit.Commands
return start.Exec();
}
public static bool Finish(string repo, string type, string name, bool keepBranch, Models.ICommandLog log)
public static bool Finish(string repo, string type, string name, bool squash, bool push, bool keepBranch, Models.ICommandLog log)
{
if (!SUPPORTED_BRANCH_TYPES.Contains(type))
{
@ -146,11 +147,22 @@ namespace SourceGit.Commands
return false;
}
var option = keepBranch ? "-k" : string.Empty;
var builder = new StringBuilder();
builder.Append("flow ");
builder.Append(type);
builder.Append(" finish ");
if (squash)
builder.Append("--squash ");
if (push)
builder.Append("--push ");
if (keepBranch)
builder.Append("-k ");
builder.Append(name);
var finish = new Command();
finish.WorkingDirectory = repo;
finish.Context = repo;
finish.Args = $"flow {type} finish {option} {name}";
finish.Args = builder.ToString();
finish.Log = log;
return finish.Exec();
}

View file

@ -323,6 +323,8 @@
<x:String x:Key="Text.GitFlow.FinishHotfix" xml:space="preserve">FLOW - Finish Hotfix</x:String>
<x:String x:Key="Text.GitFlow.FinishRelease" xml:space="preserve">FLOW - Finish Release</x:String>
<x:String x:Key="Text.GitFlow.FinishTarget" xml:space="preserve">Target:</x:String>
<x:String x:Key="Text.GitFlow.FinishWithPush" xml:space="preserve">Push to remote(s) after performing finish</x:String>
<x:String x:Key="Text.GitFlow.FinishWithSquash" xml:space="preserve">Squash during merge</x:String>
<x:String x:Key="Text.GitFlow.Hotfix" xml:space="preserve">Hotfix:</x:String>
<x:String x:Key="Text.GitFlow.HotfixPrefix" xml:space="preserve">Hotfix Prefix:</x:String>
<x:String x:Key="Text.GitFlow.Init" xml:space="preserve">Initialize Git-Flow</x:String>

View file

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

View file

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

View file

@ -13,6 +13,18 @@ namespace SourceGit.ViewModels
public bool IsRelease => _type == "release";
public bool IsHotfix => _type == "hotfix";
public bool Squash
{
get;
set;
} = false;
public bool AutoPush
{
get;
set;
} = false;
public bool KeepBranch
{
get;
@ -39,7 +51,7 @@ namespace SourceGit.ViewModels
return Task.Run(() =>
{
var succ = Commands.GitFlow.Finish(_repo.FullPath, _type, name, KeepBranch, log);
var succ = Commands.GitFlow.Finish(_repo.FullPath, _type, name, Squash, AutoPush, KeepBranch, log);
log.Complete();
CallUIThread(() => _repo.SetWatcherEnabled(true));
return succ;

View file

@ -19,7 +19,7 @@
Classes="bold"
Text="{DynamicResource Text.GitFlow.FinishHotfix}"
IsVisible="{Binding IsHotfix}"/>
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="150,*">
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32" ColumnDefinitions="150,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@ -30,8 +30,19 @@
</StackPanel>
<CheckBox Grid.Row="1" Grid.Column="1"
Content="{DynamicResource Text.GitFlow.FinishWithSquash}"
IsChecked="{Binding Squash, Mode=TwoWay}"
ToolTip.Tip="--squash"/>
<CheckBox Grid.Row="2" Grid.Column="1"
Content="{DynamicResource Text.GitFlow.FinishWithPush}"
IsChecked="{Binding AutoPush, Mode=TwoWay}"
ToolTip.Tip="--push"/>
<CheckBox Grid.Row="3" Grid.Column="1"
Content="{DynamicResource Text.GitFlow.KeepBranchAfterFinish}"
IsChecked="{Binding KeepBranch, Mode=TwoWay}"/>
IsChecked="{Binding KeepBranch, Mode=TwoWay}"
ToolTip.Tip="-k"/>
</Grid>
</StackPanel>
</UserControl>