1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00

Add menu to rebase onto selected branch remote upstream (#3020)

This commit is contained in:
Jesse Duffield 2023-09-25 10:24:06 +10:00 committed by GitHub
commit ad70341139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 2 deletions

View File

@ -109,7 +109,7 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty
},
{
Key: opts.GetKey(opts.Config.Branches.SetUpstream),
Handler: self.checkSelected(self.setUpstream),
Handler: self.checkSelected(self.viewUpstreamOptions),
Description: self.c.Tr.ViewBranchUpstreamOptions,
Tooltip: self.c.Tr.ViewBranchUpstreamOptionsTooltip,
OpensMenu: true,
@ -141,7 +141,7 @@ func (self *BranchesController) GetOnRenderToMain() func() error {
}
}
func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error {
func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branch) error {
viewDivergenceItem := &types.MenuItem{
LabelColumns: []string{self.c.Tr.ViewDivergenceFromUpstream},
OnPress: func() error {
@ -220,6 +220,15 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
map[string]string{"upstream": upstream},
)
upstreamRebaseOptions := utils.ResolvePlaceholderString(
self.c.Tr.ViewUpstreamRebaseOptions,
map[string]string{"upstream": upstream},
)
upstreamRebaseTooltip := utils.ResolvePlaceholderString(
self.c.Tr.ViewUpstreamRebaseOptionsTooltip,
map[string]string{"upstream": upstream},
)
upstreamResetItem := &types.MenuItem{
LabelColumns: []string{upstreamResetOptions},
OpensMenu: true,
@ -234,10 +243,24 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
Key: 'g',
}
upstreamRebaseItem := &types.MenuItem{
LabelColumns: []string{upstreamRebaseOptions},
OpensMenu: true,
OnPress: func() error {
if err := self.c.Helpers().MergeAndRebase.RebaseOntoRef(selectedBranch.ShortUpstreamRefName()); err != nil {
return self.c.Error(err)
}
return nil
},
Tooltip: upstreamRebaseTooltip,
Key: 'r',
}
if !selectedBranch.RemoteBranchStoredLocally() {
viewDivergenceItem.DisabledReason = self.c.Tr.UpstreamNotSetError
unsetUpstreamItem.DisabledReason = self.c.Tr.UpstreamNotSetError
upstreamResetItem.DisabledReason = self.c.Tr.UpstreamNotSetError
upstreamRebaseItem.DisabledReason = self.c.Tr.UpstreamNotSetError
}
options := []*types.MenuItem{
@ -245,6 +268,7 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
unsetUpstreamItem,
setUpstreamItem,
upstreamResetItem,
upstreamRebaseItem,
}
return self.c.Menu(types.CreateMenuOptions{

View File

@ -356,6 +356,8 @@ type TranslationSet struct {
DivergenceSectionHeaderRemote string
ViewUpstreamResetOptions string
ViewUpstreamResetOptionsTooltip string
ViewUpstreamRebaseOptions string
ViewUpstreamRebaseOptionsTooltip string
UpstreamGenericName string
SetUpstreamTitle string
SetUpstreamMessage string
@ -1152,6 +1154,8 @@ func EnglishTranslationSet() TranslationSet {
DivergenceSectionHeaderRemote: "Remote",
ViewUpstreamResetOptions: "Reset checked-out branch onto {{.upstream}}",
ViewUpstreamResetOptionsTooltip: "View options for resetting the checked-out branch onto {{upstream}}. Note: this will not reset the selected branch onto the upstream, it will reset the checked-out branch onto the upstream",
ViewUpstreamRebaseOptions: "Rebase checked-out branch onto {{.upstream}}",
ViewUpstreamRebaseOptionsTooltip: "View options for rebasing the checked-out branch onto {{upstream}}. Note: this will not rebase the selected branch onto the upstream, it will rebased the checked-out branch onto the upstream",
UpstreamGenericName: "upstream of selected branch",
SetUpstreamTitle: "Set upstream branch",
SetUpstreamMessage: "Are you sure you want to set the upstream branch of '{{.checkedOut}}' to '{{.selected}}'",

View File

@ -0,0 +1,82 @@
package branch
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Rebase the current branch to the selected branch upstream",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CloneIntoRemote("origin").
EmptyCommit("ensure-master").
EmptyCommit("to-be-added"). // <- this will only exist remotely
PushBranch("origin", "master").
HardReset("HEAD~1").
NewBranchFrom("base-branch", "master").
EmptyCommit("base-branch-commit").
NewBranch("target").
EmptyCommit("target-commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().Lines(
Contains("target-commit"),
Contains("base-branch-commit"),
Contains("ensure-master"),
)
t.Views().Branches().
Focus().
Lines(
Contains("target").IsSelected(),
Contains("base-branch"),
Contains("master"),
).
SelectNextItem().
Lines(
Contains("target"),
Contains("base-branch").IsSelected(),
Contains("master"),
).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
Select(Contains("Rebase checked-out branch onto upstream of selected branch")).
Tooltip(Contains("Disabled: The selected branch has no upstream (or the upstream is not stored locally)")).
Confirm()
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Equals("The selected branch has no upstream (or the upstream is not stored locally)")).
Confirm()
}).
SelectNextItem().
Lines(
Contains("target"),
Contains("base-branch"),
Contains("master").IsSelected(),
).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
Select(Contains("Rebase checked-out branch onto origin/master...")).
Confirm()
t.ExpectPopup().Menu().
Title(Equals("Rebase 'target' onto 'origin/master'")).
Select(Contains("Simple rebase")).
Confirm()
})
t.Views().Commits().Lines(
Contains("target-commit"),
Contains("base-branch-commit"),
Contains("to-be-added"),
Contains("ensure-master"),
)
},
})

View File

@ -47,6 +47,7 @@ var tests = []*components.IntegrationTest{
branch.RebaseCancelOnConflict,
branch.RebaseDoesNotAutosquash,
branch.RebaseFromMarkedBase,
branch.RebaseToUpstream,
branch.Rename,
branch.Reset,
branch.ResetToUpstream,