Signed-off-by: oppiliappan me@oppi.li
+42
knotserver/git/cmd.go
+42
knotserver/git/cmd.go
···
1
+
package git
2
+
3
+
import (
4
+
"fmt"
5
+
"os/exec"
6
+
)
7
+
8
+
const (
9
+
fieldSeparator = "\x1f" // ASCII Unit Separator
10
+
recordSeparator = "\x1e" // ASCII Record Separator
11
+
)
12
+
13
+
func (g *GitRepo) runGitCmd(command string, extraArgs ...string) ([]byte, error) {
14
+
var args []string
15
+
args = append(args, command)
16
+
args = append(args, extraArgs...)
17
+
18
+
cmd := exec.Command("git", args...)
19
+
cmd.Dir = g.path
20
+
21
+
out, err := cmd.Output()
22
+
if err != nil {
23
+
if exitErr, ok := err.(*exec.ExitError); ok {
24
+
return nil, fmt.Errorf("%w, stderr: %s", err, string(exitErr.Stderr))
25
+
}
26
+
return nil, err
27
+
}
28
+
29
+
return out, nil
30
+
}
31
+
32
+
func (g *GitRepo) revList(extraArgs ...string) ([]byte, error) {
33
+
return g.runGitCmd("rev-list", extraArgs...)
34
+
}
35
+
36
+
func (g *GitRepo) forEachRef(extraArgs ...string) ([]byte, error) {
37
+
return g.runGitCmd("for-each-ref", extraArgs...)
38
+
}
39
+
40
+
func (g *GitRepo) revParse(extraArgs ...string) ([]byte, error) {
41
+
return g.runGitCmd("rev-parse", extraArgs...)
42
+
}
-21
knotserver/git/git.go
-21
knotserver/git/git.go
···
6
6
"fmt"
7
7
"io"
8
8
"io/fs"
9
-
"os/exec"
10
9
"path"
11
-
"sort"
12
10
"strconv"
13
11
"strings"
14
12
"time"
···
170
168
return count, nil
171
169
}
172
170
173
-
func (g *GitRepo) revList(extraArgs ...string) ([]byte, error) {
174
-
var args []string
175
-
args = append(args, "rev-list")
176
-
args = append(args, extraArgs...)
177
-
178
-
cmd := exec.Command("git", args...)
179
-
cmd.Dir = g.path
180
-
181
-
out, err := cmd.Output()
182
-
if err != nil {
183
-
if exitErr, ok := err.(*exec.ExitError); ok {
184
-
return nil, fmt.Errorf("%w, stderr: %s", err, string(exitErr.Stderr))
185
-
}
186
-
return nil, err
187
-
}
188
-
189
-
return out, nil
190
-
}
191
-
192
171
func (g *GitRepo) Commit(h plumbing.Hash) (*object.Commit, error) {
193
172
return g.r.CommitObject(h)
194
173
}