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 261811317..f5d2f9df6 100644 --- a/git-flow-hotfix +++ b/git-flow-hotfix @@ -130,9 +130,22 @@ 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 +} + +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 } @@ -197,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 @@ -240,7 +253,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 08f595b2f..71fbd4749 100644 --- a/git-flow-release +++ b/git-flow-release @@ -127,9 +127,22 @@ 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 +} + +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 } @@ -195,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 @@ -238,7 +251,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 diff --git a/gitflow-common b/gitflow-common index 252f5d0ea..3a502c5ed 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='%(refname:short)' refs/tags; } + git_current_branch() { git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g' } @@ -105,6 +107,7 @@ git_tag_exists() { has $1 $(git_all_tags) } + # # git_compare_branches() # @@ -312,3 +315,60 @@ require_branches_equal() { fi fi } + +# +# 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' +} + +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 [ -z $(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 [ -z $(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 [ -z $(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 +}