Skip to content

Commit 2d6cee9

Browse files
committed
fix: fix shallow clones not retrieving a valid semver
1 parent 84cdcac commit 2d6cee9

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

scripts/version.sh

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ if [[ -n "${CODER_FORCE_VERSION:-}" ]]; then
2626
exit 0
2727
fi
2828

29-
# To make contributing easier, if the upstream isn't coder/coder and there are
30-
# no tags we will fall back to 0.1.0 with devel suffix.
31-
remote_url=$(git remote get-url origin)
29+
30+
# To make contributing easier, if there are no tags, we'll use a default
31+
# version.
3232
tag_list=$(git tag)
33-
if ! [[ ${remote_url} =~ [@/]github.com ]] && ! [[ ${remote_url} =~ [:/]coder/coder(\.git)?$ ]] && [[ -z ${tag_list} ]]; then
34-
log
35-
log "INFO(version.sh): It appears you've checked out a fork of Coder."
36-
log "INFO(version.sh): By default GitHub does not include tags when forking."
37-
log "INFO(version.sh): We will use the default version 2.0.0 for this build."
38-
log "INFO(version.sh): To pull tags from upstream, use the following commands:"
39-
log "INFO(version.sh): - git remote add upstream https://github.com/coder/coder.git"
40-
log "INFO(version.sh): - git fetch upstream"
41-
log
42-
last_tag="v2.0.0"
33+
if [[ -z ${tag_list} ]]; then
34+
log
35+
log "INFO(version.sh): It appears you've checked out a fork or shallow clone of Coder."
36+
log "INFO(version.sh): By default GitHub does not include tags when forking."
37+
log "INFO(version.sh): We will use the default version 2.0.0 for this build."
38+
log "INFO(version.sh): To pull tags from upstream, use the following commands:"
39+
log "INFO(version.sh): - git remote add upstream https://github.com/coder/coder.git"
40+
log "INFO(version.sh): - git fetch upstream"
41+
log
42+
last_tag="v2.0.0"
4343
else
44-
current_commit=$(git rev-parse HEAD)
45-
# Try to find the last tag that contains the current commit
46-
last_tag=$(git tag --contains "$current_commit" --sort=version:refname | head -n 1)
47-
# If there is no tag that contains the current commit,
48-
# get the latest tag sorted by semver.
49-
if [[ -z "${last_tag}" ]]; then
50-
last_tag=$(git tag --sort=version:refname | tail -n 1)
51-
fi
44+
current_commit=$(git rev-parse HEAD)
45+
# Try to find the last tag that contains the current commit
46+
last_tag=$(git tag --contains "$current_commit" --sort=version:refname | head -n 1)
47+
# If there is no tag that contains the current commit,
48+
# get the latest tag sorted by semver.
49+
if [[ -z "${last_tag}" ]]; then
50+
last_tag=$(git tag --sort=version:refname | tail -n 1)
51+
fi
5252
fi
5353

5454
version="${last_tag}"

0 commit comments

Comments
 (0)