Skip to content

Commit b3a73c0

Browse files
authored
Merge pull request #3315 from joolswills/repo_tag_ref_check_fix
packages - handle git repositories with two tag references
2 parents e54b8fa + 4a285bb commit b3a73c0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scriptmodules/packages.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,15 @@ function rp_getRemoteRepoHash() {
528528
set -o pipefail
529529
case "$type" in
530530
git)
531-
cmd=(git ls-remote "$url" "$branch")
532-
# grep to make sure we only return refs/heads/BRANCH and refs/tags/BRANCH in case there are
533-
# additional references to the branch/tag eg refs/heads/SOMETHINGELSE/master which can be the case
534-
hash=$("${cmd[@]}" 2>/dev/null | grep -P "\trefs/(heads|tags)/$branch" | cut -f1)
531+
# when the remote repository uses an annotated git tag, the real commit is found by looking for the
532+
# "tag^{}" reference, since the the tag ref will point to the tag object itself, instead of the tagged
533+
# commit. See gitrevisions(7).
534+
cmd=(git ls-remote "$url" "$branch" "$branch^{}")
535+
# grep to make sure we only return refs/heads/BRANCH and refs/tags/BRANCH in case there are additional
536+
# references to the branch/tag eg refs/heads/SOMETHINGELSE/master which can be the case.
537+
# we grab the last match reported by grep, as tags that also have a tag^{} reference
538+
# will be displayed after.
539+
hash=$("${cmd[@]}" 2>/dev/null | grep -P "\trefs/(heads|tags)/$branch" | tail -n1 | cut -f1)
535540
;;
536541
svn)
537542
cmd=(svn info -r"$commit" "$url")

0 commit comments

Comments
 (0)