From ebe0e613675d04718ec0afdc4a8121dc3bf821e3 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 9 May 2025 10:47:36 +0800 Subject: [PATCH] feature: support to enable `--squash` and `--push` option while finishing git-flow branches (#1290) Signed-off-by: leo --- src/Commands/GitFlow.cs | 18 +++++++++++++++--- src/Resources/Locales/en_US.axaml | 2 ++ src/Resources/Locales/zh_CN.axaml | 2 ++ src/Resources/Locales/zh_TW.axaml | 2 ++ src/ViewModels/GitFlowFinish.cs | 14 +++++++++++++- src/Views/GitFlowFinish.axaml | 15 +++++++++++++-- 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Commands/GitFlow.cs b/src/Commands/GitFlow.cs index 833d268d..e4fab235 100644 --- a/src/Commands/GitFlow.cs +++ b/src/Commands/GitFlow.cs @@ -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(); } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 5294f566..e2281a86 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -323,6 +323,8 @@ FLOW - Finish Hotfix FLOW - Finish Release Target: + Push to remote(s) after performing finish + Squash during merge Hotfix: Hotfix Prefix: Initialize Git-Flow diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 1593dc2e..d08c6f70 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -327,6 +327,8 @@ 结束修复分支 结束版本分支 目标分支 : + 完成后自动推送 + 压缩变更为单一提交后合并分支 修复分支 : 修复分支名前缀 : 初始化GIT工作流 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index a2a039b2..4cd68cad 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -327,6 +327,8 @@ 完成修復分支 完成發行分支 目標分支: + 完成後自動推送 + 壓縮為單一提交後合併 修復分支: 修復分支前置詞: 初始化 Git 工作流 diff --git a/src/ViewModels/GitFlowFinish.cs b/src/ViewModels/GitFlowFinish.cs index efc28db1..d7ad5d31 100644 --- a/src/ViewModels/GitFlowFinish.cs +++ b/src/ViewModels/GitFlowFinish.cs @@ -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; diff --git a/src/Views/GitFlowFinish.axaml b/src/Views/GitFlowFinish.axaml index 7af46fd9..6a16e95c 100644 --- a/src/Views/GitFlowFinish.axaml +++ b/src/Views/GitFlowFinish.axaml @@ -19,7 +19,7 @@ Classes="bold" Text="{DynamicResource Text.GitFlow.FinishHotfix}" IsVisible="{Binding IsHotfix}"/> - + + + + + + IsChecked="{Binding KeepBranch, Mode=TwoWay}" + ToolTip.Tip="-k"/>