MCPcopy
hub / github.com/perkeep/perkeep / getGitVersion

Function getGitVersion

make.go:265–291  ·  view source on GitHub ↗

getGitVersion returns the git version of the git repo at pkRoot as a string of the form "yyyy-mm-dd-xxxxxxx", with an optional trailing '+' if there are any local uncommitted modifications to the tree.

()

Source from the content-addressed store, hash-verified

263// string of the form "yyyy-mm-dd-xxxxxxx", with an optional trailing
264// '+' if there are any local uncommitted modifications to the tree.
265func getGitVersion() string {
266 if _, err := exec.LookPath("git"); err != nil {
267 return ""
268 }
269 if _, err := os.Stat(filepath.Join(pkRoot, ".git")); os.IsNotExist(err) {
270 return ""
271 }
272 cmd := exec.Command("git", "rev-list", "--max-count=1", "--pretty=format:'%ad-%h'",
273 "--date=short", "--abbrev=10", "HEAD")
274 cmd.Dir = pkRoot
275 out, err := cmd.Output()
276 if err != nil {
277 log.Fatalf("Error running git rev-list in %s: %v", pkRoot, err)
278 }
279 v := strings.TrimSpace(string(out))
280 if m := gitVersionRx.FindStringSubmatch(v); m != nil {
281 v = m[0]
282 } else {
283 panic("Failed to find git version in " + v)
284 }
285 cmd = exec.Command("git", "diff", "--exit-code")
286 cmd.Dir = pkRoot
287 if err := cmd.Run(); err != nil {
288 v += "+"
289 }
290 return v
291}
292
293// verifyPerkeepRoot sets pkRoot and crashes if dir isn't the Perkeep root directory.
294func verifyPerkeepRoot() {

Callers 1

mainFunction · 0.85

Calls 5

LookPathMethod · 0.65
StatMethod · 0.65
CommandMethod · 0.65
FatalfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected