From bc219210018b5837ef75825f59b14c89f7b161c7 Mon Sep 17 00:00:00 2001 From: AzraelSec Date: Fri, 22 Sep 2023 12:19:38 +0200 Subject: [PATCH 1/2] chore: rename branch upstream view options method --- pkg/gui/controllers/branches_controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 0e14bd6cf..7269d7493 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -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 { From ea93df571d30c4196f8ae1bfa5bb99e4d42fcb95 Mon Sep 17 00:00:00 2001 From: AzraelSec Date: Fri, 22 Sep 2023 12:24:03 +0200 Subject: [PATCH 2/2] feat: add a menu to rebase current branch to a target branch upstream --- pkg/gui/controllers/branches_controller.go | 24 ++++++ pkg/i18n/english.go | 4 + .../tests/branch/rebase_to_upstream.go | 82 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 4 files changed, 111 insertions(+) create mode 100644 pkg/integration/tests/branch/rebase_to_upstream.go diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 7269d7493..daecc5e38 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -220,6 +220,15 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc 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) viewUpstreamOptions(selectedBranch *models.Branc 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) viewUpstreamOptions(selectedBranch *models.Branc unsetUpstreamItem, setUpstreamItem, upstreamResetItem, + upstreamRebaseItem, } return self.c.Menu(types.CreateMenuOptions{ diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 6fc4cec78..b442af6f6 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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}}'", diff --git a/pkg/integration/tests/branch/rebase_to_upstream.go b/pkg/integration/tests/branch/rebase_to_upstream.go new file mode 100644 index 000000000..1fc51350d --- /dev/null +++ b/pkg/integration/tests/branch/rebase_to_upstream.go @@ -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"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index f4ec26ec2..535bf55fe 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -47,6 +47,7 @@ var tests = []*components.IntegrationTest{ branch.RebaseCancelOnConflict, branch.RebaseDoesNotAutosquash, branch.RebaseFromMarkedBase, + branch.RebaseToUpstream, branch.Rename, branch.Reset, branch.ResetToUpstream,