Skip to content

Commit ed38e7d

Browse files
committed
fix case where remote has no tags or filtering removes all tags
Signed-off-by: Taylor Silva <dev@taydev.net>
1 parent dcffa15 commit ed38e7d

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

assets/check_tags.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ fi
1414

1515
cd "$destination"
1616

17+
# git fetch exits 1 when the refspec matches no refs, so short-circuit
18+
# when the remote has no tags.
19+
if [[ -z "$(git ls-remote --tags "$uri")" ]]; then
20+
echo '[]' >&3
21+
exit 0
22+
fi
23+
1724
git fetch --depth=1 \
1825
--filter=tree:0 \
1926
--no-tags \
@@ -66,9 +73,8 @@ fi
6673
if [[ "$sorted" == "false" ]]; then
6774
sorted_tags=$filtered_tags
6875
fi
69-
sorted_tags=$(echo "$sorted_tags" | grep -v '^[[:space:]]*$')
7076

71-
jtags=$(echo "$sorted_tags" | jq -Rn \
77+
jtags=$(printf '%s' "$sorted_tags" | jq -Rn \
7278
--arg prevtag "$prev_tag" \
7379
'[inputs | (./"\t") | {tag: .[0], ref: .[1]}] | .[(map(.tag) | index($prevtag)):]')
7480

test/check_tags.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,25 @@ it_returns_new_tags() {
7979
| jq -e 'map(.tag) == ["v1.2.0","v1.2.1"]'
8080
}
8181

82+
it_finds_no_tags() {
83+
local repo=$(init_repo)
84+
85+
check_uri_with_tags $repo | jq -e '. == []'
86+
}
87+
88+
it_returns_no_tags_due_to_filtering() {
89+
local repo=$(init_repo)
90+
make_annotated_tag $repo foo-1 "tag foo-1" true >/dev/null
91+
92+
check_uri_with_tags_filter $repo "nomatch*" | jq -e '. == []'
93+
}
94+
8295
run it_gets_all_tags
8396
run it_uses_tag_filter
8497
run it_uses_tag_filters
8598
run it_combines_tag_filter_and_tag_filters
8699
run it_uses_tag_regex
87100
run it_sorts_by_semver
88101
run it_returns_new_tags
102+
run it_finds_no_tags
103+
run it_returns_no_tags_due_to_filtering

0 commit comments

Comments
 (0)