Add add command to git

Signed-off-by: Philip Laine <philip.laine@gmail.com>
pull/3199/head
Philip Laine 3 years ago
parent d3629898ea
commit 5691a444f1

@ -44,6 +44,7 @@ type Git interface {
Init(url, branch string) (bool, error) Init(url, branch string) (bool, error)
Clone(ctx context.Context, url, branch string, caBundle []byte) (bool, error) Clone(ctx context.Context, url, branch string, caBundle []byte) (bool, error)
Write(path string, reader io.Reader) error Write(path string, reader io.Reader) error
Add(path string) error
Commit(message Commit, options ...Option) (string, error) Commit(message Commit, options ...Option) (string, error)
Push(ctx context.Context, caBundle []byte) error Push(ctx context.Context, caBundle []byte) error
Status() (bool, error) Status() (bool, error)

@ -89,6 +89,18 @@ func (g *GoGit) Init(url, branch string) (bool, error) {
return true, nil return true, nil
} }
func (g *GoGit) Add(path string) error {
wt, err := g.repository.Worktree()
if err != nil {
return err
}
_, err = wt.Add(path)
if err != nil {
return err
}
return nil
}
func (g *GoGit) Clone(ctx context.Context, url, branch string, caBundle []byte) (bool, error) { func (g *GoGit) Clone(ctx context.Context, url, branch string, caBundle []byte) (bool, error) {
branchRef := plumbing.NewBranchReferenceName(branch) branchRef := plumbing.NewBranchReferenceName(branch)
r, err := gogit.PlainCloneContext(ctx, g.path, false, &gogit.CloneOptions{ r, err := gogit.PlainCloneContext(ctx, g.path, false, &gogit.CloneOptions{

Loading…
Cancel
Save