mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-03 13:21:56 +02:00
Add menu to rebase onto selected branch remote upstream (#3020)
This commit is contained in:
commit
ad70341139
@ -109,7 +109,7 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: opts.GetKey(opts.Config.Branches.SetUpstream),
|
Key: opts.GetKey(opts.Config.Branches.SetUpstream),
|
||||||
Handler: self.checkSelected(self.setUpstream),
|
Handler: self.checkSelected(self.viewUpstreamOptions),
|
||||||
Description: self.c.Tr.ViewBranchUpstreamOptions,
|
Description: self.c.Tr.ViewBranchUpstreamOptions,
|
||||||
Tooltip: self.c.Tr.ViewBranchUpstreamOptionsTooltip,
|
Tooltip: self.c.Tr.ViewBranchUpstreamOptionsTooltip,
|
||||||
OpensMenu: true,
|
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{
|
viewDivergenceItem := &types.MenuItem{
|
||||||
LabelColumns: []string{self.c.Tr.ViewDivergenceFromUpstream},
|
LabelColumns: []string{self.c.Tr.ViewDivergenceFromUpstream},
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
@ -220,6 +220,15 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
|
|||||||
map[string]string{"upstream": upstream},
|
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{
|
upstreamResetItem := &types.MenuItem{
|
||||||
LabelColumns: []string{upstreamResetOptions},
|
LabelColumns: []string{upstreamResetOptions},
|
||||||
OpensMenu: true,
|
OpensMenu: true,
|
||||||
@ -234,10 +243,24 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
|
|||||||
Key: 'g',
|
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() {
|
if !selectedBranch.RemoteBranchStoredLocally() {
|
||||||
viewDivergenceItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
viewDivergenceItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
||||||
unsetUpstreamItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
unsetUpstreamItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
||||||
upstreamResetItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
upstreamResetItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
||||||
|
upstreamRebaseItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
||||||
}
|
}
|
||||||
|
|
||||||
options := []*types.MenuItem{
|
options := []*types.MenuItem{
|
||||||
@ -245,6 +268,7 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
|
|||||||
unsetUpstreamItem,
|
unsetUpstreamItem,
|
||||||
setUpstreamItem,
|
setUpstreamItem,
|
||||||
upstreamResetItem,
|
upstreamResetItem,
|
||||||
|
upstreamRebaseItem,
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.Menu(types.CreateMenuOptions{
|
return self.c.Menu(types.CreateMenuOptions{
|
||||||
|
@ -356,6 +356,8 @@ type TranslationSet struct {
|
|||||||
DivergenceSectionHeaderRemote string
|
DivergenceSectionHeaderRemote string
|
||||||
ViewUpstreamResetOptions string
|
ViewUpstreamResetOptions string
|
||||||
ViewUpstreamResetOptionsTooltip string
|
ViewUpstreamResetOptionsTooltip string
|
||||||
|
ViewUpstreamRebaseOptions string
|
||||||
|
ViewUpstreamRebaseOptionsTooltip string
|
||||||
UpstreamGenericName string
|
UpstreamGenericName string
|
||||||
SetUpstreamTitle string
|
SetUpstreamTitle string
|
||||||
SetUpstreamMessage string
|
SetUpstreamMessage string
|
||||||
@ -1152,6 +1154,8 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
DivergenceSectionHeaderRemote: "Remote",
|
DivergenceSectionHeaderRemote: "Remote",
|
||||||
ViewUpstreamResetOptions: "Reset checked-out branch onto {{.upstream}}",
|
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",
|
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",
|
UpstreamGenericName: "upstream of selected branch",
|
||||||
SetUpstreamTitle: "Set upstream branch",
|
SetUpstreamTitle: "Set upstream branch",
|
||||||
SetUpstreamMessage: "Are you sure you want to set the upstream branch of '{{.checkedOut}}' to '{{.selected}}'",
|
SetUpstreamMessage: "Are you sure you want to set the upstream branch of '{{.checkedOut}}' to '{{.selected}}'",
|
||||||
|
82
pkg/integration/tests/branch/rebase_to_upstream.go
Normal file
82
pkg/integration/tests/branch/rebase_to_upstream.go
Normal 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"),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
@ -47,6 +47,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
branch.RebaseCancelOnConflict,
|
branch.RebaseCancelOnConflict,
|
||||||
branch.RebaseDoesNotAutosquash,
|
branch.RebaseDoesNotAutosquash,
|
||||||
branch.RebaseFromMarkedBase,
|
branch.RebaseFromMarkedBase,
|
||||||
|
branch.RebaseToUpstream,
|
||||||
branch.Rename,
|
branch.Rename,
|
||||||
branch.Reset,
|
branch.Reset,
|
||||||
branch.ResetToUpstream,
|
branch.ResetToUpstream,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user