Skip to content

Commit

Permalink
Prefer peeled hashes for tags
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Mitchell <[email protected]>
  • Loading branch information
sudo-bmitch committed Jul 23, 2023
1 parent 9325a9f commit fce3b88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion internal/source/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (g gitSource) getRefs(confExp config.Source) ([]*plumbing.Reference, error)
Name: "origin",
URLs: []string{confExp.Args["url"]},
})
return rem.List(&git.ListOptions{})
return rem.List(&git.ListOptions{
PeelingOption: git.AppendPeeled,
})
}

func (g gitSource) getCommit(confExp config.Source) (string, error) {
Expand All @@ -54,6 +56,13 @@ func (g gitSource) getCommit(confExp config.Source) (string, error) {
for _, ref := range refs {
verData.VerMap[ref.Name().Short()] = ref.Hash().String()
}
// loop over the map entries to prefer the peeled hash (underlying commit vs signed/annotated tag hash)
for k := range verData.VerMap {
if _, ok := verData.VerMap[k+"^{}"]; ok {
verData.VerMap[k] = verData.VerMap[k+"^{}"]
delete(verData.VerMap, k+"^{}")
}
}
if len(verData.VerMap) == 0 {
return "", fmt.Errorf("ref %s not found on %s", confExp.Args["ref"], confExp.Args["url"])
}
Expand Down
2 changes: 1 addition & 1 deletion internal/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestSource(t *testing.T) {
ScanMatch: map[string]string{},
SourceArgs: map[string]string{},
},
expectGet: "6f5dc406130fdf939cc0f49fb0a5904b35a3c46f",
expectGet: "b0ac3e9413b1079c8b14df5c201a2a2129d9d9e1",
expectKey: "git ref",
},
{
Expand Down

0 comments on commit fce3b88

Please sign in to comment.