forked from tangled.org/core
this repo has no description

knotserver: git: do not pass HEAD as a default arg to rev-list

when calling rev-list, HEAD was passed as a default argument:

git rev-list HEAD --count

but HEAD is only populated when we perform git.Open; it is zeroed out
when we perform git.PlainOpen:

git rev-list 00000... --count

this causes rev-list to exit with an error, when used in repos that are
git.PlainOpen'd.

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li f674a71c 46d66329

verified
Changed files
+11 -2
knotserver
git
+11 -2
knotserver/git/git.go
···
commits := []*object.Commit{}
output, err := g.revList(
+
g.h.String(),
fmt.Sprintf("--skip=%d", offset),
fmt.Sprintf("--max-count=%d", limit),
)
···
func (g *GitRepo) TotalCommits() (int, error) {
output, err := g.revList(
+
g.h.String(),
fmt.Sprintf("--count"),
)
if err != nil {
···
func (g *GitRepo) revList(extraArgs ...string) ([]byte, error) {
var args []string
args = append(args, "rev-list")
-
args = append(args, g.h.String())
args = append(args, extraArgs...)
cmd := exec.Command("git", args...)
cmd.Dir = g.path
-
return cmd.Output()
+
out, err := cmd.Output()
+
if err != nil {
+
if exitErr, ok := err.(*exec.ExitError); ok {
+
return nil, fmt.Errorf("%w, stderr: %s", err, string(exitErr.Stderr))
+
}
+
return nil, err
+
}
+
+
return out, nil
}
func (g *GitRepo) Commit(h plumbing.Hash) (*object.Commit, error) {