mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-23 12:18:51 +02:00
Add command "View divergence from base branch"
This commit is contained in:
parent
4ac77f4575
commit
343db7b3f1
@ -205,6 +205,40 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
|
||||
},
|
||||
}
|
||||
|
||||
var disabledReason *types.DisabledReason
|
||||
baseBranch, err := self.c.Git().Loaders.BranchLoader.GetBaseBranch(selectedBranch, self.c.Model().MainBranches)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if baseBranch == "" {
|
||||
baseBranch = self.c.Tr.CouldNotDetermineBaseBranch
|
||||
disabledReason = &types.DisabledReason{Text: self.c.Tr.CouldNotDetermineBaseBranch}
|
||||
}
|
||||
shortBaseBranchName := helpers.ShortBranchName(baseBranch)
|
||||
label := utils.ResolvePlaceholderString(
|
||||
self.c.Tr.ViewDivergenceFromBaseBranch,
|
||||
map[string]string{"baseBranch": shortBaseBranchName},
|
||||
)
|
||||
viewDivergenceFromBaseBranchItem := &types.MenuItem{
|
||||
LabelColumns: []string{label},
|
||||
Key: 'b',
|
||||
OnPress: func() error {
|
||||
branch := self.context().GetSelected()
|
||||
if branch == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
|
||||
Ref: branch,
|
||||
TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), shortBaseBranchName),
|
||||
RefToShowDivergenceFrom: baseBranch,
|
||||
Context: self.context(),
|
||||
ShowBranchHeads: false,
|
||||
})
|
||||
},
|
||||
DisabledReason: disabledReason,
|
||||
}
|
||||
|
||||
unsetUpstreamItem := &types.MenuItem{
|
||||
LabelColumns: []string{self.c.Tr.UnsetUpstream},
|
||||
OnPress: func() error {
|
||||
@ -312,6 +346,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
|
||||
|
||||
options := []*types.MenuItem{
|
||||
viewDivergenceItem,
|
||||
viewDivergenceFromBaseBranchItem,
|
||||
unsetUpstreamItem,
|
||||
setUpstreamItem,
|
||||
upstreamResetItem,
|
||||
|
@ -1,6 +1,8 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
@ -44,3 +46,7 @@ func (self *BranchesHelper) ConfirmDeleteRemote(remoteName string, branchName st
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func ShortBranchName(fullBranchName string) string {
|
||||
return strings.TrimPrefix(strings.TrimPrefix(fullBranchName, "refs/heads/"), "refs/remotes/")
|
||||
}
|
||||
|
@ -468,6 +468,8 @@ type TranslationSet struct {
|
||||
SetUpstream string
|
||||
UnsetUpstream string
|
||||
ViewDivergenceFromUpstream string
|
||||
ViewDivergenceFromBaseBranch string
|
||||
CouldNotDetermineBaseBranch string
|
||||
DivergenceSectionHeaderLocal string
|
||||
DivergenceSectionHeaderRemote string
|
||||
ViewUpstreamResetOptions string
|
||||
@ -1434,6 +1436,8 @@ func EnglishTranslationSet() TranslationSet {
|
||||
SetUpstream: "Set upstream of selected branch",
|
||||
UnsetUpstream: "Unset upstream of selected branch",
|
||||
ViewDivergenceFromUpstream: "View divergence from upstream",
|
||||
ViewDivergenceFromBaseBranch: "View divergence from base branch ({{.baseBranch}})",
|
||||
CouldNotDetermineBaseBranch: "Couldn't determine base branch",
|
||||
DivergenceSectionHeaderLocal: "Local",
|
||||
DivergenceSectionHeaderRemote: "Remote",
|
||||
ViewUpstreamResetOptions: "Reset checked-out branch onto {{.upstream}}",
|
||||
|
@ -0,0 +1,47 @@
|
||||
package branch
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var ShowDivergenceFromBaseBranch = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Show divergence from base branch",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
SetupConfig: func(config *config.AppConfig) {
|
||||
config.UserConfig.Gui.ShowDivergenceFromBaseBranch = "arrowAndNumber"
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.
|
||||
EmptyCommit("master 1").
|
||||
EmptyCommit("master 2").
|
||||
EmptyCommit("master 3").
|
||||
NewBranchFrom("feature", "master^").
|
||||
EmptyCommit("feature 1").
|
||||
EmptyCommit("feature 2")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Branches().
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("feature ↓1").IsSelected(),
|
||||
Contains("master"),
|
||||
).
|
||||
Press(keys.Branches.SetUpstream)
|
||||
|
||||
t.ExpectPopup().Menu().Title(Contains("Upstream")).
|
||||
Select(Contains("View divergence from base branch (master)")).Confirm()
|
||||
|
||||
t.Views().SubCommits().
|
||||
IsFocused().
|
||||
Title(Contains("Commits (feature <-> master)")).
|
||||
Lines(
|
||||
DoesNotContainAnyOf("↓", "↑").Contains("--- Remote ---"),
|
||||
Contains("↓").Contains("master 3"),
|
||||
DoesNotContainAnyOf("↓", "↑").Contains("--- Local ---"),
|
||||
Contains("↑").Contains("feature 2"),
|
||||
Contains("↑").Contains("feature 1"),
|
||||
)
|
||||
},
|
||||
})
|
@ -56,6 +56,7 @@ var tests = []*components.IntegrationTest{
|
||||
branch.Reset,
|
||||
branch.ResetToUpstream,
|
||||
branch.SetUpstream,
|
||||
branch.ShowDivergenceFromBaseBranch,
|
||||
branch.ShowDivergenceFromUpstream,
|
||||
branch.SortLocalBranches,
|
||||
branch.SortRemoteBranches,
|
||||
|
Loading…
x
Reference in New Issue
Block a user