Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear cherry-picked commits after pasting #3240

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions pkg/gui/controllers/helpers/cherry_pick_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,36 @@ func (self *CherryPickHelper) Paste() error {
if err := self.c.Git().Rebase.CherryPickCommitsDuringRebase(self.getData().CherryPickedCommits); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{
err = self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
})
if err != nil {
return err
}

return self.Reset()
}

return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.CherryPick)
err := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits)
return self.rebaseHelper.CheckMergeOrRebase(err)
err = self.rebaseHelper.CheckMergeOrRebase(err)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above:

err = self.rebaseHelper.CheckMergeOrRebase(err)
if err != nil {
	return err
}

// If we're in an interactive rebase at this point, it must
// be because there were conflicts. Don't clear the copied
// commits in this case, since we might want to abort and
// try pasting them again.
isInRebase, err = self.c.Git().Status.IsInInteractiveRebase()
if err != nil {
	return err
}

if !isInRebase {
	return self.Reset()
}

return nil

I know it's more verbose to do it this way but it's less nested and I find it easier to reason about go code when I can skim over if err != nil blocks compared to if err == nil

if err != nil {
return err
}

// If we're in an interactive rebase at this point, it must
// be because there were conflicts. Don't clear the copied
// commits in this case, since we might want to abort and
// try pasting them again.
isInRebase, err = self.c.Git().Status.IsInInteractiveRebase()
if err != nil {
return err
}
if !isInRebase {
return self.Reset()
}
return nil
})
},
})
Expand Down
17 changes: 8 additions & 9 deletions pkg/integration/tests/cherry_pick/cherry_pick.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,25 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("base"),
).
Press(keys.Commits.PasteCommits).
Tap(func() {
// cherry-picked commits will be deleted after confirmation
t.Views().Information().Content(Contains("2 commits copied"))
}).
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?")).
Confirm()
}).
Tap(func() {
t.Views().Information().Content(DoesNotContain("commits copied"))
}).
Lines(
Contains("four"),
Contains("three"),
Contains("two"),
Contains("one"),
Contains("base"),
).
Tap(func() {
// we need to manually exit out of cherry pick mode
t.Views().Information().Content(Contains("2 commits copied"))
}).
PressEscape().
Tap(func() {
t.Views().Information().Content(DoesNotContain("commits copied"))
})
)
},
})
4 changes: 4 additions & 0 deletions pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{

t.Common().AcknowledgeConflicts()

// cherry pick selection is not cleared when there are conflicts, so that the user
// is able to abort and try again without having to re-copy the commits
t.Views().Information().Content(Contains("2 commits copied"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a comment explaining why we expect to see this i.e.:
"cherry pick selection is not cleared when there are conflicts, so that the user is able to abort and try again without having to re-copy the commits"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Thank you for the feedback.

Copy link
Contributor Author

@molejnik88 molejnik88 Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jesseduffield I amended and force-pushed the suggested comment.


t.Views().Files().
IsFocused().
SelectedLine(Contains("file")).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ var CherryPickDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Confirm()
}).
Tap(func() {
t.Views().Information().Content(DoesNotContain("commit copied"))
}).
Lines(
Contains("pick CI two"),
Contains("pick CI three"),
Expand Down
13 changes: 4 additions & 9 deletions pkg/integration/tests/cherry_pick/cherry_pick_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,15 @@ var CherryPickRange = NewIntegrationTest(NewIntegrationTestArgs{
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Confirm()
}).
Tap(func() {
t.Views().Information().Content(DoesNotContain("commits copied"))
}).
Lines(
Contains("four"),
Contains("three"),
Contains("two"),
Contains("one"),
Contains("base"),
).
Tap(func() {
// we need to manually exit out of cherry pick mode
t.Views().Information().Content(Contains("2 commits copied"))
}).
PressEscape().
Tap(func() {
t.Views().Information().Content(DoesNotContain("commits copied"))
})
)
},
})
Loading