Skip to content

Commit

Permalink
Merge pull request #12 from sortlist/fix_name_issue
Browse files Browse the repository at this point in the history
Fix issue when the prefix tag contains a '-'
  • Loading branch information
Tycale authored May 14, 2024
2 parents 5447d47 + 0ebb816 commit fb1409a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions test/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GIT_LIST_TAGS_COMMAND="git tag --list"
source "${BATS_TEST_DIRNAME}/../version.sh" >/dev/null 2>/dev/null

rand_prefix() {
echo $(tr -dc a-z0-9 </dev/urandom | head -c 5)
tr -dc a-z0-9 </dev/urandom | head -c 5
}

setup() {
Expand All @@ -17,31 +17,31 @@ teardown() {
}

@test "Initial version" {
run compute_version $prefix false
run compute_version "$prefix" false

[ $status -eq 0 ]
[ "$output" = "${base_part}.1" ]
}

@test "Initial version with pre-release" {
run compute_version $prefix true
run compute_version "$prefix" true

[ $status -eq 0 ]
[ "$output" = "${base_part}.1-1" ]
}

@test "Initial version with pre-release and pre-release prefix" {
prepre=$(rand_prefix)
run compute_version $prefix true $prepre
run compute_version "$prefix" true "$prepre"

[ $status -eq 0 ]
[ "$output" = "${base_part}.1-${prepre}1" ]
}

@test "Version increment" {
git tag $(compute_version $prefix)
git tag "$(compute_version "$prefix")"

run compute_version $prefix
run compute_version "$prefix"

[ $status -eq 0 ]
[ "$output" = "${base_part}.2" ]
Expand All @@ -53,16 +53,16 @@ teardown() {
git tag "${base_part}.${i}"
done

run compute_version $prefix
run compute_version "$prefix"

[ $status -eq 0 ]
[ "$output" = "${base_part}.101" ]
}

@test "Version pre-release increment" {
git tag $(compute_version $prefix true)
git tag "$(compute_version "$prefix" true)"

run compute_version $prefix true
run compute_version "$prefix" true

[ $status -eq 0 ]
[ "$output" = "${base_part}.1-2" ]
Expand All @@ -74,16 +74,16 @@ teardown() {
git tag "${base_part}.1-${i}"
done

run compute_version $prefix true
run compute_version "$prefix" true

[ $status -eq 0 ]
[ "$output" = "${base_part}.1-101" ]
}

@test "Version pre-release increment existing version" {
git tag $(compute_version $prefix)
git tag "$(compute_version "$prefix")"

run compute_version $prefix true
run compute_version "$prefix" true

[ $status -eq 0 ]
[ "$output" = "${base_part}.2-1" ]
Expand Down
2 changes: 1 addition & 1 deletion version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ compute_version() {
preprefix=$3

next="${prefix}$(base_version)"
inc=$("${GIT_LIST_TAGS_COMMAND[@]}" "${next}.*" | grep -v '\-.*[0-9]\+$' --count ||:)
inc=$("${GIT_LIST_TAGS_COMMAND[@]}" "${next}.*" | grep -v "\-${preprefix}[0-9]\+$" --count ||:)
inc=$((inc+1))

if [ "$prerelease" = true ]
Expand Down

0 comments on commit fb1409a

Please sign in to comment.