diff options
Diffstat (limited to 'git.go')
-rw-r--r-- | git.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -2,8 +2,10 @@ package svn2git2aur import ( "bytes" + "fmt" "os" "os/exec" + "strings" "git.lukeshu.com/go/libfastimport" ) @@ -77,3 +79,30 @@ func gitFastImport(args ...string) (*libfastimport.Backend, error) { return backend, nil } + +func gitRefs() (map[string]string, error) { + cmd := exec.Command("git", "for-each-ref") + b, err := cmd.Output() + if err != nil { + return nil, err + } + lines := strings.Split(string(b), "\n") + ret := make(map[string]string, len(lines)-1) + for _, line := range lines { + if line == "" { + continue + } + fields := strings.SplitN(line, " ", 3) + if len(fields) != 3 { + return nil, fmt.Errorf("malformed git for-each-ref line: %q", line) + } + refTarget := fields[0] + refType := fields[1] + refName := fields[2] + if refType != "commit" { + continue + } + ret[refName] = refTarget + } + return ret, nil +} |