From fcfecc450c69b312c677ac9a08f6dd8a69d8c069 Mon Sep 17 00:00:00 2001 From: Nickolas Means Date: Tue, 24 May 2011 16:44:12 -0500 Subject: [PATCH 1/5] 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. --- git-flow-hotfix | 8 ++++--- git-flow-release | 8 ++++--- gitflow-common | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/git-flow-hotfix b/git-flow-hotfix index 261811317..7e5a170a4 100644 --- a/git-flow-hotfix +++ b/git-flow-hotfix @@ -130,9 +130,11 @@ parse_args() { require_version_arg() { if [ "$VERSION" = "" ]; then - warn "Missing argument " - 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 } diff --git a/git-flow-release b/git-flow-release index 08f595b2f..31a0eb2d2 100644 --- a/git-flow-release +++ b/git-flow-release @@ -127,9 +127,11 @@ parse_args() { require_version_arg() { if [ "$VERSION" = "" ]; then - warn "Missing argument " - 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 } diff --git a/gitflow-common b/gitflow-common index 252f5d0ea..1f6b35cd6 100644 --- a/gitflow-common +++ b/gitflow-common @@ -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 +} From c48e24078e576acdc43a7127a8cf088389aea3a9 Mon Sep 17 00:00:00 2001 From: Nickolas Means Date: Wed, 25 May 2011 11:38:41 -0500 Subject: [PATCH 2/5] Sort tags by date. --- gitflow-common | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitflow-common b/gitflow-common index 1f6b35cd6..0b3d0e9f4 100644 --- a/gitflow-common +++ b/gitflow-common @@ -75,6 +75,8 @@ git_remote_branches() { git branch -r --no-color | sed 's/^[* ] //'; } git_all_branches() { ( git branch --no-color; git branch -r --no-color) | sed 's/^[* ] //'; } git_all_tags() { git tag; } +git_all_tags_by_date() { git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags; } + git_current_branch() { git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g' } @@ -319,7 +321,7 @@ require_branches_equal() { # 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' + echo "$(git_all_tags_by_date)" | 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() { From 79d1a15d3b2e128bfee06fc4d57c6054a5276c3d Mon Sep 17 00:00:00 2001 From: Nickolas Means Date: Wed, 25 May 2011 12:02:53 -0500 Subject: [PATCH 3/5] Change tag sort and auto-annotate created tags. Tag sort is now done by date on the tag, not alpha. This should ensure we're always looking at the latest tag when incrementing version number while remaining much simpler than a version sort. Tags that are created by feature finish and hotfix finish are now auto-annotated with the version number. This can still be overridden by adding a -m flag with message to the finish call, but avoids an unnecessary interruption since the actual tag message is mostly worthless, but we have to have it to get author and date metadata. --- .gitignore | 1 + git-flow-hotfix | 6 +++++- git-flow-release | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8d038485f..43d27d221 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ debian/files debian/*.substvars debian/*.debhelper.log debian/*/* +*.swp diff --git a/git-flow-hotfix b/git-flow-hotfix index 7e5a170a4..32dd3b332 100644 --- a/git-flow-hotfix +++ b/git-flow-hotfix @@ -242,7 +242,11 @@ cmd_finish() { local opts="-a" flag sign && opts="$opts -s" [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'" - [ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'" + if [ "$FLAGS_message" != "" ]; then + opts="$opts -m '$FLAGS_message'" + else + opts="$opts -m '$VERSION_PREFIX$VERSION'" + fi git tag $opts "$VERSION_PREFIX$VERSION" || \ die "Tagging failed. Please run finish again to retry." fi diff --git a/git-flow-release b/git-flow-release index 31a0eb2d2..e67dff5c0 100644 --- a/git-flow-release +++ b/git-flow-release @@ -240,7 +240,11 @@ cmd_finish() { local opts="-a" flag sign && opts="$opts -s" [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'" - [ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'" + if [ "$FLAGS_message" != "" ]; then + opts="$opts -m '$FLAGS_message'" + else + opts="$opts -m '$VERSION_PREFIX$VERSION'" + fi git tag $opts "$tagname" || \ die "Tagging failed. Please run finish again to retry." fi From bba9408473bf2a1a2cedb895112a15f57aad4188 Mon Sep 17 00:00:00 2001 From: Nickolas Means Date: Thu, 26 May 2011 16:44:47 -0500 Subject: [PATCH 4/5] Fix a few bugs present in no-tags-present scenario. --- gitflow-common | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gitflow-common b/gitflow-common index 0b3d0e9f4..eecb915b2 100644 --- a/gitflow-common +++ b/gitflow-common @@ -75,7 +75,7 @@ git_remote_branches() { git branch -r --no-color | sed 's/^[* ] //'; } git_all_branches() { ( git branch --no-color; git branch -r --no-color) | sed 's/^[* ] //'; } git_all_tags() { git tag; } -git_all_tags_by_date() { git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags; } +git_all_tags_by_date() { git for-each-ref --sort='*authordate' --format='%(refname:short)' refs/tags; } git_current_branch() { git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g' @@ -321,7 +321,7 @@ require_branches_equal() { # git_current_version() { - echo "$(git_all_tags_by_date)" | grep -e '.*[0-9]*\.[0-9]*\.[0-9].*' | sed '$!d' | sed -n 's/[^0-9]*\([0-9]*.[0-9]*.[0-9]\)/\1/p' + echo "$(git_all_tags_by_date)" | grep -e '.*[0-9]*\.[0-9]*\.[0-9].*' | sed '$!d' | sed -n 's/[^0-9]*\([0-9]*.[0-9]*.[0-9]\)[^0-9]*/\1/p' } git_current_major_version() { @@ -337,7 +337,7 @@ git_current_revision_version() { } git_next_major_version() { - if [ $(git_current_version) == ""]; then + if [ -z $(git_current_version) ]; then echo "1.0.0" else maj=$( echo "$(git_current_major_version)" | awk '{ print $1 + 1 }' ) @@ -348,7 +348,7 @@ git_next_major_version() { } git_next_minor_version() { - if [ $(git_current_version) == ""]; then + if [ -z $(git_current_version) ]; then echo "1.0.0" else maj=$(git_current_major_version) @@ -359,7 +359,7 @@ git_next_minor_version() { } git_next_revision_version() { - if [ $(git_current_version) == "" ]; then + if [ -z $(git_current_version) ]; then echo "1.0.0" else maj=$(git_current_major_version) From c81941fffcf0361ddfa2757b2f275d6caaa65b13 Mon Sep 17 00:00:00 2001 From: Nickolas Means Date: Fri, 27 May 2011 10:16:53 -0500 Subject: [PATCH 5/5] Get our finish version number guess from branch. Previous versions attempted to guess version number on finish based on version number auto-incrementation. It's more intuitive to guess based on current branch on finish as that honors a user override of default version number incrementation on release or hotfix start. --- git-flow-hotfix | 13 ++++++++++++- git-flow-release | 13 ++++++++++++- gitflow-common | 4 ++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/git-flow-hotfix b/git-flow-hotfix index 32dd3b332..f5d2f9df6 100644 --- a/git-flow-hotfix +++ b/git-flow-hotfix @@ -138,6 +138,17 @@ require_version_arg() { fi } +require_version_arg_for_finish() { + if [ "$VERSION" = "" ]; then + default_suggestion="$(gitflow_current_version_from_branch_name)" + printf "Version number for this release: [$default_suggestion] " + read answer + VERSION=${answer:-$default_suggestion} + BRANCH=$PREFIX$VERSION + require_branch $BRANCH + fi +} + require_base_is_on_master() { if ! git branch --no-color --contains "$BASE" 2>/dev/null \ | sed 's/[* ] //g' \ @@ -199,7 +210,7 @@ cmd_finish() { DEFINE_boolean keep false "keep branch after performing finish" k DEFINE_boolean notag false "don't tag this release" n parse_args "$@" - require_version_arg + require_version_arg_for_finish # handle flags that imply other flags if [ "$FLAGS_signingkey" != "" ]; then diff --git a/git-flow-release b/git-flow-release index e67dff5c0..71fbd4749 100644 --- a/git-flow-release +++ b/git-flow-release @@ -135,6 +135,17 @@ require_version_arg() { fi } +require_version_arg_for_finish() { + if [ "$VERSION" = "" ]; then + default_suggestion="$(gitflow_current_version_from_branch_name)" + printf "Version number for this release: [$default_suggestion] " + read answer + VERSION=${answer:-$default_suggestion} + BRANCH=$PREFIX$VERSION + require_branch $BRANCH + fi +} + require_base_is_on_develop() { if ! git branch --no-color --contains "$BASE" 2>/dev/null \ | sed 's/[* ] //g' \ @@ -197,7 +208,7 @@ cmd_finish() { DEFINE_boolean notag false "don't tag this release" n parse_args "$@" - require_version_arg + require_version_arg_for_finish # handle flags that imply other flags if [ "$FLAGS_signingkey" != "" ]; then diff --git a/gitflow-common b/gitflow-common index eecb915b2..3a502c5ed 100644 --- a/gitflow-common +++ b/gitflow-common @@ -320,6 +320,10 @@ require_branches_equal() { # Functions for auto version incrementing # +gitflow_current_version_from_branch_name() { + echo "$(git_current_branch)" | sed 's/.*\/\(.*\)/\1/g' +} + git_current_version() { echo "$(git_all_tags_by_date)" | grep -e '.*[0-9]*\.[0-9]*\.[0-9].*' | sed '$!d' | sed -n 's/[^0-9]*\([0-9]*.[0-9]*.[0-9]\)[^0-9]*/\1/p' }