forked from toolshed/abra
42 lines
817 B
Go
42 lines
817 B
Go
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
|
|
}
|