diff options
author | Vincent Ambo <Vincent Ambo> | 2020-01-18T14·48+0000 |
---|---|---|
committer | Vincent Ambo <Vincent Ambo> | 2020-01-18T14·49+0000 |
commit | 44116522dd82aefbaf7cdb9f42dbcc1e96eedc99 (patch) | |
tree | 5caae5480b9247e3e86323447cfb9ca3f39f42e6 /ops | |
parent | a21be17719d95e75036e6423fb623a9914d2fbd5 (diff) |
feat(ops/sync-gcsr): Skip unneccessary branch updates r/405
Checks whether branches are already up-to-date before setting references. This also makes it possible to hook additional logic on the update flow.
Diffstat (limited to '')
-rw-r--r-- | ops/sync-gcsr/main.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ops/sync-gcsr/main.go b/ops/sync-gcsr/main.go index a02f6d552730..08e2627c6602 100644 --- a/ops/sync-gcsr/main.go +++ b/ops/sync-gcsr/main.go @@ -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()) } |