forked from gopasspw/gopass
/
git.go
63 lines (55 loc) · 1.65 KB
/
git.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
package root
import (
"fmt"
"strings"
"github.com/blang/semver"
"github.com/fatih/color"
"github.com/justwatchcom/gopass/store"
)
// GitInit initializes the git repo
func (r *Store) GitInit(name, sk, userName, userEmail string) error {
store := r.getStore(name)
return store.GitInit(store.Alias(), sk, userName, userEmail)
}
// GitVersion returns git version information
func (r *Store) GitVersion() semver.Version {
return r.store.GitVersion()
}
// Git runs arbitrary git commands on this store and all substores
func (r *Store) Git(name string, recurse, force bool, args ...string) error {
sub := r.getStore(name)
dispName := name
if dispName == "" {
dispName = "root"
}
fmt.Println(color.CyanString("[%s] Running git %s", dispName, strings.Join(args, " ")))
if err := sub.Git(args...); err != nil {
if err == store.ErrGitNoRemote {
fmt.Println(color.YellowString("[%s] Has no remote. Skipping", dispName))
} else {
if !force {
return err
}
fmt.Println(color.RedString("[%s] Failed to run 'git %s'", dispName, strings.Join(args, " ")))
}
}
// TODO(dschulz) we could properly handle the "recurse to given substores"
// case ...
if !recurse || name != "" {
return nil
}
for _, alias := range r.MountPoints() {
fmt.Println(color.CyanString("[%s] Running 'git %s'", alias, strings.Join(args, " ")))
if err := r.mounts[alias].Git(args...); err != nil {
if err == store.ErrGitNoRemote {
fmt.Println(color.YellowString("[%s] Has no remote. Skipping", alias))
continue
}
if !force {
return err
}
fmt.Println(color.RedString("[%s] Failed to run 'git %s'", alias, strings.Join(args, " ")))
}
}
return nil
}