Skip to content

Commit

Permalink
Add version number auto-increment support.
Browse files Browse the repository at this point in the history
'git flow hotfix start' and 'git flow release start' will suggest
a new version number based on previous tags in the respository.
The respective stop commands will suggest the same version number.
Version numbers are in the form [major].[minor].[revision]
(eg. 1.3.5). 'hotfix' assumes a revision bump and 'release' assumes
a minor bump, but suggestion can be overridden. In addition
'git flow hotfix start 1.0.0' and 'git flow release start 1.0.0'
still work as expected.
  • Loading branch information
Nickolas Means committed May 24, 2011
1 parent 14bcc58 commit fcfecc4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
8 changes: 5 additions & 3 deletions git-flow-hotfix
Expand Up @@ -130,9 +130,11 @@ parse_args() {

require_version_arg() {
if [ "$VERSION" = "" ]; then
warn "Missing argument <version>"
usage
exit 1
default_suggestion="$(git_next_revision_version)"
printf "Version number for this hotfix: [$default_suggestion] "
read answer
VERSION=${answer:-$default_suggestion}
BRANCH=$PREFIX$VERSION
fi
}

Expand Down
8 changes: 5 additions & 3 deletions git-flow-release
Expand Up @@ -127,9 +127,11 @@ parse_args() {

require_version_arg() {
if [ "$VERSION" = "" ]; then
warn "Missing argument <version>"
usage
exit 1
default_suggestion="$(git_next_minor_version)"
printf "Version number for this release: [$default_suggestion] "
read answer
VERSION=${answer:-$default_suggestion}
BRANCH=$PREFIX$VERSION
fi
}

Expand Down
54 changes: 54 additions & 0 deletions gitflow-common
Expand Up @@ -105,6 +105,7 @@ git_tag_exists() {
has $1 $(git_all_tags)
}


#
# git_compare_branches()
#
Expand Down Expand Up @@ -312,3 +313,56 @@ require_branches_equal() {
fi
fi
}

#
# Functions for auto version incrementing
#

git_current_version() {
echo "$(git_all_tags)" | grep -e '.*[0-9]*\.[0-9]*\.[0-9].*' | sed '$!d' | sed -n 's/[^0-9]*\([0-9]*.[0-9]*.[0-9]\)/\1/p'
}

git_current_major_version() {
echo "$(git_current_version)" | sed -n 's/\([0-9]*\).[0-9]*.[0-9]*/\1/p'
}

git_current_minor_version() {
echo "$(git_current_version)" | sed -n 's/[0-9]*.\([0-9]*\).[0-9]*/\1/p'
}

git_current_revision_version() {
echo "$(git_current_version)" | sed -n 's/[0-9]*.[0-9]*.\([0-9]*\)/\1/p'
}

git_next_major_version() {
if [ $(git_current_version) == ""]; then
echo "1.0.0"
else
maj=$( echo "$(git_current_major_version)" | awk '{ print $1 + 1 }' )
min=0
rev=0
echo "$maj.$min.$rev"
fi
}

git_next_minor_version() {
if [ $(git_current_version) == ""]; then
echo "1.0.0"
else
maj=$(git_current_major_version)
min=$( echo "$(git_current_minor_version)" | awk '{ print $1 + 1 }' )
rev=0
echo "$maj.$min.$rev"
fi
}

git_next_revision_version() {
if [ $(git_current_version) == "" ]; then
echo "1.0.0"
else
maj=$(git_current_major_version)
min=$(git_current_minor_version)
rev=$( echo "$(git_current_revision_version)" | awk '{ print $1 + 1 }' )
echo "$maj.$min.$rev"
fi
}

1 comment on commit fcfecc4

@jcftang
Copy link

Choose a reason for hiding this comment

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

+1 for this as well, though I kinda also like the idea of using "epochs" or something like that, there are times when I just want to do regular releases using the year+month+day+hour+min as a version number.

Please sign in to comment.