WIP: operator collaboration MVP

See toolshed/organising#467
This commit is contained in:
2024-12-30 00:46:25 +01:00
parent 74108b0dd9
commit 4d7c812fe2
13 changed files with 319 additions and 20 deletions

41
pkg/git/pull.go Normal file
View 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
}