@@ -13,9 +13,54 @@ show_usage() {
1313 echo " major - Increment major version (X.0.0)"
1414}
1515
16+ # Try to fetch tags; if it fails (eg. due to moving tags like v0),
17+ # print helpful instructions and continue using local tags.
18+ fetch_tags_or_report() {
19+ if git fetch --tags --quiet 2>/dev/null; then
20+ return 0
21+ fi
22+
23+ echo "WARNING: git fetch --tags failed. This can happen if moving tags (eg. v0) differ locally."
24+
25+ # Detect conflicting tags between remote and local
26+ declare -A _remote _local
27+
28+ while read -r sha ref; do
29+ tag="${ref#refs/tags/}"
30+ [[ -n "$tag" ]] && _remote["$tag"]="$sha"
31+ done < <(git ls-remote --tags --refs origin 2>/dev/null || true)
32+
33+ while read -r sha ref; do
34+ tag="${ref#refs/tags/}"
35+ [[ -n "$tag" ]] && _local["$tag"]="$sha"
36+ done < <(git show-ref --tags 2>/dev/null || true)
37+
38+ conflicts=()
39+ for tag in "${!_remote[@]}"; do
40+ if [[ -n "${_local[$tag]:-}" && "${_local[$tag]}" != "${_remote[$tag]}" ]]; then
41+ conflicts+=("$tag")
42+ fi
43+ done
44+
45+ if [[ ${#conflicts[@]} -gt 0 ]]; then
46+ echo "Detected conflicting tags: ${conflicts[*]}"
47+ echo "To sync, either run:"
48+ echo " git fetch --tags --force"
49+ echo "or update individually, eg:"
50+ for t in "${conflicts[@]}"; do
51+ echo " git tag -d $t && git fetch origin tag $t -f"
52+ done
53+ else
54+ echo "No specific conflicting tags detected. You may try: git fetch --tags --force"
55+ fi
56+
57+ # Continue with local tags
58+ return 0
59+ }
60+
1661get_last_release() {
17- # Get the most recent version tag
18- git tag -l 'v*' --sort=-version:refname | head -1
62+ # Get the most recent semver tag (vX.Y.Z), ignore moving tags like v0
63+ git tag -l 'v[0-9]*.[0-9]*.[0-9] *' --sort=-version:refname | head -1
1964}
2065
2166increment_version() {
@@ -50,8 +95,8 @@ if [ -z "$current_version" ] || [ "$current_version" = "null" ]; then
5095 exit 1
5196fi
5297
53- # Fetch latest tags to ensure we have accurate release history
54- git fetch --tags --quiet 2>/dev/null
98+ # Fetch latest tags to ensure we have accurate release history (with guidance on failure)
99+ fetch_tags_or_report
55100
56101# Verify version consistency
57102last_release=$(get_last_release)
0 commit comments