Permalink
Browse files

Add version number auto-increment support.

'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...
1 parent 14bcc58 commit fcfecc450c69b312c677ac9a08f6dd8a69d8c069 Nickolas Means committed May 24, 2011
Showing with 64 additions and 6 deletions.
  1. +5 −3 git-flow-hotfix
  2. +5 −3 git-flow-release
  3. +54 −0 gitflow-common
View
@@ -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
}
View
@@ -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
}
View
@@ -105,6 +105,7 @@ git_tag_exists() {
has $1 $(git_all_tags)
}
+
#
# git_compare_branches()
#
@@ -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

+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.