forked from itpp-labs/hound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bzr.go
79 lines (65 loc) · 1.3 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package vcs
import (
"bytes"
"io"
"log"
"os/exec"
"path/filepath"
"strings"
)
func init() {
Register(newBzr, "bzr")
}
func newBzr(b []byte) (Driver, error) {
return &BzrDriver{}, nil
}
type BzrDriver struct{}
func (g *BzrDriver) HeadRev(dir string) (string, error) {
cmd := exec.Command(
"bzr",
"revno")
cmd.Dir = dir
r, err := cmd.StdoutPipe()
if err != nil {
return "", err
}
defer r.Close()
if err := cmd.Start(); err != nil {
return "", err
}
var buf bytes.Buffer
if _, err := io.Copy(&buf, r); err != nil {
return "", err
}
return strings.TrimSpace(buf.String()), cmd.Wait()
}
func (g *BzrDriver) Pull(dir string) (string, error) {
cmd := exec.Command("bzr", "pull")
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Failed to bzr pull %s, see output below\n%sContinuing...", dir, out)
return "", err
}
return g.HeadRev(dir)
}
func (g *BzrDriver) Clone(dir, url string) (string, error) {
par, rep := filepath.Split(dir)
cmd := exec.Command(
"bzr",
"branch",
url,
rep)
cmd.Dir = par
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Failed to clone %s, see output below\n%sContinuing...", url, out)
return "", err
}
return g.HeadRev(dir)
}
func (g *BzrDriver) SpecialFiles() []string {
return []string{
".bzr",
}
}