-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add command to show divergence from upstream #2871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
911aa77
12f24aa
4de3fad
e8fac6c
572d1b5
ea532b4
df38e95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import ( | |
| "github.com/jesseduffield/lazygit/pkg/commands/models" | ||
| "github.com/jesseduffield/lazygit/pkg/gui/presentation" | ||
| "github.com/jesseduffield/lazygit/pkg/gui/types" | ||
| "github.com/jesseduffield/lazygit/pkg/utils" | ||
| "github.com/samber/lo" | ||
| ) | ||
|
|
||
| type SubCommitsContext struct { | ||
|
|
@@ -73,12 +73,41 @@ func NewSubCommitsContext( | |
| selectedCommitSha, | ||
| startIdx, | ||
| endIdx, | ||
| shouldShowGraph(c), | ||
| // Don't show the graph in the left/right view; we'd like to, but | ||
| // it's too complicated: | ||
| shouldShowGraph(c) && viewModel.GetRefToShowDivergenceFrom() == "", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really too bad; I'd like to have the graph in the left/right view, too. But I tried, and it's too hard to do; not only would we have to render the graph in two sections, but we'd actually have to calculate two separate sets of pipe sets; and then there's this global cache for these. I'll leave this as a future improvement. |
||
| git_commands.NewNullBisectInfo(), | ||
| false, | ||
| ) | ||
| } | ||
|
|
||
| getNonModelItems := func() []*NonModelItem { | ||
| result := []*NonModelItem{} | ||
| if viewModel.GetRefToShowDivergenceFrom() != "" { | ||
| _, upstreamIdx, found := lo.FindIndexOf( | ||
| c.Model().SubCommits, func(c *models.Commit) bool { return c.Divergence == models.DivergenceRight }) | ||
| if !found { | ||
| upstreamIdx = 0 | ||
| } | ||
| result = append(result, &NonModelItem{ | ||
| Index: upstreamIdx, | ||
| Content: fmt.Sprintf("--- %s ---", c.Tr.DivergenceSectionHeaderRemote), | ||
| }) | ||
|
|
||
| _, localIdx, found := lo.FindIndexOf( | ||
| c.Model().SubCommits, func(c *models.Commit) bool { return c.Divergence == models.DivergenceLeft }) | ||
| if !found { | ||
| localIdx = len(c.Model().SubCommits) | ||
| } | ||
| result = append(result, &NonModelItem{ | ||
| Index: localIdx, | ||
| Content: fmt.Sprintf("--- %s ---", c.Tr.DivergenceSectionHeaderLocal), | ||
| }) | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| ctx := &SubCommitsContext{ | ||
| c: c, | ||
| SubCommitsViewModel: viewModel, | ||
|
|
@@ -96,6 +125,7 @@ func NewSubCommitsContext( | |
| ListRenderer: ListRenderer{ | ||
| list: viewModel, | ||
| getDisplayStrings: getDisplayStrings, | ||
| getNonModelItems: getNonModelItems, | ||
| }, | ||
| c: c, | ||
| refreshViewportOnChange: true, | ||
|
|
@@ -112,7 +142,8 @@ func NewSubCommitsContext( | |
|
|
||
| type SubCommitsViewModel struct { | ||
| // name of the ref that the sub-commits are shown for | ||
| ref types.Ref | ||
| ref types.Ref | ||
| refToShowDivergenceFrom string | ||
| *ListViewModel[*models.Commit] | ||
|
|
||
| limitCommits bool | ||
|
|
@@ -127,6 +158,14 @@ func (self *SubCommitsViewModel) GetRef() types.Ref { | |
| return self.ref | ||
| } | ||
|
|
||
| func (self *SubCommitsViewModel) SetRefToShowDivergenceFrom(ref string) { | ||
| self.refToShowDivergenceFrom = ref | ||
| } | ||
|
|
||
| func (self *SubCommitsViewModel) GetRefToShowDivergenceFrom() string { | ||
| return self.refToShowDivergenceFrom | ||
| } | ||
|
|
||
| func (self *SubCommitsViewModel) SetShowBranchHeads(value bool) { | ||
| self.showBranchHeads = value | ||
| } | ||
|
|
@@ -160,10 +199,6 @@ func (self *SubCommitsContext) GetCommits() []*models.Commit { | |
| return self.getModel() | ||
| } | ||
|
|
||
| func (self *SubCommitsContext) Title() string { | ||
| return fmt.Sprintf(self.c.Tr.SubCommitsDynamicTitle, utils.TruncateWithEllipsis(self.ref.RefName(), 50)) | ||
| } | ||
|
|
||
| func (self *SubCommitsContext) SetLimitCommits(value bool) { | ||
| self.limitCommits = value | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a comment explaining that this is only set when comparing refs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one in 8d163ca.