Skip to content

Instantly share code, notes, and snippets.

@ae6rt
Created November 15, 2014 14:24
Show Gist options
  • Save ae6rt/0aa35403f678bfe54960 to your computer and use it in GitHub Desktop.
Save ae6rt/0aa35403f678bfe54960 to your computer and use it in GitHub Desktop.
Read lines from a buffer of bytes
func GetBranches() ([]string, error) {
cmd := "git"
args := []string{"ls-remote", "--heads"}
if debug {
log.Printf("%s %v\n", cmd, args)
}
command := exec.Command(cmd, args...)
if data, err := command.Output(); err != nil {
return nil, err
} else {
r := make([]string, 0)
readbuffer := bytes.NewBuffer(data)
reader := bufio.NewReader(readbuffer)
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
parts := strings.Fields(scanner.Text())
branchName := strings.Replace(parts[1], "refs/heads/", "", -1)
r = append(r, branchName)
}
return r, nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment