Extract git interactions into interface

This commit is contained in:
Sam Coe 2021-06-11 13:25:21 -04:00
parent c6f89d3c17
commit 8b5abc77ea
No known key found for this signature in database
GPG key ID: 8E322C20F811D086
4 changed files with 144 additions and 66 deletions

View file

@ -368,30 +368,3 @@ func getBranchShortName(output []byte) string {
branch := firstLine(output)
return strings.TrimPrefix(branch, "refs/heads/")
}
func IsAncestor(ancestor, commit string) (bool, error) {
cmd, err := GitCommand("merge-base", "--is-ancestor", ancestor, commit)
if err != nil {
return false, err
}
err = run.PrepareCmd(cmd).Run()
return err == nil, nil
}
func IsDirty() (bool, error) {
cmd, err := GitCommand("status", "--untracked-files=no", "--porcelain")
if err != nil {
return false, err
}
output, err := run.PrepareCmd(cmd).Output()
if err != nil {
return true, err
}
if len(output) > 0 {
return true, nil
}
return false, nil
}