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

Fix failure to sort properly with prefix, sort double numbers (#43 #44). #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions git-semver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,22 @@ version-parse-pre-release() {
version-get() {
local sort_args version version_pre_releases pre_release_id_count pre_release_id_index
local tags=$(git tag)
local sorted_tags=$(
echo "$tags" |
grep -oP "^${VERSION_PREFIX}\K[0-9]+\.[0-9]+\.[0-9]+.*" |
Copy link

@endavid endavid Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks on macOS because the P option does not exist.
In macOS, I replaced it with this and it worked:

perl -nle "m/^${VERSION_PREFIX}\K[0-9]+\.[0-9]+\.[0-9]+.*/ && print $&"

awk -F '[-+]' '{ print $1 }' |
uniq |
sort -t '.' -k 1,1n -k 2,2n -k 3,3n |
awk -v VERSION_PREFIX="${VERSION_PREFIX}" '{print VERSION_PREFIX $1}'
)

local version_pre_release=$(
local version_main=$(
echo "$tags" |
grep "^${VERSION_PREFIX}[0-9]\+\.[0-9]\+\.[0-9]\+" |
awk -F '[-+]' '{ print $1 }' |
uniq |
sort -t '.' -k 1,1n -k 2,2n -k 3,3n |
echo "$sorted_tags" |
tail -n 1
)
local version_pre_releases=$(
echo "$tags" |
echo "$sorted_tags" |
grep "^${version_main//./\\.}" |
awk -F '-' '{ print $2 }'
)
Expand Down Expand Up @@ -210,7 +215,7 @@ version-get() {
tail -n 1
)
# Get the version with the build number
version=$(echo "$tags" | grep "^${version_pre_release//./\\.}" | tail -n 1)
version=$(echo "$sorted_tags" | grep "^${version_pre_release//./\\.}" | tail -n 1)
if [ "" == "${version}" ]
then
return 1
Expand Down