Skip to content

Commit

Permalink
Assigning a non-strictly-increasing version is possible with force
Browse files Browse the repository at this point in the history
Close #11
  • Loading branch information
jola5 committed Jul 5, 2017
1 parent 6297ae7 commit 6f21246
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/git-tag-version
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function help
SYNOPSIS
git-tag-version [command] [-m|--message=<message>] [-x|--suffix=<suffix>]
[-s|--strict] [-n|--non-strict]
[-s|--strict] [-n|--non-strict] [-f|--force]
DESCRIPTION
A script to use git tags for repository version numbers through a simple
Expand Down Expand Up @@ -80,7 +80,7 @@ DESCRIPTION
For gtv there is no meaning in suffixes like 'alpha', 'beta', 'RC1' etc.
If you assign multiple tag versions to the same commit by non-strict mode
the version reported by 'gtv show' is the last version that is reported by
'git tag --list'. This may or may not be what is expected.
'git tag --list'. This may or may not be what is expected.
Mind, assigning mulitple version tags to the same commit is possible
by default. If you want to omit this behaviour use the strict-mode option.
Expand Down Expand Up @@ -124,12 +124,13 @@ COMMANDS
'strict'.
set <version> [-m|--message=<message>] [-x|--suffix=<suffix>]
[-s|--strict] [-n|--non-strict]
[-s|--strict] [-n|--non-strict] [-f|--force]
Assign a specific git version number tag, must be strictly
increasing. Add the optional message to annotated tags. Add the
optional tag suffix as a suffix to the tag name itself. Do not
allow assignment of mulitple version tags to the same commit
using 'strict'.
using 'strict'. If you want to assign a not strictly increasing
version number you may do so by using 'force'.
EXAMPLES
# show current version, eg. 1.21.3
Expand Down Expand Up @@ -322,7 +323,7 @@ function set-version
VERSION_OK=true
fi

if [ "$VERSION_OK" = true ]; then
if [ "$VERSION_OK" = true ] || [ "$FORCE" = true ]; then
echo "New version: $1"
create-version-tag "manually defined version number" $1
else
Expand Down Expand Up @@ -353,9 +354,10 @@ SUFFIX_DELIMITER=$(git config gtv.suffix-delimiter)
SUFFIX_DELIMITER=${SUFFIX_DELIMITER:--}
STRICT=$(git config gtv.strict-mode)
STRICT=${STRICT:-false}
FORCE=false

# get the optional arguments
ARGS=$(getopt -o m:nsx: -l "message:,non-strict,strict,suffix:" -n "getopt.sh" -- "$@");
ARGS=$(getopt -o fm:nsx: -l "force,message:,non-strict,strict,suffix:" -n "getopt.sh" -- "$@");

#Bad arguments
if [ $? -ne 0 ];
Expand All @@ -367,6 +369,10 @@ eval set -- "$ARGS";

while true; do
case "$1" in
-f|--force)
FORCE=true
shift;
;;
-n|--non-strict)
STRICT=false
shift;
Expand Down
9 changes: 8 additions & 1 deletion test/01-basics.bats
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function teardown {
[ "$output" = "1.2.3" ]
}

@test "set semantically invalid specific version fails" {
@test "set specific non-strictly-increasing version fails" {
run ${GTV} init
run ${GTV} set 1.2.3
run ${GTV} set 1.0.0
Expand All @@ -86,3 +86,10 @@ function teardown {
echo "status: $status"
[ "$status" = 1 ]
}

@test "set specifc non-strictly-increasing version with force" {
run ${GTV} init
run ${GTV} set 1.2.3
run ${GTV} set 1.0.0 --force
[ "$status" = 0 ]
}

0 comments on commit 6f21246

Please sign in to comment.