From 06bc251dba916be3c27c702d720a03b0c7ea1520 Mon Sep 17 00:00:00 2001 From: Billy Lynch Date: Tue, 6 Sep 2022 10:10:40 -0400 Subject: [PATCH] attest: preserve refs/attestations parent. (#129) Signed-off-by: Billy Lynch Signed-off-by: Billy Lynch --- cmd/gitsign-attest/internal/attest/attest.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/gitsign-attest/internal/attest/attest.go b/cmd/gitsign-attest/internal/attest/attest.go index 2e62b28f..2dc688f1 100644 --- a/cmd/gitsign-attest/internal/attest/attest.go +++ b/cmd/gitsign-attest/internal/attest/attest.go @@ -94,10 +94,7 @@ func WriteFile(ctx context.Context, repo *git.Repository, refName string, sha pl // Check current attestation ref to see if there is existing data. // If so, make sure old data is preserved. - var ( - parentHash plumbing.Hash - attCommit *object.Commit - ) + var attCommit *object.Commit attRef, err := repo.Reference(plumbing.ReferenceName(refName), true) if err != nil { if !errors.Is(err, plumbing.ErrReferenceNotFound) { @@ -138,8 +135,8 @@ func WriteFile(ctx context.Context, repo *git.Repository, refName string, sha pl When: time.Now(), }, } - if parentHash != plumbing.ZeroHash { - commit.ParentHashes = []plumbing.Hash{parentHash} + if attCommit != nil { + commit.ParentHashes = []plumbing.Hash{attCommit.Hash} } chash, err := encode(repo.Storer, commit) if err != nil {