Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer peeled hashes for tags #20

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading