diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 9a8f94618..11c187f36 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -255,7 +255,7 @@ func (self *RebaseCommands) SquashAllAboveFixupCommits(sha string) error { return self.runSkipEditorCommand( self.cmd.New( fmt.Sprintf( - "git rebase --interactive --autostash --autosquash %s^", + "git rebase --interactive --rebase-merges --autostash --autosquash %s^", sha, ), ), diff --git a/pkg/integration/components/input.go b/pkg/integration/components/input.go index 61c78e9eb..61b0f771f 100644 --- a/pkg/integration/components/input.go +++ b/pkg/integration/components/input.go @@ -76,6 +76,12 @@ func (self *Input) Confirm() { self.pressKey(self.keys.Universal.Confirm) } +func (self *Input) ProceedWhenAsked(matcher *matcher) { + self.assert.InConfirm() + self.assert.MatchCurrentViewContent(matcher) + self.Confirm() +} + // i.e. same as Confirm func (self *Input) Enter() { self.pressKey(self.keys.Universal.Confirm) diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 458528be7..5f7fef350 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -63,6 +63,10 @@ func (s *Shell) Checkout(name string) *Shell { return s.RunCommand("git checkout " + name) } +func (s *Shell) Merge(name string) *Shell { + return s.RunCommand("git merge --commit --no-ff " + name) +} + func (s *Shell) GitAdd(path string) *Shell { return s.RunCommand(fmt.Sprintf("git add \"%s\"", path)) } diff --git a/pkg/integration/tests/interactive_rebase/amend_merge.go b/pkg/integration/tests/interactive_rebase/amend_merge.go new file mode 100644 index 000000000..e01e79a78 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/amend_merge.go @@ -0,0 +1,50 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ( + postMergeFileContent = "post merge file content" + postMergeFilename = "post-merge-file" +) + +var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Amends a staged file to a merge commit.", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell. + NewBranch("development-branch"). + CreateFileAndAdd("initial-file", "initial file content"). + Commit("initial commit"). + NewBranch("feature-branch"). // it's also checked out automatically + CreateFileAndAdd("new-feature-file", "new content"). + Commit("new feature commit"). + Checkout("development-branch"). + Merge("feature-branch"). + CreateFileAndAdd(postMergeFilename, postMergeFileContent) + }, + Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { + assert.CommitCount(3) + + input.SwitchToCommitsWindow() + assert.CurrentViewName("commits") + + mergeCommitMessage := "Merge branch 'feature-branch' into development-branch" + assert.MatchHeadCommitMessage(Contains(mergeCommitMessage)) + + input.PressKeys(keys.Commits.AmendToCommit) + input.ProceedWhenAsked(Contains("Are you sure you want to amend this commit with your staged files?")) + + // assuring we haven't added a brand new commit + assert.CommitCount(3) + assert.MatchHeadCommitMessage(Contains(mergeCommitMessage)) + + // assuring the post-merge file shows up in the merge commit. + assert.MatchMainViewContent(Contains(postMergeFilename)) + assert.MatchMainViewContent(Contains("++" + postMergeFileContent)) + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index eb2fd83fa..d59177c7e 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -29,6 +29,7 @@ var tests = []*components.IntegrationTest{ branch.Rebase, branch.RebaseAndDrop, interactive_rebase.One, + interactive_rebase.AmendMerge, custom_commands.Basic, custom_commands.MultiplePrompts, custom_commands.MenuFromCommand, diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/COMMIT_EDITMSG new file mode 100644 index 000000000..de6160af5 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/COMMIT_EDITMSG @@ -0,0 +1 @@ +fixup! Merge branch 'feature-branch' into development-branch diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/FETCH_HEAD b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/FETCH_HEAD new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/HEAD b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/HEAD new file mode 100644 index 000000000..dbe0904e2 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/HEAD @@ -0,0 +1 @@ +ref: refs/heads/development-branch diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/ORIG_HEAD b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/ORIG_HEAD new file mode 100644 index 000000000..4829a07d0 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/ORIG_HEAD @@ -0,0 +1 @@ +7802c86c6ce62289e32aa13d0c85dc3f733195cb diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/config b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/config new file mode 100644 index 000000000..8a748ce32 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/config @@ -0,0 +1,12 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[user] + email = CI@example.com + name = CI +[commit] + gpgSign = false diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/description b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/index b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/index new file mode 100644 index 000000000..01d1d03a3 Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/index differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/info/exclude b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/info/exclude new file mode 100644 index 000000000..8e9f2071f --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/info/exclude @@ -0,0 +1,7 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ +.DS_Store diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/HEAD b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/HEAD new file mode 100644 index 000000000..bf29df758 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/HEAD @@ -0,0 +1,12 @@ +0000000000000000000000000000000000000000 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 CI 1663440492 -0700 commit (initial): initial commit +3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 CI 1663440492 -0700 checkout: moving from development-branch to feature-branch +3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 d1c7801838f293fe8f4b49dae6b4919d0359e6e6 CI 1663440492 -0700 commit: new feature commit +d1c7801838f293fe8f4b49dae6b4919d0359e6e6 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 CI 1663440492 -0700 checkout: moving from feature-branch to development-branch +3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 f68c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 CI 1663440492 -0700 merge feature-branch: Merge made by the 'recursive' strategy. +f68c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 7802c86c6ce62289e32aa13d0c85dc3f733195cb CI 1663440493 -0700 commit: fixup! Merge branch 'feature-branch' into development-branch +7802c86c6ce62289e32aa13d0c85dc3f733195cb 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 CI 1663440494 -0700 rebase (start): checkout f68c5b48c653ca6ab23abd7606fe8fa8cc8d5b15^ +3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 d1c7801838f293fe8f4b49dae6b4919d0359e6e6 CI 1663440494 -0700 rebase: fast-forward +d1c7801838f293fe8f4b49dae6b4919d0359e6e6 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 CI 1663440494 -0700 rebase (reset): 'onto' +3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 f68c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 CI 1663440494 -0700 rebase: fast-forward +f68c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 f517de66e2a158d4a1d85246611cae9ca23a938d CI 1663440494 -0700 rebase (fixup): Merge branch 'feature-branch' into development-branch +f517de66e2a158d4a1d85246611cae9ca23a938d f517de66e2a158d4a1d85246611cae9ca23a938d CI 1663440494 -0700 rebase (finish): returning to refs/heads/development-branch diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/refs/heads/development-branch b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/refs/heads/development-branch new file mode 100644 index 000000000..c7353e0e3 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/refs/heads/development-branch @@ -0,0 +1,4 @@ +0000000000000000000000000000000000000000 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 CI 1663440492 -0700 commit (initial): initial commit +3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 f68c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 CI 1663440492 -0700 merge feature-branch: Merge made by the 'recursive' strategy. +f68c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 7802c86c6ce62289e32aa13d0c85dc3f733195cb CI 1663440493 -0700 commit: fixup! Merge branch 'feature-branch' into development-branch +7802c86c6ce62289e32aa13d0c85dc3f733195cb f517de66e2a158d4a1d85246611cae9ca23a938d CI 1663440494 -0700 rebase (finish): refs/heads/development-branch onto 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/refs/heads/feature-branch b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/refs/heads/feature-branch new file mode 100644 index 000000000..2d2177acc --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/logs/refs/heads/feature-branch @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 CI 1663440492 -0700 branch: Created from HEAD +3ad14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 d1c7801838f293fe8f4b49dae6b4919d0359e6e6 CI 1663440492 -0700 commit: new feature commit diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/34/9e7420fb0fcc3ff740eae5b9dc103a1261558e b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/34/9e7420fb0fcc3ff740eae5b9dc103a1261558e new file mode 100644 index 000000000..5f350fcff Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/34/9e7420fb0fcc3ff740eae5b9dc103a1261558e differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/3a/d14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/3a/d14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 new file mode 100644 index 000000000..0ac8eaeca Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/3a/d14f8b4ed479f2fd9d8d4f7fe2a9913771b7f3 differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/3f/891fb57220f67735a13cb5a65d27c8ad388030 b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/3f/891fb57220f67735a13cb5a65d27c8ad388030 new file mode 100644 index 000000000..057b302dc Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/3f/891fb57220f67735a13cb5a65d27c8ad388030 differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/47/d2739ba2c34690248c8f91b84bb54e8936899a b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/47/d2739ba2c34690248c8f91b84bb54e8936899a new file mode 100644 index 000000000..c416a87e0 Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/47/d2739ba2c34690248c8f91b84bb54e8936899a differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/63/e06ef6d5baa80461d12e953ee7e75444180d8f b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/63/e06ef6d5baa80461d12e953ee7e75444180d8f new file mode 100644 index 000000000..21a235054 Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/63/e06ef6d5baa80461d12e953ee7e75444180d8f differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/78/02c86c6ce62289e32aa13d0c85dc3f733195cb b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/78/02c86c6ce62289e32aa13d0c85dc3f733195cb new file mode 100644 index 000000000..e99473942 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/78/02c86c6ce62289e32aa13d0c85dc3f733195cb @@ -0,0 +1,2 @@ +xMj0F)R$J ,zx1Drkh޷xTK; .~ ֍ݠ%k!"iFyhfjK |v`1O1 Q|6^o +O,띿o0!X-uZͻ!7\a[?`^z|k_BN \ No newline at end of file diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/7a/02580e6e6ba96ea8fb9c7ebad7d03d00ec0643 b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/7a/02580e6e6ba96ea8fb9c7ebad7d03d00ec0643 new file mode 100644 index 000000000..c30233de1 Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/7a/02580e6e6ba96ea8fb9c7ebad7d03d00ec0643 differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/7b/d422e3608d9bcfeef85748c90a5ec114fc2c17 b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/7b/d422e3608d9bcfeef85748c90a5ec114fc2c17 new file mode 100644 index 000000000..0b10fcf3f Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/7b/d422e3608d9bcfeef85748c90a5ec114fc2c17 differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/d1/c7801838f293fe8f4b49dae6b4919d0359e6e6 b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/d1/c7801838f293fe8f4b49dae6b4919d0359e6e6 new file mode 100644 index 000000000..abe014bbc Binary files /dev/null and b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/d1/c7801838f293fe8f4b49dae6b4919d0359e6e6 differ diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/f5/17de66e2a158d4a1d85246611cae9ca23a938d b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/f5/17de66e2a158d4a1d85246611cae9ca23a938d new file mode 100644 index 000000000..3d42ec640 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/f5/17de66e2a158d4a1d85246611cae9ca23a938d @@ -0,0 +1,2 @@ +xjADWtHf9@"9-fwFƟ˱^m et,Gx6JRg9ZI9`R2ȦYBfTQXCeb{?1 +pX:Ve7Ǹ:/Nm㵬퍴sYq4tT^i_wp~'(+i<:@eTyL?2#Y| \ No newline at end of file diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/f6/8c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/f6/8c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 new file mode 100644 index 000000000..72c90791a --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/objects/f6/8c5b48c653ca6ab23abd7606fe8fa8cc8d5b15 @@ -0,0 +1,2 @@ +xjC1DS߯ΕkiBrC>?9i<U!W4&Gµ)#5v{V.b}*ق Z6 ǜ}x-GS2R4Y\<&MSy|Mʼ+"Cptٹi_wħw +]`ZƣඌD?n{Lr[Y \ No newline at end of file diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/refs/heads/development-branch b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/refs/heads/development-branch new file mode 100644 index 000000000..8dec112d4 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/refs/heads/development-branch @@ -0,0 +1 @@ +f517de66e2a158d4a1d85246611cae9ca23a938d diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/refs/heads/feature-branch b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/refs/heads/feature-branch new file mode 100644 index 000000000..61eacdc31 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/refs/heads/feature-branch @@ -0,0 +1 @@ +d1c7801838f293fe8f4b49dae6b4919d0359e6e6 diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/initial-file b/test/integration_new/interactive_rebase/amend_merge/expected/repo/initial-file new file mode 100644 index 000000000..7a02580e6 --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/initial-file @@ -0,0 +1 @@ +initial file content \ No newline at end of file diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/new-feature-file b/test/integration_new/interactive_rebase/amend_merge/expected/repo/new-feature-file new file mode 100644 index 000000000..47d2739ba --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/new-feature-file @@ -0,0 +1 @@ +new content \ No newline at end of file diff --git a/test/integration_new/interactive_rebase/amend_merge/expected/repo/post-merge-file b/test/integration_new/interactive_rebase/amend_merge/expected/repo/post-merge-file new file mode 100644 index 000000000..63e06ef6d --- /dev/null +++ b/test/integration_new/interactive_rebase/amend_merge/expected/repo/post-merge-file @@ -0,0 +1 @@ +post merge file content \ No newline at end of file