feat(ops/sync-gcsr): Skip unneccessary branch updates
Checks whether branches are already up-to-date before setting references. This also makes it possible to hook additional logic on the update flow.
This commit is contained in:
parent
a21be17719
commit
44116522dd
1 changed files with 12 additions and 4 deletions
|
@ -44,15 +44,23 @@ func updateBranches(auth *http.BasicAuth, repo *git.Repository) error {
|
|||
continue
|
||||
}
|
||||
|
||||
branch := plumbing.NewHashReference(
|
||||
plumbing.NewBranchReferenceName(ref.Name().Short()),
|
||||
ref.Hash(),
|
||||
)
|
||||
name := plumbing.NewBranchReferenceName(ref.Name().Short())
|
||||
|
||||
if current, err := repo.Storer.Reference(name); err == nil {
|
||||
// Determine whether the reference has changed to skip
|
||||
// unnecessary modifications.
|
||||
if current.Hash() == ref.Hash() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
branch := plumbing.NewHashReference(name, ref.Hash())
|
||||
|
||||
err := repo.Storer.SetReference(branch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("Updated branch", ref.Name().String())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue