Skip to content

Commit 092363a

Browse files
Merge pull request #2164 from mark2185/fix-rebasing-over-merge-commits
2 parents 90feb4b + 23d39c7 commit 092363a

32 files changed

+114
-1
lines changed

pkg/commands/git_commands/rebase.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (self *RebaseCommands) SquashAllAboveFixupCommits(sha string) error {
255255
return self.runSkipEditorCommand(
256256
self.cmd.New(
257257
fmt.Sprintf(
258-
"git rebase --interactive --autostash --autosquash %s^",
258+
"git rebase --interactive --rebase-merges --autostash --autosquash %s^",
259259
sha,
260260
),
261261
),

pkg/integration/components/input.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ func (self *Input) Confirm() {
7676
self.pressKey(self.keys.Universal.Confirm)
7777
}
7878

79+
func (self *Input) ProceedWhenAsked(matcher *matcher) {
80+
self.assert.InConfirm()
81+
self.assert.MatchCurrentViewContent(matcher)
82+
self.Confirm()
83+
}
84+
7985
// i.e. same as Confirm
8086
func (self *Input) Enter() {
8187
self.pressKey(self.keys.Universal.Confirm)

pkg/integration/components/shell.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (s *Shell) Checkout(name string) *Shell {
6363
return s.RunCommand("git checkout " + name)
6464
}
6565

66+
func (s *Shell) Merge(name string) *Shell {
67+
return s.RunCommand("git merge --commit --no-ff " + name)
68+
}
69+
6670
func (s *Shell) GitAdd(path string) *Shell {
6771
return s.RunCommand(fmt.Sprintf("git add \"%s\"", path))
6872
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package interactive_rebase
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var (
9+
postMergeFileContent = "post merge file content"
10+
postMergeFilename = "post-merge-file"
11+
)
12+
13+
var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
14+
Description: "Amends a staged file to a merge commit.",
15+
ExtraCmdArgs: "",
16+
Skip: false,
17+
SetupConfig: func(config *config.AppConfig) {},
18+
SetupRepo: func(shell *Shell) {
19+
shell.
20+
NewBranch("development-branch").
21+
CreateFileAndAdd("initial-file", "initial file content").
22+
Commit("initial commit").
23+
NewBranch("feature-branch"). // it's also checked out automatically
24+
CreateFileAndAdd("new-feature-file", "new content").
25+
Commit("new feature commit").
26+
Checkout("development-branch").
27+
Merge("feature-branch").
28+
CreateFileAndAdd(postMergeFilename, postMergeFileContent)
29+
},
30+
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
31+
assert.CommitCount(3)
32+
33+
input.SwitchToCommitsWindow()
34+
assert.CurrentViewName("commits")
35+
36+
mergeCommitMessage := "Merge branch 'feature-branch' into development-branch"
37+
assert.MatchHeadCommitMessage(Contains(mergeCommitMessage))
38+
39+
input.PressKeys(keys.Commits.AmendToCommit)
40+
input.ProceedWhenAsked(Contains("Are you sure you want to amend this commit with your staged files?"))
41+
42+
// assuring we haven't added a brand new commit
43+
assert.CommitCount(3)
44+
assert.MatchHeadCommitMessage(Contains(mergeCommitMessage))
45+
46+
// assuring the post-merge file shows up in the merge commit.
47+
assert.MatchMainViewContent(Contains(postMergeFilename))
48+
assert.MatchMainViewContent(Contains("++" + postMergeFileContent))
49+
},
50+
})

pkg/integration/tests/tests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var tests = []*components.IntegrationTest{
2929
branch.Rebase,
3030
branch.RebaseAndDrop,
3131
interactive_rebase.One,
32+
interactive_rebase.AmendMerge,
3233
custom_commands.Basic,
3334
custom_commands.MultiplePrompts,
3435
custom_commands.MenuFromCommand,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fixup! Merge branch 'feature-branch' into development-branch

test/integration_new/interactive_rebase/amend_merge/expected/repo/.git_keep/FETCH_HEAD

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/development-branch
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7802c86c6ce62289e32aa13d0c85dc3f733195cb
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
precomposeunicode = true
8+
[user]
9+
10+
name = CI
11+
[commit]
12+
gpgSign = false

0 commit comments

Comments
 (0)