From ca7cfc32322f016a430ecbf87e3e638d1a02cfc1 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 26 Jan 2022 15:17:11 +1100 Subject: [PATCH] only show commits from start ref if bad commit is reachable from there --- pkg/commands/git_commands/bisect.go | 8 ++++++++ pkg/gui/commits_panel.go | 25 +++++++++++++++++-------- pkg/gui/presentation/commits.go | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pkg/commands/git_commands/bisect.go b/pkg/commands/git_commands/bisect.go index 2e362af2a..c72eaee52 100644 --- a/pkg/commands/git_commands/bisect.go +++ b/pkg/commands/git_commands/bisect.go @@ -162,3 +162,11 @@ func (self *BisectCommands) IsDone() (bool, []string, error) { return done, candidates, nil } + +func (self *BisectCommands) ReachableFromStart(ref string, startRef string) bool { + err := self.cmd.New( + fmt.Sprintf("git merge-base --is-ancestor %s %s", startRef, ref), + ).Run() + + return err == nil +} diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index b169423dc..6e7ffb928 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -116,19 +116,12 @@ func (gui *Gui) refreshCommitsWithLimit() error { gui.Mutexes.BranchCommitsMutex.Lock() defer gui.Mutexes.BranchCommitsMutex.Unlock() - refName := "HEAD" - bisectInfo := gui.Git.Bisect.GetInfo() - gui.State.BisectInfo = bisectInfo - if bisectInfo.Started() { - refName = bisectInfo.StartSha() - } - commits, err := gui.Git.Loaders.Commits.GetCommits( loaders.GetCommitsOptions{ Limit: gui.State.Panels.Commits.LimitCommits, FilterPath: gui.State.Modes.Filtering.GetPath(), IncludeRebaseCommits: true, - RefName: refName, + RefName: gui.refForLog(), All: gui.State.ShowWholeGitGraph, }, ) @@ -140,6 +133,22 @@ func (gui *Gui) refreshCommitsWithLimit() error { return gui.postRefreshUpdate(gui.State.Contexts.BranchCommits) } +func (gui *Gui) refForLog() string { + bisectInfo := gui.Git.Bisect.GetInfo() + gui.State.BisectInfo = bisectInfo + + if !bisectInfo.Started() { + return "HEAD" + } + + // need to see if our bisect's current commit is reachable from our 'start' ref. + if bisectInfo.Bisecting() && !gui.Git.Bisect.ReachableFromStart(bisectInfo.StartSha(), bisectInfo.GetCurrentSha()) { + return bisectInfo.GetNewSha() + } + + return bisectInfo.StartSha() +} + func (gui *Gui) refreshRebaseCommits() error { gui.Mutexes.BranchCommitsMutex.Lock() defer gui.Mutexes.BranchCommitsMutex.Unlock() diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 7f5b2e5cd..99ab96750 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -175,7 +175,7 @@ func getBisectStatus(commitSha string, bisectInfo *git_commands.BisectInfo, bise return BisectStatusSkipped, bisectProgress } } else { - if bisectProgress == InbetweenCommits { + if bisectProgress == InbetweenCommits && bisectInfo.Bisecting() { return BisectStatusCandidate, bisectProgress } else { return BisectStatusNone, bisectProgress