-
Notifications
You must be signed in to change notification settings - Fork 0
/
bzr.go
45 lines (36 loc) · 743 Bytes
/
bzr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"io"
"os"
"os/exec"
"path/filepath"
)
type bzrRepo struct {
Repo string
Rev string
SourceDir string
Output io.Writer
}
func newBzrRepo(repo, rev, workingDir string, output io.Writer) *bzrRepo {
r := new(bzrRepo)
r.Repo = repo
r.Rev = rev
r.SourceDir = filepath.Join(workingDir, "src")
r.Output = output
return r
}
func (r *bzrRepo) checkout() error {
args := []string{"branch", "-v"}
if r.Rev != "" {
args = append(args, "-r", r.Rev)
}
args = append(args, r.Repo)
args = append(args, r.SourceDir)
cmd := exec.Command("bzr", args...)
cmd.Stdout = r.Output
cmd.Stderr = r.Output
if err := cmd.Run(); err != nil {
return err
}
return os.RemoveAll(filepath.Join(r.SourceDir, ".bzr"))
}