MCPcopy Index your code
hub / github.com/devspace-sh/devspace / GetHash

Function GetHash

pkg/util/git/helper.go:36–58  ·  view source on GitHub ↗

GetHash retrieves the current HEADs hash

(ctx context.Context, localPath string)

Source from the content-addressed store, hash-verified

34
35// GetHash retrieves the current HEADs hash
36func GetHash(ctx context.Context, localPath string) (string, error) {
37 repo, err := git.PlainOpen(localPath)
38 if err != nil {
39 // last resort, try with cli
40 if isGitCommandAvailable(ctx) {
41 out, err := command.CombinedOutput(ctx, localPath, expand.ListEnviron(os.Environ()...), "git", "rev-parse", "HEAD")
42 if err != nil {
43 return "", errors.Errorf("Error running 'git rev-parse HEAD': %v -> %s", err, string(out))
44 }
45
46 return strings.TrimSpace(string(out)), nil
47 }
48
49 return "", errors.Wrap(err, "git open")
50 }
51
52 head, err := repo.Head()
53 if err != nil {
54 return "", errors.Wrap(err, "get head")
55 }
56
57 return head.Hash().String(), nil
58}
59
60// GetRemote retrieves the remote origin
61func GetRemote(localPath string) (string, error) {

Callers 3

TestGitCliCommitFunction · 0.85
TestGoGitFunction · 0.85

Calls 4

isGitCommandAvailableFunction · 0.85
EnvironMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by 2

TestGitCliCommitFunction · 0.68
TestGoGitFunction · 0.68