Skip to content

Commit 8f75e76

Browse files
chore: revert go-git changes (#112)
* chore: revert go-git changes Signed-off-by: Siddhant N Trivedi <siddhant@deepsource.io> * chore: tidy go modules Signed-off-by: Siddhant N Trivedi <siddhant@deepsource.io> * Update command/report/git.go
1 parent 4e81080 commit 8f75e76

3 files changed

Lines changed: 16 additions & 90 deletions

File tree

command/report/git.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package report
22

33
import (
4+
"bytes"
45
"fmt"
56
"os"
7+
"os/exec"
8+
"strings"
69

710
"github.com/getsentry/sentry-go"
8-
"github.com/go-git/go-git/v5"
9-
"github.com/go-git/go-git/v5/plumbing"
1011
)
1112

1213
// gitGetHead accepts a git directory and returns head commit OID / error
@@ -61,22 +62,21 @@ func gitGetHead(workspaceDir string) (string, error) {
6162
}
6263

6364
// Fetches the latest commit hash using the command `git rev-parse HEAD`
64-
// through go-git
65+
// through git
6566
func fetchHeadManually(directoryPath string) (string, error) {
66-
gitOpts := &git.PlainOpenOptions{
67-
DetectDotGit: true,
68-
}
67+
cmd := exec.Command("git", "--no-pager", "rev-parse", "HEAD")
68+
cmd.Dir = directoryPath
6969

70-
// Open a new repository targeting the given path (the .git folder)
71-
repo, err := git.PlainOpenWithOptions(directoryPath, gitOpts)
72-
if err != nil {
73-
return "", err
74-
}
70+
var stdout, stderr bytes.Buffer
71+
cmd.Stdout = &stdout
72+
cmd.Stderr = &stderr
7573

76-
// Resolve revision into a sha1 commit
77-
commitHash, err := repo.ResolveRevision(plumbing.Revision("HEAD"))
74+
err := cmd.Run()
75+
outStr, _ := stdout.String(), stderr.String()
7876
if err != nil {
7977
return "", err
8078
}
81-
return commitHash.String(), nil
79+
80+
// Trim newline suffix from Commit OID
81+
return strings.TrimSuffix(outStr, "\n"), nil
8282
}

go.mod

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,26 @@ go 1.16
55
require (
66
github.com/AlecAivazis/survey/v2 v2.2.12
77
github.com/Jeffail/gabs/v2 v2.6.1
8-
github.com/Microsoft/go-winio v0.5.1 // indirect
9-
github.com/ProtonMail/go-crypto v0.0.0-20211112122917-428f8eabeeb3 // indirect
108
github.com/cli/browser v1.1.0
119
github.com/deepsourcelabs/graphql v0.2.2
1210
github.com/fatih/color v1.12.0
1311
github.com/getsentry/sentry-go v0.6.0
14-
github.com/go-git/go-git-fixtures/v4 v4.2.2 // indirect
15-
github.com/go-git/go-git/v5 v5.4.2
1612
github.com/google/go-cmp v0.5.5 // indirect
17-
github.com/kevinburke/ssh_config v1.1.0 // indirect
1813
github.com/kr/pretty v0.3.0 // indirect
1914
github.com/matryer/is v1.4.0 // indirect
2015
github.com/mattn/go-isatty v0.0.14 // indirect
2116
github.com/mitchellh/mapstructure v1.4.1 // indirect
2217
github.com/owenrumney/go-sarif/v2 v2.1.0
2318
github.com/pelletier/go-toml v1.9.2
19+
github.com/pkg/errors v0.9.1 // indirect
2420
github.com/pterm/pterm v0.12.23
2521
github.com/rogpeppe/go-internal v1.8.0 // indirect
26-
github.com/sergi/go-diff v1.2.0 // indirect
2722
github.com/spf13/cobra v1.1.3
2823
github.com/spf13/viper v1.7.1
29-
github.com/xanzy/ssh-agent v0.3.1 // indirect
3024
github.com/xeipuuv/gojsonschema v1.2.0
3125
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e // indirect
32-
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
3326
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
3427
golang.org/x/text v0.3.7 // indirect
3528
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
29+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3630
)

0 commit comments

Comments
 (0)