Refactor code to live inside default pkg

This commit is contained in:
Sam Coe 2022-04-19 13:31:59 +02:00
parent 9060b44e6d
commit 22a5d2abf8
No known key found for this signature in database
GPG key ID: 8E322C20F811D086
8 changed files with 589 additions and 268 deletions

View file

@ -394,7 +394,6 @@ func ToplevelDir() (string, error) {
}
output, err := run.PrepareCmd(showCmd).Output()
return firstLine(output), err
}
// ToplevelDirFromPath returns the top-level given path of the current repository
@ -439,3 +438,16 @@ func getBranchShortName(output []byte) string {
branch := firstLine(output)
return strings.TrimPrefix(branch, "refs/heads/")
}
func IsGitDirectory() bool {
showCmd, err := GitCommand("rev-parse", "--is-inside-work-tree")
if err != nil {
return false
}
output, err := run.PrepareCmd(showCmd).Output()
if err != nil {
return false
}
out := firstLine(output)
return out == "true"
}