Commit 1a2868b8 authored by Vincent Driessen's avatar Vincent Driessen

Add tag annotation and tag signing to both release and hotfix.

Require branch and tag to be absent when start is run (for release/hotfix)

Require branch to exist when trying to finish (for release/hotfix)

Die the finish script when either the fetch, checkout or tagging fails.
parent ca73caf8
...@@ -113,7 +113,7 @@ require_base_is_on_master() { ...@@ -113,7 +113,7 @@ require_base_is_on_master() {
} }
cmd_start() { cmd_start() {
DEFINE_boolean fetch true "fetch from $ORIGIN before finishing hotfix" F DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
parse_args "$@" parse_args "$@"
BASE="${2:-$MASTER_BRANCH}" BASE="${2:-$MASTER_BRANCH}"
require_version_arg require_version_arg
...@@ -121,11 +121,12 @@ cmd_start() { ...@@ -121,11 +121,12 @@ cmd_start() {
# sanity checks # sanity checks
gitflow_require_clean_working_tree gitflow_require_clean_working_tree
gitflow_require_branch_absent $BRANCH
gitflow_require_tag_absent $VERSION_PREFIX$VERSION
if flag fetch; then if flag fetch; then
git fetch -q $ORIGIN $MASTER_BRANCH git fetch -q $ORIGIN $MASTER_BRANCH
fi fi
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
gitflow_require_branch_absent $BRANCH
# create branch # create branch
git checkout -b $BRANCH $BASE git checkout -b $BRANCH $BASE
...@@ -145,27 +146,46 @@ cmd_start() { ...@@ -145,27 +146,46 @@ cmd_start() {
} }
cmd_finish() { cmd_finish() {
DEFINE_boolean fetch true "fetch from $ORIGIN before finishing hotfix" F DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
DEFINE_boolean sign false "sign the release tag cryptographically" s
DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u
DEFINE_string message "" "use the given tag message" m
parse_args "$@" parse_args "$@"
require_version_arg require_version_arg
# handle flags that imply other flags
if [ "$FLAGS_signingkey" != "" ]; then
FLAGS_sign=$FLAGS_TRUE
fi
# sanity checks # sanity checks
gitflow_require_branch $BRANCH
gitflow_require_clean_working_tree gitflow_require_clean_working_tree
if flag fetch; then if flag fetch; then
git fetch -q $ORIGIN $MASTER_BRANCH git fetch -q $ORIGIN $MASTER_BRANCH || \
git fetch -q $ORIGIN $DEVELOP_BRANCH die "Could not fetch $MASTER_BRANCH from $ORIGIN."
git fetch -q $ORIGIN $DEVELOP_BRANCH || \
die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
fi fi
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
# merge into master # merge into master
git checkout $MASTER_BRANCH git checkout $MASTER_BRANCH || \
git merge --no-ff $BRANCH die "Could not check out $MASTER_BRANCH."
git tag $VERSION_PREFIX$VERSION git merge --no-ff $BRANCH # TODO: This can fail!
# merge into develop if we fixed a master issue typeset opts="-a"
git checkout $DEVELOP_BRANCH flag sign && opts="$opts -s"
git merge --no-ff $BRANCH [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
[ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
git tag $opts "$VERSION_PREFIX$VERSION" || \
die "Tagging failed. Please run finish again to retry."
# merge into develop
git checkout $DEVELOP_BRANCH || \
die "Could not check out $DEVELOP_BRANCH."
git merge --no-ff $BRANCH # TODO: This can fail!
# delete branch # delete branch
git branch -d $BRANCH git branch -d $BRANCH
......
...@@ -127,11 +127,12 @@ cmd_start() { ...@@ -127,11 +127,12 @@ cmd_start() {
# sanity checks # sanity checks
gitflow_require_clean_working_tree gitflow_require_clean_working_tree
gitflow_require_branch_absent $BRANCH
gitflow_require_tag_absent $VERSION_PREFIX$VERSION
if flag fetch; then if flag fetch; then
git fetch -q $ORIGIN $DEVELOP_BRANCH git fetch -q $ORIGIN $DEVELOP_BRANCH
fi fi
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
gitflow_require_branch_absent $BRANCH
# create branch # create branch
git checkout -b $BRANCH $BASE git checkout -b $BRANCH $BASE
...@@ -152,26 +153,45 @@ cmd_start() { ...@@ -152,26 +153,45 @@ cmd_start() {
cmd_finish() { cmd_finish() {
DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
DEFINE_boolean sign false "sign the release tag cryptographically" s
DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u
DEFINE_string message "" "use the given tag message" m
parse_args "$@" parse_args "$@"
require_version_arg require_version_arg
# handle flags that imply other flags
if [ "$FLAGS_signingkey" != "" ]; then
FLAGS_sign=$FLAGS_TRUE
fi
# sanity checks # sanity checks
gitflow_require_branch $BRANCH
gitflow_require_clean_working_tree gitflow_require_clean_working_tree
if flag fetch; then if flag fetch; then
git fetch -q $ORIGIN $MASTER_BRANCH git fetch -q $ORIGIN $MASTER_BRANCH || \
git fetch -q $ORIGIN $DEVELOP_BRANCH die "Could not fetch $MASTER_BRANCH from $ORIGIN."
git fetch -q $ORIGIN $DEVELOP_BRANCH || \
die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
fi fi
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
# merge into master # merge into master
git checkout $MASTER_BRANCH git checkout $MASTER_BRANCH || \
git merge --no-ff $BRANCH die "Could not check out $MASTER_BRANCH."
git tag $VERSION_PREFIX$VERSION git merge --no-ff $BRANCH # TODO: This can fail!
typeset opts="-a"
flag sign && opts="$opts -s"
[ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
[ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
git tag $opts "$VERSION_PREFIX$VERSION" || \
die "Tagging failed. Please run finish again to retry."
# merge into develop # merge into develop
git checkout $DEVELOP_BRANCH git checkout $DEVELOP_BRANCH || \
git merge --no-ff $BRANCH die "Could not check out $DEVELOP_BRANCH."
git merge --no-ff $BRANCH # TODO: This can fail!
# delete branch # delete branch
git branch -d $BRANCH git branch -d $BRANCH
......
...@@ -42,6 +42,7 @@ noflag() { typeset FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; } ...@@ -42,6 +42,7 @@ noflag() { typeset FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; }
LOCAL_BRANCHES=$(git branch | sed 's/^[* ] //') LOCAL_BRANCHES=$(git branch | sed 's/^[* ] //')
REMOTE_BRANCHES=$(git branch -r | sed 's/^[* ] //') REMOTE_BRANCHES=$(git branch -r | sed 's/^[* ] //')
ALL_BRANCHES="$LOCAL_BRANCHES $REMOTE_BRANCHES" ALL_BRANCHES="$LOCAL_BRANCHES $REMOTE_BRANCHES"
ALL_TAGS=$(git tag)
# #
# resolve_nameprefix # resolve_nameprefix
...@@ -141,6 +142,12 @@ gitflow_require_branch_absent() { ...@@ -141,6 +142,12 @@ gitflow_require_branch_absent() {
fi fi
} }
gitflow_require_tag_absent() {
if has $1 $ALL_TAGS; then
die "Tag '$1' already exists. Pick another name."
fi
}
# #
# gitflow_test_branches_equal() # gitflow_test_branches_equal()
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment