Created
November 7, 2014 17:55
-
-
Save adamhjk/9c7eae1d053a1788f581 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func current_branch(git_dir string) string { | |
head_bytes, err := ioutil.ReadFile(path.Join(git_dir, "HEAD")) | |
head := string(head_bytes) | |
if err != nil { | |
log.Fatal("Cannot open HEAD from ", git_dir) | |
} | |
r, _ := regexp.Compile("ref: ref/heads/(.+)") | |
match := r.FindStringSubmatch(head) | |
branch := match[1] | |
return branch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment