2010-01-21 00:36:44 +00:00
|
|
|
#
|
2010-01-26 21:18:36 +00:00
|
|
|
# git-flow -- A collection of Git extensions to provide high-level
|
|
|
|
# repository operations for Vincent Driessen's branching model.
|
2010-01-26 11:39:36 +00:00
|
|
|
#
|
2010-01-21 00:36:44 +00:00
|
|
|
# Original blog post presenting this model is found at:
|
2010-07-09 07:42:09 +00:00
|
|
|
# http://nvie.com/git-model
|
2010-01-26 11:39:36 +00:00
|
|
|
#
|
2010-01-21 00:36:44 +00:00
|
|
|
# Feel free to contribute to this project at:
|
|
|
|
# http://github.com/nvie/gitflow
|
|
|
|
#
|
2010-04-04 14:10:17 +00:00
|
|
|
# Copyright 2010 Vincent Driessen. All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions and the following disclaimer.
|
|
|
|
#
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
|
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
|
|
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# The views and conclusions contained in the software and documentation are
|
|
|
|
# those of the authors and should not be interpreted as representing official
|
|
|
|
# policies, either expressed or implied, of Vincent Driessen.
|
2010-01-21 00:36:44 +00:00
|
|
|
#
|
2010-01-21 00:32:18 +00:00
|
|
|
|
2010-02-21 20:31:03 +00:00
|
|
|
require_git_repo
|
|
|
|
require_gitflow_initialized
|
2010-02-16 20:33:51 +00:00
|
|
|
gitflow_load_settings
|
2010-01-27 23:51:15 +00:00
|
|
|
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
|
2010-02-20 15:52:48 +00:00
|
|
|
PREFIX=$(git config --get gitflow.prefix.release)
|
2010-01-27 23:51:15 +00:00
|
|
|
|
2010-01-21 00:32:18 +00:00
|
|
|
usage() {
|
2010-02-04 10:30:18 +00:00
|
|
|
echo "usage: git flow release [list] [-v]"
|
2010-02-24 00:37:07 +00:00
|
|
|
echo " git flow release start [-F] <version>"
|
|
|
|
echo " git flow release finish [-Fsump] <version>"
|
2010-01-21 00:32:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 23:20:51 +00:00
|
|
|
cmd_default() {
|
2010-01-28 00:01:53 +00:00
|
|
|
cmd_list "$@"
|
2010-01-26 11:39:36 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 00:01:53 +00:00
|
|
|
cmd_list() {
|
2010-02-04 10:30:18 +00:00
|
|
|
DEFINE_boolean verbose false 'verbose (more) output' v
|
|
|
|
parse_args "$@"
|
|
|
|
|
2010-02-15 22:01:52 +00:00
|
|
|
local release_branches
|
|
|
|
local current_branch
|
|
|
|
local short_names
|
2010-02-21 20:31:03 +00:00
|
|
|
release_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
|
2010-02-06 13:45:39 +00:00
|
|
|
if [ -z "$release_branches" ]; then
|
2010-01-27 23:20:51 +00:00
|
|
|
warn "No release branches exist."
|
2010-06-26 05:14:15 +00:00
|
|
|
warn ""
|
|
|
|
warn "You can start a new release branch:"
|
|
|
|
warn ""
|
|
|
|
warn " git flow release start <name> [<base>]"
|
2010-06-26 05:19:06 +00:00
|
|
|
warn ""
|
2010-01-27 23:20:51 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2010-02-04 10:30:18 +00:00
|
|
|
|
2010-02-06 13:45:39 +00:00
|
|
|
current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
|
2010-02-09 23:43:21 +00:00
|
|
|
short_names=$(echo "$release_branches" | sed "s ^$PREFIX g")
|
2010-02-06 13:45:39 +00:00
|
|
|
|
2010-02-04 10:30:18 +00:00
|
|
|
# determine column width first
|
2010-02-15 22:01:52 +00:00
|
|
|
local width=0
|
|
|
|
local branch
|
2010-02-06 13:45:39 +00:00
|
|
|
for branch in $short_names; do
|
2010-02-15 22:01:52 +00:00
|
|
|
local len=${#branch}
|
2010-02-04 10:30:18 +00:00
|
|
|
width=$(max $width $len)
|
|
|
|
done
|
2010-02-15 22:01:52 +00:00
|
|
|
width=$(($width+3))
|
2010-02-04 10:30:18 +00:00
|
|
|
|
2010-02-15 22:01:52 +00:00
|
|
|
local branch
|
2010-02-06 13:45:39 +00:00
|
|
|
for branch in $short_names; do
|
2010-02-15 22:01:52 +00:00
|
|
|
local fullname=$PREFIX$branch
|
|
|
|
local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
|
|
|
|
local develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
|
|
|
|
local branch_sha=$(git rev-parse "$fullname")
|
2010-02-06 13:45:39 +00:00
|
|
|
if [ "$fullname" = "$current_branch" ]; then
|
2010-02-04 10:30:18 +00:00
|
|
|
printf "* "
|
|
|
|
else
|
|
|
|
printf " "
|
|
|
|
fi
|
|
|
|
if flag verbose; then
|
|
|
|
printf "%-${width}s" "$branch"
|
|
|
|
if [ "$branch_sha" = "$develop_sha" ]; then
|
|
|
|
printf "(no commits yet)"
|
|
|
|
else
|
2010-02-15 22:01:52 +00:00
|
|
|
local nicename=$(git rev-parse --short "$base")
|
2010-02-04 10:30:18 +00:00
|
|
|
printf "(based on $nicename)"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
printf "%s" "$branch"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
done
|
2010-01-27 23:20:51 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
cmd_help() {
|
|
|
|
usage
|
|
|
|
exit 0
|
2010-01-21 00:32:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 00:01:53 +00:00
|
|
|
parse_args() {
|
2010-02-04 10:30:18 +00:00
|
|
|
# parse options
|
|
|
|
FLAGS "$@" || exit $?
|
|
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
|
|
|
|
# read arguments into global variables
|
2010-02-09 23:18:08 +00:00
|
|
|
VERSION=$1
|
|
|
|
BRANCH=$PREFIX$VERSION
|
2010-02-04 10:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require_version_arg() {
|
2010-01-28 00:01:53 +00:00
|
|
|
if [ "$VERSION" = "" ]; then
|
2010-02-04 10:30:18 +00:00
|
|
|
warn "Missing argument <version>"
|
2010-01-28 00:01:53 +00:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-02-04 09:31:29 +00:00
|
|
|
require_base_is_on_develop() {
|
|
|
|
if ! git branch --contains "$BASE" 2>/dev/null \
|
|
|
|
| sed 's/[* ] //g' \
|
|
|
|
| grep -q "^$DEVELOP_BRANCH\$"; then
|
|
|
|
die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-02-16 05:41:13 +00:00
|
|
|
require_no_existing_release_branches() {
|
2010-02-21 20:31:03 +00:00
|
|
|
local release_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
|
2010-02-16 05:41:13 +00:00
|
|
|
local first_branch=$(echo ${release_branches} | head -n1)
|
|
|
|
first_branch=${first_branch#$PREFIX}
|
|
|
|
[ -z "$release_branches" ] || \
|
|
|
|
die "There is an existing release branch ($first_branch). Finish that one first."
|
|
|
|
}
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
cmd_start() {
|
2010-07-22 13:11:17 +00:00
|
|
|
DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
|
2010-01-21 00:32:18 +00:00
|
|
|
parse_args "$@"
|
2010-02-09 23:18:08 +00:00
|
|
|
BASE=${2:-$DEVELOP_BRANCH}
|
2010-02-04 10:30:18 +00:00
|
|
|
require_version_arg
|
2010-02-04 09:31:29 +00:00
|
|
|
require_base_is_on_develop
|
2010-02-16 05:41:13 +00:00
|
|
|
require_no_existing_release_branches
|
2010-01-25 21:16:08 +00:00
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
# sanity checks
|
2010-02-21 20:31:03 +00:00
|
|
|
require_clean_working_tree
|
|
|
|
require_branch_absent "$BRANCH"
|
|
|
|
require_tag_absent "$VERSION_PREFIX$VERSION"
|
2010-02-07 18:46:38 +00:00
|
|
|
if flag fetch; then
|
2010-02-09 23:34:59 +00:00
|
|
|
git fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
|
2010-01-29 11:37:22 +00:00
|
|
|
fi
|
2010-07-22 13:11:17 +00:00
|
|
|
if has "$ORIGIN/$DEVELOP_BRANCH" "$(git_remote_branches)"; then
|
|
|
|
require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
|
|
|
|
fi
|
2010-01-25 21:16:08 +00:00
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
# create branch
|
2010-02-09 23:34:59 +00:00
|
|
|
git checkout -b "$BRANCH" "$BASE"
|
2010-01-26 00:15:51 +00:00
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
echo
|
2010-01-26 00:15:51 +00:00
|
|
|
echo "Summary of actions:"
|
2010-02-04 09:31:29 +00:00
|
|
|
echo "- A new branch '$BRANCH' was created, based on '$BASE'"
|
2010-01-26 11:39:36 +00:00
|
|
|
echo "- You are now on branch '$BRANCH'"
|
|
|
|
echo
|
2010-01-26 00:15:51 +00:00
|
|
|
echo "Follow-up actions:"
|
|
|
|
echo "- Bump the version number now!"
|
|
|
|
echo "- Start committing last-minute fixes in preparing your release"
|
|
|
|
echo "- When done, run:"
|
2010-01-26 11:39:36 +00:00
|
|
|
echo
|
2010-02-04 09:31:29 +00:00
|
|
|
echo " git flow release finish '$VERSION'"
|
2010-01-26 11:39:36 +00:00
|
|
|
echo
|
2010-01-21 00:32:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
cmd_finish() {
|
2010-07-22 13:11:17 +00:00
|
|
|
DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
|
2010-02-07 22:23:16 +00:00
|
|
|
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
|
2010-02-19 05:42:18 +00:00
|
|
|
DEFINE_boolean push false "push to $ORIGIN after performing finish" p
|
2010-02-19 04:57:08 +00:00
|
|
|
|
2010-01-21 00:32:18 +00:00
|
|
|
parse_args "$@"
|
2010-02-04 10:30:18 +00:00
|
|
|
require_version_arg
|
2010-01-25 21:16:08 +00:00
|
|
|
|
2010-02-07 22:23:16 +00:00
|
|
|
# handle flags that imply other flags
|
|
|
|
if [ "$FLAGS_signingkey" != "" ]; then
|
|
|
|
FLAGS_sign=$FLAGS_TRUE
|
|
|
|
fi
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
# sanity checks
|
2010-02-21 20:31:03 +00:00
|
|
|
require_branch "$BRANCH"
|
|
|
|
require_clean_working_tree
|
2010-02-07 18:46:38 +00:00
|
|
|
if flag fetch; then
|
2010-02-09 23:34:59 +00:00
|
|
|
git fetch -q "$ORIGIN" "$MASTER_BRANCH" || \
|
2010-02-07 22:23:16 +00:00
|
|
|
die "Could not fetch $MASTER_BRANCH from $ORIGIN."
|
2010-02-09 23:34:59 +00:00
|
|
|
git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" || \
|
2010-02-07 22:23:16 +00:00
|
|
|
die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
|
2010-01-29 11:37:22 +00:00
|
|
|
fi
|
2010-07-22 13:11:17 +00:00
|
|
|
if has "$ORIGIN/$MASTER_BRANCH" "$(git_remote_branches)"; then
|
|
|
|
require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
|
|
|
|
fi
|
|
|
|
if has "$ORIGIN/$DEVELOP_BRANCH" "$(git_remote_branches)"; then
|
|
|
|
require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
|
|
|
|
fi
|
2010-01-25 21:16:08 +00:00
|
|
|
|
2010-02-08 23:31:33 +00:00
|
|
|
# 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
|
2010-02-21 20:31:03 +00:00
|
|
|
if ! git_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
|
2010-02-09 23:34:59 +00:00
|
|
|
git checkout "$MASTER_BRANCH" || \
|
2010-02-08 23:31:33 +00:00
|
|
|
die "Could not check out $MASTER_BRANCH."
|
2010-02-09 23:34:59 +00:00
|
|
|
git merge --no-ff "$BRANCH" || \
|
2010-02-08 23:31:33 +00:00
|
|
|
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
|
2010-02-15 22:01:52 +00:00
|
|
|
local tagname=$VERSION_PREFIX$VERSION
|
2010-02-21 20:31:03 +00:00
|
|
|
if ! git_tag_exists "$tagname"; then
|
2010-02-15 22:01:52 +00:00
|
|
|
local opts="-a"
|
2010-02-08 23:31:33 +00:00
|
|
|
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
|
2010-02-21 20:31:03 +00:00
|
|
|
if ! git_is_branch_merged_into "$BRANCH" "$DEVELOP_BRANCH"; then
|
2010-02-09 23:34:59 +00:00
|
|
|
git checkout "$DEVELOP_BRANCH" || \
|
2010-02-08 23:31:33 +00:00
|
|
|
die "Could not check out $DEVELOP_BRANCH."
|
2010-02-08 23:55:06 +00:00
|
|
|
|
|
|
|
# TODO: Actually, accounting for 'git describe' pays, so we should
|
|
|
|
# ideally git merge --no-ff $tagname here, instead!
|
2010-02-09 23:34:59 +00:00
|
|
|
git merge --no-ff "$BRANCH" || \
|
2010-02-08 23:31:33 +00:00
|
|
|
die "There were merge conflicts."
|
|
|
|
# TODO: What do we do now?
|
|
|
|
fi
|
2010-01-26 11:39:36 +00:00
|
|
|
|
|
|
|
# delete branch
|
2010-02-09 23:34:59 +00:00
|
|
|
git branch -d "$BRANCH"
|
2010-01-26 00:15:51 +00:00
|
|
|
|
2010-02-19 05:42:18 +00:00
|
|
|
if flag push; then
|
|
|
|
git push "$ORIGIN" "$DEVELOP_BRANCH" || \
|
|
|
|
die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
|
|
|
|
git push "$ORIGIN" "$MASTER_BRANCH" || \
|
|
|
|
die "Could not push to $MASTER_BRANCH from $ORIGIN."
|
|
|
|
git push --tags "$ORIGIN" || \
|
|
|
|
die "Could not push tags to $ORIGIN."
|
|
|
|
fi
|
2010-01-26 00:15:51 +00:00
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
echo
|
2010-01-26 00:15:51 +00:00
|
|
|
echo "Summary of actions:"
|
2010-01-26 12:05:05 +00:00
|
|
|
echo "- Latest objects have been fetched from '$ORIGIN'"
|
2010-01-26 11:59:27 +00:00
|
|
|
echo "- Release branch has been merged into '$MASTER_BRANCH'"
|
2010-02-08 23:31:33 +00:00
|
|
|
echo "- The release was tagged '$tagname'"
|
2010-01-26 11:59:27 +00:00
|
|
|
echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
|
2010-01-26 11:39:36 +00:00
|
|
|
echo "- Release branch '$BRANCH' has been deleted"
|
2010-02-19 05:42:18 +00:00
|
|
|
if flag push; then
|
|
|
|
echo "- '$DEVELOP_BRANCH', '$MASTER_BRANCH' and tags have been pushed to '$ORIGIN'"
|
|
|
|
fi
|
2010-01-26 11:39:36 +00:00
|
|
|
echo
|
2010-01-21 00:32:18 +00:00
|
|
|
}
|