forked from gopasspw/gopass
/
git.go
72 lines (59 loc) · 2.24 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 root
import (
"context"
"github.com/gopasspw/gopass/pkg/backend"
"github.com/gopasspw/gopass/pkg/store"
"github.com/blang/semver"
)
// RCS returns the sync backend
func (r *Store) RCS(ctx context.Context, name string) backend.RCS {
_, sub, _ := r.getStore(ctx, name)
if sub == nil || !sub.Valid() {
return nil
}
return sub.RCS()
}
// GitInit initializes the git repo
func (r *Store) GitInit(ctx context.Context, name, userName, userEmail string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.GitInit(ctx, userName, userEmail)
}
// GitInitConfig initializes the git repos local config
func (r *Store) GitInitConfig(ctx context.Context, name, userName, userEmail string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().InitConfig(ctx, userName, userEmail)
}
// GitVersion returns git version information
func (r *Store) GitVersion(ctx context.Context) semver.Version {
return r.store.RCS().Version(ctx)
}
// GitAddRemote adds a git remote
func (r *Store) GitAddRemote(ctx context.Context, name, remote, url string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().AddRemote(ctx, remote, url)
}
// GitRemoveRemote removes a git remote
func (r *Store) GitRemoveRemote(ctx context.Context, name, remote string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().RemoveRemote(ctx, remote)
}
// GitPull performs a git pull
func (r *Store) GitPull(ctx context.Context, name, origin, remote string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().Pull(ctx, origin, remote)
}
// GitPush performs a git push
func (r *Store) GitPush(ctx context.Context, name, origin, remote string) error {
ctx, store, _ := r.getStore(ctx, name)
return store.RCS().Push(ctx, origin, remote)
}
// ListRevisions will list all revisions for the named entity
func (r *Store) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) {
ctx, store, name := r.getStore(ctx, name)
return store.ListRevisions(ctx, name)
}
// GetRevision will try to retrieve the given revision from the sync backend
func (r *Store) GetRevision(ctx context.Context, name, revision string) (store.Secret, error) {
ctx, store, name := r.getStore(ctx, name)
return store.GetRevision(ctx, name, revision)
}