WIP: Refactor entire project #16
2 changed files with 21 additions and 0 deletions
|
@ -42,6 +42,7 @@ func backup(ctx context.Context, c *config.Config) error {
|
|||
c.GitRepo,
|
||||
git.WithBasicAuth(c.GitUser, c.GitPass),
|
||||
git.WithBranch(c.GitBranch),
|
||||
git.WithOutputWriter(c.Output),
|
||||
)
|
||||
|
||||
if err := project.Clone(ctx); err != nil {
|
||||
|
|
|
@ -3,6 +3,7 @@ package git
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/go-git/go-billy/v5"
|
||||
"github.com/go-git/go-billy/v5/memfs"
|
||||
|
@ -30,6 +31,12 @@ func WithBranch(branch string) ProjectOption {
|
|||
}
|
||||
}
|
||||
|
||||
func WithOutputWriter(o io.Writer) ProjectOption {
|
||||
return func(p *Project) {
|
||||
p.writer = o
|
||||
}
|
||||
}
|
||||
|
||||
type Project struct {
|
||||
Branch string
|
||||
Force bool
|
||||
|
@ -40,6 +47,7 @@ type Project struct {
|
|||
storer *memory.Storage
|
||||
repository *git.Repository
|
||||
worktree *git.Worktree
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
func NewProject(url string, options ...ProjectOption) *Project {
|
||||
|
@ -103,6 +111,10 @@ func (p *Project) Clone(ctx context.Context) error {
|
|||
cloneOpts.Auth = p.auth
|
||||
}
|
||||
|
||||
if p.writer != nil {
|
||||
cloneOpts.Progress = p.writer
|
||||
}
|
||||
|
||||
if err := cloneOpts.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -147,6 +159,10 @@ func (p *Project) Pull(ctx context.Context) error {
|
|||
ReferenceName: plumbing.NewBranchReferenceName(p.Branch),
|
||||
}
|
||||
|
||||
if p.writer != nil {
|
||||
pullOpts.Progress = p.writer
|
||||
}
|
||||
|
||||
if err := pullOpts.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -168,6 +184,10 @@ func (p *Project) Push(ctx context.Context) error {
|
|||
pushOpts.Auth = p.auth
|
||||
}
|
||||
|
||||
if p.writer != nil {
|
||||
pushOpts.Progress = p.writer
|
||||
}
|
||||
|
||||
if err := pushOpts.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue