Skip to content

Commit

Permalink
Made the finishing of release/hotfix branches fail-safe. When a
Browse files Browse the repository at this point in the history
release/hotfix branch fails finishing, the user may just try so again.
  • Loading branch information
nvie committed Feb 8, 2010
1 parent 1a2868b commit 5fa4758
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 33 deletions.
51 changes: 35 additions & 16 deletions git-flow-hotfix
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,41 @@ cmd_finish() {
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH

# merge into master
git checkout $MASTER_BRANCH || \
die "Could not check out $MASTER_BRANCH."
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
git checkout $DEVELOP_BRANCH || \
die "Could not check out $DEVELOP_BRANCH."
git merge --no-ff $BRANCH # TODO: This can fail!
# try to merge into master
# in case a previous attempt to finish this release branch has failed,
# but the merge into master was successful, we skip it now
if ! gitflow_is_branch_merged_into $BRANCH $MASTER_BRANCH; then
git checkout $MASTER_BRANCH || \
die "Could not check out $MASTER_BRANCH."
git merge --no-ff $BRANCH || \
die "There were merge conflicts."
# TODO: What do we do now?
fi

# try to tag the release
# in case a previous attempt to finish this release branch has failed,
# but the tag was set successful, we skip it now
typeset tagname=$VERSION_PREFIX$VERSION
if ! gitflow_tag_exists $tagname; then
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."
fi

# try to merge into develop
# in case a previous attempt to finish this release branch has failed,
# but the merge into develop was successful, we skip it now
if ! gitflow_is_branch_merged_into $BRANCH $DEVELOP_BRANCH; then
git checkout $DEVELOP_BRANCH || \
die "Could not check out $DEVELOP_BRANCH."

git merge --no-ff $BRANCH || \
die "There were merge conflicts."
# TODO: What do we do now?
fi

# delete branch
git branch -d $BRANCH
Expand Down
52 changes: 35 additions & 17 deletions git-flow-release
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,40 @@ cmd_finish() {
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH

# merge into master
git checkout $MASTER_BRANCH || \
die "Could not check out $MASTER_BRANCH."
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
git checkout $DEVELOP_BRANCH || \
die "Could not check out $DEVELOP_BRANCH."
git merge --no-ff $BRANCH # TODO: This can fail!
# try to merge into master
# in case a previous attempt to finish this release branch has failed,
# but the merge into master was successful, we skip it now
if ! gitflow_is_branch_merged_into $BRANCH $MASTER_BRANCH; then
git checkout $MASTER_BRANCH || \
die "Could not check out $MASTER_BRANCH."
git merge --no-ff $BRANCH || \
die "There were merge conflicts."
# TODO: What do we do now?
fi

# try to tag the release
# in case a previous attempt to finish this release branch has failed,
# but the tag was set successful, we skip it now
typeset tagname=$VERSION_PREFIX$VERSION
if ! gitflow_tag_exists $tagname; then
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 "$tagname" || \
die "Tagging failed. Please run finish again to retry."
fi

# try to merge into develop
# in case a previous attempt to finish this release branch has failed,
# but the merge into develop was successful, we skip it now
if ! gitflow_is_branch_merged_into $BRANCH $DEVELOP_BRANCH; then
git checkout $DEVELOP_BRANCH || \
die "Could not check out $DEVELOP_BRANCH."
git merge --no-ff $BRANCH || \
die "There were merge conflicts."
# TODO: What do we do now?
fi

# delete branch
git branch -d $BRANCH
Expand All @@ -203,7 +221,7 @@ cmd_finish() {
echo "Summary of actions:"
echo "- Latest objects have been fetched from '$ORIGIN'"
echo "- Release branch has been merged into '$MASTER_BRANCH'"
echo "- The release was tagged '$VERSION_PREFIX$VERSION'"
echo "- The release was tagged '$tagname'"
echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
echo "- Release branch '$BRANCH' has been deleted"
echo
Expand Down
4 changes: 4 additions & 0 deletions gitflow-common
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ gitflow_require_tag_absent() {
fi
}

gitflow_tag_exists() {
has $1 $ALL_TAGS
}

#
# gitflow_test_branches_equal()
#
Expand Down

0 comments on commit 5fa4758

Please sign in to comment.