mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Add command "Rebase onto base branch" to rebase menu
This commit is contained in:
parent
b3252ee7c8
commit
eded3ccf54
2 changed files with 46 additions and 4 deletions
|
@ -234,11 +234,22 @@ func (self *MergeAndRebaseHelper) PromptToContinueRebase() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
||||||
checkedOutBranch := self.refsHelper.GetCheckedOutRef().Name
|
checkedOutBranch := self.refsHelper.GetCheckedOutRef()
|
||||||
var disabledReason *types.DisabledReason
|
checkedOutBranchName := self.refsHelper.GetCheckedOutRef().Name
|
||||||
if checkedOutBranch == ref {
|
var disabledReason, baseBranchDisabledReason *types.DisabledReason
|
||||||
|
if checkedOutBranchName == ref {
|
||||||
disabledReason = &types.DisabledReason{Text: self.c.Tr.CantRebaseOntoSelf}
|
disabledReason = &types.DisabledReason{Text: self.c.Tr.CantRebaseOntoSelf}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseBranch, err := self.c.Git().Loaders.BranchLoader.GetBaseBranch(checkedOutBranch, self.refsHelper.c.Model().ExistingMainBranches)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if baseBranch == "" {
|
||||||
|
baseBranch = self.c.Tr.CouldNotDetermineBaseBranch
|
||||||
|
baseBranchDisabledReason = &types.DisabledReason{Text: self.c.Tr.CouldNotDetermineBaseBranch}
|
||||||
|
}
|
||||||
|
|
||||||
menuItems := []*types.MenuItem{
|
menuItems := []*types.MenuItem{
|
||||||
{
|
{
|
||||||
Label: utils.ResolvePlaceholderString(self.c.Tr.SimpleRebase,
|
Label: utils.ResolvePlaceholderString(self.c.Tr.SimpleRebase,
|
||||||
|
@ -289,6 +300,31 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
||||||
return self.c.PushContext(self.c.Contexts().LocalCommits)
|
return self.c.PushContext(self.c.Contexts().LocalCommits)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Label: utils.ResolvePlaceholderString(self.c.Tr.RebaseOntoBaseBranch,
|
||||||
|
map[string]string{"baseBranch": strings.TrimPrefix(baseBranch, "refs/remotes/")},
|
||||||
|
),
|
||||||
|
Key: 'b',
|
||||||
|
DisabledReason: baseBranchDisabledReason,
|
||||||
|
Tooltip: self.c.Tr.RebaseOntoBaseBranchTooltip,
|
||||||
|
OnPress: func() error {
|
||||||
|
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
|
||||||
|
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(task gocui.Task) error {
|
||||||
|
baseCommit := self.c.Modes().MarkedBaseCommit.GetHash()
|
||||||
|
var err error
|
||||||
|
if baseCommit != "" {
|
||||||
|
err = self.c.Git().Rebase.RebaseBranchFromBaseCommit(baseBranch, baseCommit)
|
||||||
|
} else {
|
||||||
|
err = self.c.Git().Rebase.RebaseBranch(baseBranch)
|
||||||
|
}
|
||||||
|
err = self.CheckMergeOrRebase(err)
|
||||||
|
if err == nil {
|
||||||
|
return self.ResetMarkedBaseCommit()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
title := utils.ResolvePlaceholderString(
|
title := utils.ResolvePlaceholderString(
|
||||||
|
@ -296,7 +332,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
||||||
self.c.Tr.RebasingFromBaseCommitTitle,
|
self.c.Tr.RebasingFromBaseCommitTitle,
|
||||||
self.c.Tr.RebasingTitle),
|
self.c.Tr.RebasingTitle),
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"checkedOutBranch": checkedOutBranch,
|
"checkedOutBranch": checkedOutBranchName,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -289,7 +289,9 @@ type TranslationSet struct {
|
||||||
RebasingFromBaseCommitTitle string
|
RebasingFromBaseCommitTitle string
|
||||||
SimpleRebase string
|
SimpleRebase string
|
||||||
InteractiveRebase string
|
InteractiveRebase string
|
||||||
|
RebaseOntoBaseBranch string
|
||||||
InteractiveRebaseTooltip string
|
InteractiveRebaseTooltip string
|
||||||
|
RebaseOntoBaseBranchTooltip string
|
||||||
MustSelectTodoCommits string
|
MustSelectTodoCommits string
|
||||||
ConfirmMerge string
|
ConfirmMerge string
|
||||||
FwdNoUpstream string
|
FwdNoUpstream string
|
||||||
|
@ -471,6 +473,7 @@ type TranslationSet struct {
|
||||||
ViewDivergenceFromBaseBranch string
|
ViewDivergenceFromBaseBranch string
|
||||||
NoMainBranches string
|
NoMainBranches string
|
||||||
BaseBranch string
|
BaseBranch string
|
||||||
|
CouldNotDetermineBaseBranch string
|
||||||
DivergenceSectionHeaderLocal string
|
DivergenceSectionHeaderLocal string
|
||||||
DivergenceSectionHeaderRemote string
|
DivergenceSectionHeaderRemote string
|
||||||
ViewUpstreamResetOptions string
|
ViewUpstreamResetOptions string
|
||||||
|
@ -1258,7 +1261,9 @@ func EnglishTranslationSet() TranslationSet {
|
||||||
RebasingFromBaseCommitTitle: "Rebase '{{.checkedOutBranch}}' from marked base",
|
RebasingFromBaseCommitTitle: "Rebase '{{.checkedOutBranch}}' from marked base",
|
||||||
SimpleRebase: "Simple rebase onto '{{.ref}}'",
|
SimpleRebase: "Simple rebase onto '{{.ref}}'",
|
||||||
InteractiveRebase: "Interactive rebase onto '{{.ref}}'",
|
InteractiveRebase: "Interactive rebase onto '{{.ref}}'",
|
||||||
|
RebaseOntoBaseBranch: "Rebase onto base branch ({{.baseBranch}})",
|
||||||
InteractiveRebaseTooltip: "Begin an interactive rebase with a break at the start, so you can update the TODO commits before continuing.",
|
InteractiveRebaseTooltip: "Begin an interactive rebase with a break at the start, so you can update the TODO commits before continuing.",
|
||||||
|
RebaseOntoBaseBranchTooltip: "Rebase the checked out branch onto its base branch (i.e. the closest main branch).",
|
||||||
MustSelectTodoCommits: "When rebasing, this action only works on a selection of TODO commits.",
|
MustSelectTodoCommits: "When rebasing, this action only works on a selection of TODO commits.",
|
||||||
ConfirmMerge: "Are you sure you want to merge '{{.selectedBranch}}' into '{{.checkedOutBranch}}'?",
|
ConfirmMerge: "Are you sure you want to merge '{{.selectedBranch}}' into '{{.checkedOutBranch}}'?",
|
||||||
FwdNoUpstream: "Cannot fast-forward a branch with no upstream",
|
FwdNoUpstream: "Cannot fast-forward a branch with no upstream",
|
||||||
|
@ -1440,6 +1445,7 @@ func EnglishTranslationSet() TranslationSet {
|
||||||
ViewDivergenceFromBaseBranch: "View divergence from base branch ({{.baseBranch}})",
|
ViewDivergenceFromBaseBranch: "View divergence from base branch ({{.baseBranch}})",
|
||||||
NoMainBranches: "There are no main branches",
|
NoMainBranches: "There are no main branches",
|
||||||
BaseBranch: "base branch",
|
BaseBranch: "base branch",
|
||||||
|
CouldNotDetermineBaseBranch: "couldn't determine base branch",
|
||||||
DivergenceSectionHeaderLocal: "Local",
|
DivergenceSectionHeaderLocal: "Local",
|
||||||
DivergenceSectionHeaderRemote: "Remote",
|
DivergenceSectionHeaderRemote: "Remote",
|
||||||
ViewUpstreamResetOptions: "Reset checked-out branch onto {{.upstream}}",
|
ViewUpstreamResetOptions: "Reset checked-out branch onto {{.upstream}}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue