1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-23 12:18:51 +02:00

better way of knowing which commits are unpushed

This commit is contained in:
Jesse Duffield 2020-08-27 08:42:42 +10:00 committed by github-actions[bot]
parent 196c83d058
commit c6948582e6

View File

@ -12,7 +12,6 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -112,14 +111,21 @@ func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*Commit, error
} }
} }
unpushedCommits := c.getUnpushedCommits(opts.RefName) firstPushedCommit, err := c.getFirstPushedCommit(opts.RefName)
if err != nil {
return nil, err
}
cmd := c.getLogCmd(opts) cmd := c.getLogCmd(opts)
err := RunLineOutputCmd(cmd, func(line string) (bool, error) { passedFirstPushedCommit := false
err = RunLineOutputCmd(cmd, func(line string) (bool, error) {
if strings.Split(line, " ")[0] != "gpg:" { if strings.Split(line, " ")[0] != "gpg:" {
commit := c.extractCommitFromLine(line) commit := c.extractCommitFromLine(line)
_, unpushed := unpushedCommits[commit.ShortSha()] if commit.Sha == firstPushedCommit {
commit.Status = map[bool]string{true: "unpushed", false: "pushed"}[unpushed] passedFirstPushedCommit = true
}
commit.Status = map[bool]string{true: "unpushed", false: "pushed"}[!passedFirstPushedCommit]
commits = append(commits, commit) commits = append(commits, commit)
} }
return false, nil return false, nil
@ -292,19 +298,14 @@ func (c *CommitListBuilder) getMergeBase() (string, error) {
return output, nil return output, nil
} }
// getUnpushedCommits Returns the sha's of the commits that have not yet been pushed // getFirstPushedCommit returns the first commit SHA which has been pushed to the ref's upstream.
// to the remote branch of the current branch, a map is returned to ease look up // all commits above this are deemed unpushed and marked as such.
func (c *CommitListBuilder) getUnpushedCommits(refName string) map[string]bool { func (c *CommitListBuilder) getFirstPushedCommit(refName string) (string, error) {
pushables := map[string]bool{} output, err := c.OSCommand.RunCommandWithOutput("git merge-base %s %s@{u}", refName, refName)
o, err := c.OSCommand.RunCommandWithOutput("git rev-list %s@{u}..%s --abbrev-commit --abbrev=8", refName, refName)
if err != nil { if err != nil {
return pushables return "", err
} }
for _, p := range utils.SplitLines(o) { return strings.TrimSpace(output), nil
pushables[p] = true
}
return pushables
} }
// getLog gets the git log. // getLog gets the git log.