Add number of commits to cherry-pick confirmation prompt (#4158)

- **PR Description**

The other day, I was cherry-picking a selection of commits and was
annoyed that the "Are you sure..." prompt did not include the actual
number of commits I was about to cherry-pick.

I failed to realize the number of copied commits is displayed at the
bottom right until going to update the integration tests. I personally
think it's still nice to display the number in the actual confirmation
prompt but feel free to close this PR if the change is unwanted.
This commit is contained in:
Stefan Haller 2025-01-09 08:46:37 +01:00 committed by GitHub
commit b2c46c33b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 17 additions and 10 deletions

View file

@ -1,10 +1,13 @@
package helpers
import (
"strconv"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
)
@ -67,8 +70,12 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
// Only to be called from the branch commits controller
func (self *CherryPickHelper) Paste() error {
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.CherryPick,
Prompt: self.c.Tr.SureCherryPick,
Title: self.c.Tr.CherryPick,
Prompt: utils.ResolvePlaceholderString(
self.c.Tr.SureCherryPick,
map[string]string{
"numCommits": strconv.Itoa(len(self.getData().CherryPickedCommits)),
}),
HandleConfirm: func() error {
isInRebase, err := self.c.Git().Status.IsInInteractiveRebase()
if err != nil {

View file

@ -1337,7 +1337,7 @@ func EnglishTranslationSet() *TranslationSet {
CherryPickCopyTooltip: "Mark commit as copied. Then, within the local commits view, you can press `{{.paste}}` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `{{.escape}}` to cancel the selection.",
CherryPickCopyRangeTooltip: "Mark commits as copied from the last copied commit to the selected commit.",
PasteCommits: "Paste (cherry-pick)",
SureCherryPick: "Are you sure you want to cherry-pick the copied commits onto this branch?",
SureCherryPick: "Are you sure you want to cherry-pick the {{.numCommits}} copied commit(s) onto this branch?",
CherryPick: "Cherry-pick",
CannotCherryPickNonCommit: "Cannot cherry-pick this kind of todo item",
CannotCherryPickMergeCommit: "Cherry-picking merge commits is not supported",

View file

@ -66,7 +66,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Content(Contains("Are you sure you want to cherry-pick the 2 copied commit(s) onto this branch?")).
Confirm()
}).
Tap(func() {
@ -95,7 +95,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Content(Contains("Are you sure you want to cherry-pick the 2 copied commit(s) onto this branch?")).
Confirm()
}).
Tap(func() {

View file

@ -49,7 +49,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Content(Contains("Are you sure you want to cherry-pick the 2 copied commit(s) onto this branch?")).
Confirm()
t.Common().AcknowledgeConflicts()

View file

@ -67,7 +67,7 @@ var CherryPickDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Content(Contains("Are you sure you want to cherry-pick the 1 copied commit(s) onto this branch?")).
Confirm()
}).
Tap(func() {

View file

@ -63,7 +63,7 @@ var CherryPickRange = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Content(Contains("Are you sure you want to cherry-pick the 2 copied commit(s) onto this branch?")).
Confirm()
}).
Tap(func() {

View file

@ -71,7 +71,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
t.Wait(1000)
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Content(Contains("Are you sure you want to cherry-pick the 2 copied commit(s) onto this branch?")).
Confirm()
}).
TopLines(

View file

@ -39,7 +39,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Content(Contains("Are you sure you want to cherry-pick the 1 copied commit(s) onto this branch?")).
Confirm()
}).
Lines(