Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version number auto-increment support. #129

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ debian/files
debian/*.substvars debian/*.substvars
debian/*.debhelper.log debian/*.debhelper.log
debian/*/* debian/*/*
*.swp
27 changes: 22 additions & 5 deletions git-flow-hotfix
Expand Up @@ -130,9 +130,22 @@ parse_args() {


require_version_arg() { require_version_arg() {
if [ "$VERSION" = "" ]; then if [ "$VERSION" = "" ]; then
warn "Missing argument <version>" default_suggestion="$(git_next_revision_version)"
usage printf "Version number for this hotfix: [$default_suggestion] "
exit 1 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 fi
} }


Expand Down Expand Up @@ -197,7 +210,7 @@ cmd_finish() {
DEFINE_boolean keep false "keep branch after performing finish" k DEFINE_boolean keep false "keep branch after performing finish" k
DEFINE_boolean notag false "don't tag this release" n DEFINE_boolean notag false "don't tag this release" n
parse_args "$@" parse_args "$@"
require_version_arg require_version_arg_for_finish


# handle flags that imply other flags # handle flags that imply other flags
if [ "$FLAGS_signingkey" != "" ]; then if [ "$FLAGS_signingkey" != "" ]; then
Expand Down Expand Up @@ -240,7 +253,11 @@ cmd_finish() {
local opts="-a" local opts="-a"
flag sign && opts="$opts -s" flag sign && opts="$opts -s"
[ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'" [ "$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" || \ git tag $opts "$VERSION_PREFIX$VERSION" || \
die "Tagging failed. Please run finish again to retry." die "Tagging failed. Please run finish again to retry."
fi fi
Expand Down
27 changes: 22 additions & 5 deletions git-flow-release
Expand Up @@ -127,9 +127,22 @@ parse_args() {


require_version_arg() { require_version_arg() {
if [ "$VERSION" = "" ]; then if [ "$VERSION" = "" ]; then
warn "Missing argument <version>" default_suggestion="$(git_next_minor_version)"
usage printf "Version number for this release: [$default_suggestion] "
exit 1 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 fi
} }


Expand Down Expand Up @@ -195,7 +208,7 @@ cmd_finish() {
DEFINE_boolean notag false "don't tag this release" n DEFINE_boolean notag false "don't tag this release" n


parse_args "$@" parse_args "$@"
require_version_arg require_version_arg_for_finish


# handle flags that imply other flags # handle flags that imply other flags
if [ "$FLAGS_signingkey" != "" ]; then if [ "$FLAGS_signingkey" != "" ]; then
Expand Down Expand Up @@ -238,7 +251,11 @@ cmd_finish() {
local opts="-a" local opts="-a"
flag sign && opts="$opts -s" flag sign && opts="$opts -s"
[ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'" [ "$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" || \ git tag $opts "$tagname" || \
die "Tagging failed. Please run finish again to retry." die "Tagging failed. Please run finish again to retry."
fi fi
Expand Down
60 changes: 60 additions & 0 deletions gitflow-common
Expand Up @@ -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_branches() { ( git branch --no-color; git branch -r --no-color) | sed 's/^[* ] //'; }
git_all_tags() { git tag; } 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_current_branch() {
git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g' git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g'
} }
Expand Down Expand Up @@ -105,6 +107,7 @@ git_tag_exists() {
has $1 $(git_all_tags) has $1 $(git_all_tags)
} }



# #
# git_compare_branches() # git_compare_branches()
# #
Expand Down Expand Up @@ -312,3 +315,60 @@ require_branches_equal() {
fi fi
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
}