mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
more compatible commands
This commit is contained in:
@ -43,7 +43,7 @@ func (b *BranchListBuilder) obtainCurrentBranchName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BranchListBuilder) obtainBranches() []*Branch {
|
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)
|
output, err := b.GitCommand.OSCommand.RunCommandWithOutput(cmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -51,40 +51,48 @@ func (b *BranchListBuilder) obtainBranches() []*Branch {
|
|||||||
|
|
||||||
trimmedOutput := strings.TrimSpace(output)
|
trimmedOutput := strings.TrimSpace(output)
|
||||||
outputLines := strings.Split(trimmedOutput, "\n")
|
outputLines := strings.Split(trimmedOutput, "\n")
|
||||||
branches := make([]*Branch, len(outputLines))
|
branches := make([]*Branch, 0, len(outputLines))
|
||||||
for i, line := range outputLines {
|
for _, line := range outputLines {
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
split := strings.Split(line, SEPARATION_CHAR)
|
split := strings.Split(line, SEPARATION_CHAR)
|
||||||
|
|
||||||
name := split[1]
|
name := split[1]
|
||||||
branches[i] = &Branch{
|
branch := &Branch{
|
||||||
Name: name,
|
Name: name,
|
||||||
Pullables: "?",
|
Pullables: "?",
|
||||||
Pushables: "?",
|
Pushables: "?",
|
||||||
Head: split[0] == "*",
|
Head: split[0] == "*",
|
||||||
}
|
}
|
||||||
|
|
||||||
upstreamName := split[2]
|
upstreamName := split[2]
|
||||||
if upstreamName == "" {
|
if upstreamName == "" {
|
||||||
|
branches = append(branches, branch)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
branches[i].UpstreamName = upstreamName
|
branch.UpstreamName = upstreamName
|
||||||
|
|
||||||
track := split[3]
|
track := split[3]
|
||||||
re := regexp.MustCompile(`ahead (\d+)`)
|
re := regexp.MustCompile(`ahead (\d+)`)
|
||||||
match := re.FindStringSubmatch(track)
|
match := re.FindStringSubmatch(track)
|
||||||
if len(match) > 1 {
|
if len(match) > 1 {
|
||||||
branches[i].Pushables = match[1]
|
branch.Pushables = match[1]
|
||||||
} else {
|
} else {
|
||||||
branches[i].Pushables = "0"
|
branch.Pushables = "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
re = regexp.MustCompile(`behind (\d+)`)
|
re = regexp.MustCompile(`behind (\d+)`)
|
||||||
match = re.FindStringSubmatch(track)
|
match = re.FindStringSubmatch(track)
|
||||||
if len(match) > 1 {
|
if len(match) > 1 {
|
||||||
branches[i].Pullables = match[1]
|
branch.Pullables = match[1]
|
||||||
} else {
|
} else {
|
||||||
branches[i].Pullables = "0"
|
branch.Pullables = "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
branches = append(branches, branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
return branches
|
return branches
|
||||||
@ -116,12 +124,10 @@ outer:
|
|||||||
|
|
||||||
branches = append(branchesWithRecency, branches...)
|
branches = append(branchesWithRecency, branches...)
|
||||||
|
|
||||||
if len(branches) == 0 {
|
foundHead := false
|
||||||
branches = append([]*Branch{{Name: currentBranchName}}, branches...)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, branch := range branches {
|
for i, branch := range branches {
|
||||||
if branch.Head {
|
if branch.Head {
|
||||||
|
foundHead = true
|
||||||
branch.Name = currentBranchName
|
branch.Name = currentBranchName
|
||||||
branch.Recency = " *"
|
branch.Recency = " *"
|
||||||
branches = append(branches[0:i], branches[i+1:]...)
|
branches = append(branches[0:i], branches[i+1:]...)
|
||||||
@ -129,6 +135,9 @@ outer:
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !foundHead {
|
||||||
|
branches = append([]*Branch{{Name: currentBranchName, Head: true, Recency: " *"}}, branches...)
|
||||||
|
}
|
||||||
|
|
||||||
return branches
|
return branches
|
||||||
}
|
}
|
||||||
|
@ -866,7 +866,7 @@ func (c *GitCommand) CherryPickCommits(commits []*Commit) error {
|
|||||||
|
|
||||||
// GetCommitFiles get the specified commit files
|
// GetCommitFiles get the specified commit files
|
||||||
func (c *GitCommand) GetCommitFiles(commitSha string, patchManager *PatchManager) ([]*CommitFile, error) {
|
func (c *GitCommand) GetCommitFiles(commitSha string, patchManager *PatchManager) ([]*CommitFile, error) {
|
||||||
files, err := c.OSCommand.RunCommandWithOutput("git show --pretty= --name-only --no-renames %s", commitSha)
|
files, err := c.OSCommand.RunCommandWithOutput("git diff-tree --no-commit-id --name-only -r --no-renames %s", commitSha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1108,23 +1108,26 @@ func (c *GitCommand) FetchRemote(remoteName string) error {
|
|||||||
func (c *GitCommand) GetReflogCommits() ([]*Commit, error) {
|
func (c *GitCommand) GetReflogCommits() ([]*Commit, error) {
|
||||||
output, err := c.OSCommand.RunCommandWithOutput("git reflog --abbrev=20")
|
output, err := c.OSCommand.RunCommandWithOutput("git reflog --abbrev=20")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
// assume error means we have no reflog
|
||||||
|
return []*Commit{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(strings.TrimSpace(output), "\n")
|
lines := strings.Split(strings.TrimSpace(output), "\n")
|
||||||
commits := make([]*Commit, len(lines))
|
commits := make([]*Commit, 0)
|
||||||
re := regexp.MustCompile(`(\w+).*HEAD@\{\d+\}: (.*)`)
|
re := regexp.MustCompile(`(\w+).*HEAD@\{\d+\}: (.*)`)
|
||||||
for i, line := range lines {
|
for _, line := range lines {
|
||||||
match := re.FindStringSubmatch(line)
|
match := re.FindStringSubmatch(line)
|
||||||
if len(match) <= 1 {
|
if len(match) <= 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
commits[i] = &Commit{
|
commit := &Commit{
|
||||||
Sha: match[1],
|
Sha: match[1],
|
||||||
Name: match[2],
|
Name: match[2],
|
||||||
Status: "reflog",
|
Status: "reflog",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commits = append(commits, commit)
|
||||||
}
|
}
|
||||||
|
|
||||||
return commits, nil
|
return commits, nil
|
||||||
|
@ -1907,7 +1907,7 @@ func TestGitCommandGetCommitFiles(t *testing.T) {
|
|||||||
"123456",
|
"123456",
|
||||||
test.CreateMockCommand(t, []*test.CommandSwapper{
|
test.CreateMockCommand(t, []*test.CommandSwapper{
|
||||||
{
|
{
|
||||||
Expect: "git show --pretty= --name-only --no-renames 123456",
|
Expect: "git diff-tree --no-commit-id --name-only -r --no-renames 123456",
|
||||||
Replace: "echo 'hello\nworld'",
|
Replace: "echo 'hello\nworld'",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
Reference in New Issue
Block a user