1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 16:22:24 +03:00

more compatible commands

This commit is contained in:
Jesse Duffield
2020-03-23 21:26:24 +11:00
parent c06c0b7133
commit 3d3e0be7bd
3 changed files with 31 additions and 19 deletions

View File

@@ -43,7 +43,7 @@ func (b *BranchListBuilder) obtainCurrentBranchName() string {
}
func (b *BranchListBuilder) obtainBranches() []*Branch {
cmdStr := `git branch --format="%(HEAD)|%(refname:short)|%(upstream:short)|%(upstream:track)"`
cmdStr := `git for-each-ref --sort=-committerdate --format="%(HEAD)|%(refname:short)|%(upstream:short)|%(upstream:track)" refs/heads`
output, err := b.GitCommand.OSCommand.RunCommandWithOutput(cmdStr)
if err != nil {
panic(err)
@@ -51,40 +51,48 @@ func (b *BranchListBuilder) obtainBranches() []*Branch {
trimmedOutput := strings.TrimSpace(output)
outputLines := strings.Split(trimmedOutput, "\n")
branches := make([]*Branch, len(outputLines))
for i, line := range outputLines {
branches := make([]*Branch, 0, len(outputLines))
for _, line := range outputLines {
if line == "" {
continue
}
split := strings.Split(line, SEPARATION_CHAR)
name := split[1]
branches[i] = &Branch{
branch := &Branch{
Name: name,
Pullables: "?",
Pushables: "?",
Head: split[0] == "*",
}
upstreamName := split[2]
if upstreamName == "" {
branches = append(branches, branch)
continue
}
branches[i].UpstreamName = upstreamName
branch.UpstreamName = upstreamName
track := split[3]
re := regexp.MustCompile(`ahead (\d+)`)
match := re.FindStringSubmatch(track)
if len(match) > 1 {
branches[i].Pushables = match[1]
branch.Pushables = match[1]
} else {
branches[i].Pushables = "0"
branch.Pushables = "0"
}
re = regexp.MustCompile(`behind (\d+)`)
match = re.FindStringSubmatch(track)
if len(match) > 1 {
branches[i].Pullables = match[1]
branch.Pullables = match[1]
} else {
branches[i].Pullables = "0"
branch.Pullables = "0"
}
branches = append(branches, branch)
}
return branches
@@ -116,12 +124,10 @@ outer:
branches = append(branchesWithRecency, branches...)
if len(branches) == 0 {
branches = append([]*Branch{{Name: currentBranchName}}, branches...)
}
foundHead := false
for i, branch := range branches {
if branch.Head {
foundHead = true
branch.Name = currentBranchName
branch.Recency = " *"
branches = append(branches[0:i], branches[i+1:]...)
@@ -129,6 +135,9 @@ outer:
break
}
}
if !foundHead {
branches = append([]*Branch{{Name: currentBranchName, Head: true, Recency: " *"}}, branches...)
}
return branches
}