From aa81c456bbea40c83d345b98c0bbf0e50e0889b0 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 Feb 2024 15:27:25 +0100 Subject: [PATCH 1/2] Add a test that demonstrates a bug with multiple args in git.merging.args config We are currently passing the whole string as a single argument, which doesn't work of course. --- pkg/commands/git_commands/branch_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/commands/git_commands/branch_test.go b/pkg/commands/git_commands/branch_test.go index b94f700cc..7dcb7f6d6 100644 --- a/pkg/commands/git_commands/branch_test.go +++ b/pkg/commands/git_commands/branch_test.go @@ -127,6 +127,20 @@ func TestBranchMerge(t *testing.T) { branchName: "mybranch", expected: []string{"merge", "--no-edit", "--merging-args", "mybranch"}, }, + { + testName: "multiple merging args", + userConfig: &config.UserConfig{ + Git: config.GitConfig{ + Merging: config.MergingConfig{ + Args: "--arg1 --arg2", // it's up to the user what they put here + }, + }, + }, + opts: MergeOpts{}, + branchName: "mybranch", + expected: []string{"merge", "--no-edit", "--arg1 --arg2", "mybranch"}, + // This is wrong, we want separate arguments for "--arg1" and "--arg2" + }, { testName: "fast forward only", userConfig: &config.UserConfig{}, From 253a0096f91fc100261030e591a1035b7efefc62 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 Feb 2024 16:03:04 +0100 Subject: [PATCH 2/2] Break git.merging.args config into separate arguments on whitespace This makes it possible again to pass multiple arguments, for example "--ff-only --autostash". This won't work correctly if you want to use an argument that contains a space, but it's very unlikely that people will want to do that, so I think this is good enough. --- pkg/commands/git_commands/branch.go | 2 +- pkg/commands/git_commands/branch_test.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index b8d562dae..d05738ef3 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -210,7 +210,7 @@ type MergeOpts struct { func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error { cmdArgs := NewGitCmd("merge"). Arg("--no-edit"). - ArgIf(self.UserConfig.Git.Merging.Args != "", self.UserConfig.Git.Merging.Args). + Arg(strings.Fields(self.UserConfig.Git.Merging.Args)...). ArgIf(opts.FastForwardOnly, "--ff-only"). Arg(branchName). ToArgv() diff --git a/pkg/commands/git_commands/branch_test.go b/pkg/commands/git_commands/branch_test.go index 7dcb7f6d6..a6082586c 100644 --- a/pkg/commands/git_commands/branch_test.go +++ b/pkg/commands/git_commands/branch_test.go @@ -138,8 +138,7 @@ func TestBranchMerge(t *testing.T) { }, opts: MergeOpts{}, branchName: "mybranch", - expected: []string{"merge", "--no-edit", "--arg1 --arg2", "mybranch"}, - // This is wrong, we want separate arguments for "--arg1" and "--arg2" + expected: []string{"merge", "--no-edit", "--arg1", "--arg2", "mybranch"}, }, { testName: "fast forward only",