1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-10 04:07:18 +02:00
lazygit/pkg/integration/tests/interactive_rebase/amend_merge.go
Stefan Haller 843e12286f Improve prompts when amending commits
This fixes two minor problems with the prompts:

1. When pressing shift-A in the local commits view, it would first prompt
   whether to stage all files, and then it would prompt whether to amend the
   commit at all. This doesn't make sense, it needs to be the other way round.

2. When pressing shift-A on the head commit in an interactive rebase, we would
   ask whether they want to amend the last commit, like when pressing shift-A in
   the files view. While this is technically correct, the fact that we're
   amending the head commit in this case is just an implementation detail, and
   from the user's point of view it's better to use the same prompt as we do for
   any other commit.

To fix these, we remove the confirmation panel from AmendHelper.AmendHead() and
instead add it at the two call sites, so that we have more control over this.
2023-09-01 18:55:16 +02:00

63 lines
1.8 KiB
Go

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: []string{},
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(t *TestDriver, keys config.KeybindingConfig) {
mergeCommitMessage := "Merge branch 'feature-branch' into development-branch"
t.Views().Commits().
Lines(
Contains(mergeCommitMessage),
Contains("new feature commit"),
Contains("initial commit"),
)
t.Views().Commits().
Focus().
Press(keys.Commits.AmendToCommit)
t.ExpectPopup().Confirmation().
Title(Equals("Amend commit")).
Content(Contains("Are you sure you want to amend this commit with your staged files?")).
Confirm()
// assuring we haven't added a brand new commit
t.Views().Commits().
Lines(
Contains(mergeCommitMessage),
Contains("new feature commit"),
Contains("initial commit"),
)
// assuring the post-merge file shows up in the merge commit.
t.Views().Main().
Content(Contains(postMergeFilename)).
Content(Contains("++" + postMergeFileContent))
},
})