forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.go
72 lines (61 loc) · 2.06 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
64
65
66
67
68
69
70
71
72
package sub
import (
"context"
"os"
"github.com/blang/semver"
gitcli "github.com/justwatchcom/gopass/backend/sync/git/cli"
"github.com/justwatchcom/gopass/backend/sync/git/gogit"
"github.com/pkg/errors"
)
type giter interface {
Add(context.Context, ...string) error
AddRemote(context.Context, string, string) error
Cmd(context.Context, string, ...string) error
Commit(context.Context, string) error
InitConfig(context.Context, string, string, string) error
Pull(context.Context, string, string) error
Push(context.Context, string, string) error
Version(context.Context) semver.Version
}
// GitInit initializes the the git repo in the store
func (s *Store) GitInit(ctx context.Context, sk, un, ue string) error {
if gg := os.Getenv("GOPASS_EXPERIMENTAL_GOGIT"); gg != "" {
git, err := gogit.Init(ctx, s.path)
if err != nil {
return errors.Wrapf(err, "failed to init git: %s", err)
}
s.git = git
return nil
}
git, err := gitcli.Init(ctx, s.path, s.gpg.Binary(), sk, un, ue)
if err != nil {
return errors.Wrapf(err, "failed to init git: %s", err)
}
s.git = git
return nil
}
// GitInitConfig (re-)intializes the git config in an existing repo
func (s *Store) GitInitConfig(ctx context.Context, sk, un, ue string) error {
return s.git.InitConfig(ctx, sk, un, ue)
}
// GitVersion returns the git version
func (s *Store) GitVersion(ctx context.Context) semver.Version {
return s.git.Version(ctx)
}
// Git channels any git subcommand to git in the store
// TODO remove this command, doesn't work with gogit
func (s *Store) Git(ctx context.Context, args ...string) error {
return s.git.Cmd(ctx, "Git", args...)
}
// GitAddRemote adds a new remote
func (s *Store) GitAddRemote(ctx context.Context, remote, url string) error {
return s.git.AddRemote(ctx, remote, url)
}
// GitPull performs a git pull
func (s *Store) GitPull(ctx context.Context, origin, branch string) error {
return s.git.Pull(ctx, origin, branch)
}
// GitPush performs a git push
func (s *Store) GitPush(ctx context.Context, origin, branch string) error {
return s.git.Push(ctx, origin, branch)
}