-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvcs.go
62 lines (52 loc) · 1.12 KB
/
vcs.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
package main
import ()
// VCS represents Version Control System.
type VCS interface {
Update() error
Commits() []string
}
// Git implements VCS interface for Git.
type Git struct {
Dir string
}
// NewGit creates new Git object.
func NewGit(dir string) *Git {
return &Git{
Dir: dir,
}
}
// Update updates info from the remote.
func (git *Git) Update() error {
_, err := Run(git.Dir, "git", "fetch", "origin")
return err
}
// Commits returns new commits in master branch.
func (git *Git) Commits() []string {
out, err := Run(git.Dir, "git", "log", "HEAD..origin/master", "--oneline")
if err != nil {
return nil
}
return out
}
// Hg implements VCS interface for Mercurial.
type Hg struct {
Dir string
}
// NewHg creates new Hg object.
func NewHg(dir string) *Hg {
return &Hg{
Dir: dir,
}
}
// Update updates info from the remote.
func (hg *Hg) Update() error {
return nil
}
// Commits returns new commits in master branch.
func (hg *Hg) Commits() []string {
out, err := Run(hg.Dir, "hg", "incoming", "-n", "-q", "--template", "{node|short} {desc|strip|firstline}\n")
if err != nil {
return nil
}
return out
}