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:
|
|
|
|
# http://nvie.com/archives/323
|
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
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 by Vincent Driessen
|
2010-01-26 11:39:36 +00:00
|
|
|
# Copyright (c) 2010 by Benedikt Böhm
|
2010-01-21 00:36:44 +00:00
|
|
|
#
|
2010-01-21 00:32:18 +00:00
|
|
|
|
2010-01-27 23:51:15 +00:00
|
|
|
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
|
|
|
|
PREFIX=$(git config --get gitflow.prefix.release || echo release/)
|
|
|
|
|
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-01-27 23:20:51 +00:00
|
|
|
echo " git flow release start <version>"
|
|
|
|
echo " git flow release finish <version>"
|
2010-01-26 00:15:51 +00:00
|
|
|
# TODO
|
|
|
|
#echo ""
|
|
|
|
#echo "options:"
|
|
|
|
#echo "--option Explanation"
|
|
|
|
#echo ""
|
|
|
|
#echo "start-only options:"
|
|
|
|
#echo "--bump <script>"
|
|
|
|
#echo " Run the given script to auto-update the version number"
|
|
|
|
#echo ""
|
|
|
|
#echo "finish-only options:"
|
|
|
|
#echo "--push Push to the origin repo when finished"
|
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-09 23:18:08 +00:00
|
|
|
release_branches=$(echo "$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."
|
|
|
|
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-01-26 11:39:36 +00:00
|
|
|
cmd_start() {
|
2010-02-07 18:46:38 +00:00
|
|
|
DEFINE_boolean fetch true "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-01-25 21:16:08 +00:00
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
# sanity checks
|
2010-01-29 09:30:40 +00:00
|
|
|
gitflow_require_clean_working_tree
|
2010-02-09 23:34:59 +00:00
|
|
|
gitflow_require_branch_absent "$BRANCH"
|
|
|
|
gitflow_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-02-09 23:34:59 +00:00
|
|
|
gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
|
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-02-07 18:46:38 +00:00
|
|
|
DEFINE_boolean fetch true "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-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-09 23:34:59 +00:00
|
|
|
gitflow_require_branch "$BRANCH"
|
2010-01-29 09:30:40 +00:00
|
|
|
gitflow_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-02-09 23:34:59 +00:00
|
|
|
gitflow_require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
|
|
|
|
gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
|
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-09 23:34:59 +00:00
|
|
|
if ! gitflow_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
|
|
|
|
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-09 23:34:59 +00:00
|
|
|
if ! gitflow_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-09 23:34:59 +00:00
|
|
|
if ! gitflow_is_branch_merged_into "$BRANCH" "$DEVELOP_BRANCH"; then
|
|
|
|
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
|
|
|
|
|
|
|
# TODO: Implement an optional push to master
|
|
|
|
# git push origin develop; git push origin master; git push --tags origin
|
|
|
|
|
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"
|
|
|
|
echo
|
2010-01-21 00:32:18 +00:00
|
|
|
}
|