Skip to content

Commit

Permalink
#13 tag & push branch names in detached mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dkapanidis committed Jul 8, 2015
1 parent 448a074 commit 5ffe50c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions captain/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func execute(name string, arg ...string) error {
return cmd.Run()
}

func oneliner(name string, arg ...string) string {
func oneliner(name string, arg ...string) (string, error) {
var buff bytes.Buffer
gitCmd := exec.Command(name, arg...)
gitCmd:= exec.Command(name, arg...)
gitCmd.Stdout = &buff
gitCmd.Run()
return strings.TrimSpace(buff.String())
err := gitCmd.Run()
return strings.TrimSpace(buff.String()),err
}
17 changes: 12 additions & 5 deletions captain/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,35 @@ import (
)

func getRevision() string {
return oneliner("git", "rev-parse", "--short", "HEAD")
res,_ := oneliner("git", "rev-parse", "--short", "HEAD")
return res
}

func getBranch() string {
branch := oneliner("git", "rev-parse", "--abbrev-ref", "HEAD")

branch,_ := oneliner("git", "name-rev", "--name-only", "HEAD")
tag,err := oneliner("git", "describe", "--exact-match","HEAD")
if (err ==nil) {
branch = tag
}
// Remove start of "heads/origin" if exist
r := regexp.MustCompile("^heads\\/origin\\/")
branch = r.ReplaceAllString(branch, "")

// Replace all "/" with "."
branch = strings.Replace(branch, "/", ".", -1)

// Replace all "~" with "."
branch = strings.Replace(branch, "~", ".", -1)

return branch
}

func isDirty() bool {
var res = oneliner("git", "status", "--porcelain")
res,_ := oneliner("git", "status", "--porcelain")
return len(res) > 0
}

func isGit() bool {
var res = getRevision()
res := getRevision()
return len(res) > 0
}

0 comments on commit 5ffe50c

Please sign in to comment.