forked from toolshed/abra
41
pkg/git/pull.go
Normal file
41
pkg/git/pull.go
Normal file
@ -0,0 +1,41 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/go-git/go-git/v5"
|
||||
)
|
||||
|
||||
// Pull pulls the latest changes in.
|
||||
func Pull(repoDir string, dryRun bool) error {
|
||||
if dryRun {
|
||||
log.Debugf("dry run: no git changes pulled in %s", repoDir)
|
||||
return nil
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(repoDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts := &git.PullOptions{
|
||||
RemoteName: "origin", // NOTE(d1): what could go wrong 🤡
|
||||
}
|
||||
|
||||
worktree, err := repo.Worktree()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := worktree.Pull(opts); err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
|
||||
return err
|
||||
} else if err != nil && errors.Is(err, git.NoErrAlreadyUpToDate) {
|
||||
log.Debugf("skipping pulling changes at %s", repoDir)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debugf("git changes pulled in at %s", repoDir)
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user