From d8d61ed92e57c4f35a6aa230d50633c30e63d7b0 Mon Sep 17 00:00:00 2001 From: Harsh Abasaheb Chavan Date: Sun, 15 Mar 2026 04:29:41 +0530 Subject: [PATCH] Add gitFlowFinishArgs config option for git flow finish Allow users to pass extra arguments to git flow finish via a new gitFlowFinishArgs config option. This is useful for teams that need flags like --keepremote to prevent remote branch deletion after finishing a git flow branch. Closes #5296 Made-with: Cursor --- docs-master/Config.md | 4 ++++ pkg/commands/git_commands/flow.go | 4 +++- pkg/commands/git_commands/flow_test.go | 33 +++++++++++++++++++++++++- pkg/config/user_config.go | 3 +++ schema-master/config.json | 7 ++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/docs-master/Config.md b/docs-master/Config.md index aa149e9e8ea..c3ab56036c8 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -481,6 +481,10 @@ git: # to 40 to disable truncation. truncateCopiedCommitHashesTo: 12 + # Extra arguments to pass to `git flow finish `, e.g. + # ["--keepremote"] + gitFlowFinishArgs: [] + # Periodic update checks update: # One of: 'prompt' (default) | 'background' | 'never' diff --git a/pkg/commands/git_commands/flow.go b/pkg/commands/git_commands/flow.go index fc00c11a171..cd158d3870b 100644 --- a/pkg/commands/git_commands/flow.go +++ b/pkg/commands/git_commands/flow.go @@ -49,7 +49,9 @@ func (self *FlowCommands) FinishCmdObj(branchName string) (*oscommands.CmdObj, e return nil, errors.New(self.Tr.NotAGitFlowBranch) } - cmdArgs := NewGitCmd("flow").Arg(branchType, "finish", suffix).ToArgv() + cmdArgs := NewGitCmd("flow").Arg(branchType, "finish", suffix). + Arg(self.UserConfig().Git.GitFlowFinishArgs...). + ToArgv() return self.cmd.New(cmdArgs), nil } diff --git a/pkg/commands/git_commands/flow_test.go b/pkg/commands/git_commands/flow_test.go index 911f50c7eb4..c36f1dda1da 100644 --- a/pkg/commands/git_commands/flow_test.go +++ b/pkg/commands/git_commands/flow_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/jesseduffield/lazygit/pkg/commands/git_config" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/stretchr/testify/assert" ) @@ -41,6 +42,7 @@ func TestFinishCmdObj(t *testing.T) { expected []string expectedError string gitConfigMockResponses map[string]string + userConfig *config.UserConfig }{ { testName: "not a git flow branch", @@ -65,12 +67,41 @@ func TestFinishCmdObj(t *testing.T) { "--local --get-regexp gitflow.prefix": "gitflow.prefix.feature feature/", }, }, + { + testName: "feature branch with extra finish args", + branchName: "feature/mybranch", + expected: []string{"git", "flow", "feature", "finish", "mybranch", "--keepremote"}, + expectedError: "", + gitConfigMockResponses: map[string]string{ + "--local --get-regexp gitflow.prefix": "gitflow.prefix.feature feature/", + }, + userConfig: &config.UserConfig{ + Git: config.GitConfig{ + GitFlowFinishArgs: []string{"--keepremote"}, + }, + }, + }, + { + testName: "feature branch with multiple extra finish args", + branchName: "feature/mybranch", + expected: []string{"git", "flow", "feature", "finish", "mybranch", "--keepremote", "--keeplocal"}, + expectedError: "", + gitConfigMockResponses: map[string]string{ + "--local --get-regexp gitflow.prefix": "gitflow.prefix.feature feature/", + }, + userConfig: &config.UserConfig{ + Git: config.GitConfig{ + GitFlowFinishArgs: []string{"--keepremote", "--keeplocal"}, + }, + }, + }, } for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { instance := buildFlowCommands(commonDeps{ - gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses), + gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses), + userConfig: s.userConfig, }) cmd, err := instance.FinishCmdObj(s.branchName) diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 192d13843d7..234daa00859 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -321,6 +321,8 @@ type GitConfig struct { RemoteBranchSortOrder string `yaml:"remoteBranchSortOrder" jsonschema:"enum=date,enum=alphabetical"` // When copying commit hashes to the clipboard, truncate them to this length. Set to 40 to disable truncation. TruncateCopiedCommitHashesTo int `yaml:"truncateCopiedCommitHashesTo"` + // Extra arguments to pass to `git flow finish `, e.g. ["--keepremote"] + GitFlowFinishArgs []string `yaml:"gitFlowFinishArgs"` } type PagerType string @@ -858,6 +860,7 @@ func GetDefaultConfig() *UserConfig { BranchPrefix: "", ParseEmoji: false, TruncateCopiedCommitHashesTo: 12, + GitFlowFinishArgs: []string{}, }, Refresher: RefresherConfig{ RefreshInterval: 10, diff --git a/schema-master/config.json b/schema-master/config.json index 54f9fa9ec4d..c590594dd1d 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -446,6 +446,13 @@ "type": "integer", "description": "When copying commit hashes to the clipboard, truncate them to this length. Set to 40 to disable truncation.", "default": 12 + }, + "gitFlowFinishArgs": { + "items": { + "type": "string" + }, + "type": "array", + "description": "Extra arguments to pass to `git flow \u003ctype\u003e finish \u003cname\u003e`, e.g. [\"--keepremote\"]" } }, "additionalProperties": false,