1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

add support for git bisect

This commit is contained in:
Jesse Duffield
2022-01-19 18:32:27 +11:00
parent ab84410b41
commit 4ab5e54139
117 changed files with 1013 additions and 104 deletions

View File

@ -4,6 +4,7 @@ import (
"strings"
"sync"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/authors"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/graph"
@ -21,6 +22,14 @@ type pipeSetCacheKey struct {
var pipeSetCache = make(map[pipeSetCacheKey][][]*graph.Pipe)
var mutex sync.Mutex
type BisectProgress int
const (
BeforeNewCommit BisectProgress = iota
InbetweenCommits
AfterOldCommit
)
func GetCommitListDisplayStrings(
commits []*models.Commit,
fullDescription bool,
@ -31,6 +40,7 @@ func GetCommitListDisplayStrings(
startIdx int,
length int,
showGraph bool,
bisectInfo *git_commands.BisectInfo,
) [][]string {
mutex.Lock()
defer mutex.Unlock()
@ -77,12 +87,94 @@ func GetCommitListDisplayStrings(
}
lines := make([][]string, 0, len(filteredCommits))
bisectProgress := BeforeNewCommit
var bisectStatus BisectStatus
for i, commit := range filteredCommits {
lines = append(lines, displayCommit(commit, cherryPickedCommitShaMap, diffName, parseEmoji, getGraphLine(i), fullDescription))
bisectStatus, bisectProgress = getBisectStatus(commit.Sha, bisectInfo, bisectProgress)
lines = append(lines, displayCommit(
commit,
cherryPickedCommitShaMap,
diffName,
parseEmoji,
getGraphLine(i),
fullDescription,
bisectStatus,
bisectInfo,
))
}
return lines
}
// similar to the git_commands.BisectStatus but more gui-focused
type BisectStatus int
const (
BisectStatusNone BisectStatus = iota
BisectStatusOld
BisectStatusNew
BisectStatusSkipped
// adding candidate here which isn't present in the commands package because
// we need to actually go through the commits to get this info
BisectStatusCandidate
// also adding this
BisectStatusCurrent
)
func getBisectStatus(commitSha string, bisectInfo *git_commands.BisectInfo, bisectProgress BisectProgress) (BisectStatus, BisectProgress) {
if !bisectInfo.Started() {
return BisectStatusNone, bisectProgress
}
if bisectInfo.GetCurrentSha() == commitSha {
return BisectStatusCurrent, bisectProgress
}
status, ok := bisectInfo.Status(commitSha)
if ok {
switch status {
case git_commands.BisectStatusNew:
return BisectStatusNew, InbetweenCommits
case git_commands.BisectStatusOld:
return BisectStatusOld, AfterOldCommit
case git_commands.BisectStatusSkipped:
return BisectStatusSkipped, bisectProgress
}
} else {
if bisectProgress == InbetweenCommits {
return BisectStatusCandidate, bisectProgress
} else {
return BisectStatusNone, bisectProgress
}
}
// should never land here
return BisectStatusNone, bisectProgress
}
func getBisectStatusText(bisectStatus BisectStatus, bisectInfo *git_commands.BisectInfo) string {
if bisectStatus == BisectStatusNone {
return ""
}
style := getBisectStatusColor(bisectStatus)
switch bisectStatus {
case BisectStatusNew:
return style.Sprintf("<-- " + bisectInfo.NewTerm())
case BisectStatusOld:
return style.Sprintf("<-- " + bisectInfo.OldTerm())
case BisectStatusCurrent:
// TODO: i18n
return style.Sprintf("<-- current")
case BisectStatusSkipped:
return style.Sprintf("<-- skipped")
case BisectStatusCandidate:
return style.Sprintf("?")
}
return ""
}
func displayCommit(
commit *models.Commit,
cherryPickedCommitShaMap map[string]bool,
@ -90,9 +182,11 @@ func displayCommit(
parseEmoji bool,
graphLine string,
fullDescription bool,
bisectStatus BisectStatus,
bisectInfo *git_commands.BisectInfo,
) []string {
shaColor := getShaColor(commit, diffName, cherryPickedCommitShaMap)
shaColor := getShaColor(commit, diffName, cherryPickedCommitShaMap, bisectStatus, bisectInfo)
bisectString := getBisectStatusText(bisectStatus, bisectInfo)
actionString := ""
if commit.Action != "" {
@ -122,6 +216,7 @@ func displayCommit(
cols := make([]string, 0, 5)
cols = append(cols, shaColor.Sprint(commit.ShortSha()))
cols = append(cols, bisectString)
if fullDescription {
cols = append(cols, style.FgBlue.Sprint(utils.UnixToDate(commit.UnixTimestamp)))
}
@ -133,10 +228,39 @@ func displayCommit(
)
return cols
}
func getShaColor(commit *models.Commit, diffName string, cherryPickedCommitShaMap map[string]bool) style.TextStyle {
func getBisectStatusColor(status BisectStatus) style.TextStyle {
switch status {
case BisectStatusNone:
return style.FgBlack
case BisectStatusNew:
return style.FgRed
case BisectStatusOld:
return style.FgGreen
case BisectStatusSkipped:
return style.FgYellow
case BisectStatusCurrent:
return style.FgMagenta
case BisectStatusCandidate:
return style.FgBlue
}
// shouldn't land here
return style.FgWhite
}
func getShaColor(
commit *models.Commit,
diffName string,
cherryPickedCommitShaMap map[string]bool,
bisectStatus BisectStatus,
bisectInfo *git_commands.BisectInfo,
) style.TextStyle {
if bisectInfo.Started() {
return getBisectStatusColor(bisectStatus)
}
diffed := commit.Sha == diffName
shaColor := theme.DefaultTextColor
switch commit.Status {