diff options
author | Alan Pearce | 2024-06-25 20:50:53 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-25 20:50:53 +0200 |
commit | b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d (patch) | |
tree | 3775cc5fde036bb31eb0751a59aed719395fd53d | |
parent | 7550950f27e5904cfb23ca492feb402edafbcb9a (diff) | |
download | website-b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d.tar.lz website-b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d.tar.zst website-b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d.zip |
update worktree after fetching updates
-rw-r--r-- | internal/vcs/repository.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go index cc9bdaa..56d439d 100644 --- a/internal/vcs/repository.go +++ b/internal/vcs/repository.go @@ -3,6 +3,7 @@ package vcs import ( "os" "website/internal/config" + "website/internal/log" "github.com/go-git/go-git/v5" gitc "github.com/go-git/go-git/v5/config" @@ -39,6 +40,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) { if err != nil { return nil, err } + return repo, nil } @@ -48,6 +50,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) { } func (r *Repository) Update(cfg *Config) (bool, error) { + log.Debug("updating repository") err := r.repo.Fetch(&git.FetchOptions{ RefSpecs: []gitc.RefSpec{ gitc.RefSpec( @@ -57,9 +60,21 @@ func (r *Repository) Update(cfg *Config) (bool, error) { }) if err != nil { if errors.Is(err, git.NoErrAlreadyUpToDate) { + log.Debug("no changes to pull") return false, nil } + + return false, err + } + + head, err := r.repo.Head() + if err != nil { return false, err } + log.Debug("applying changes", "head", head.Name()) + err = r.repo.Merge(*head, git.MergeOptions{ + Strategy: git.FastForwardMerge, + }) + return true, nil } |