173 lines
4.2 KiB
Text
173 lines
4.2 KiB
Text
#
|
|
# git-flow -- A collection of Git extensions to provide high-level
|
|
# repository operations for Vincent Driessen's branching model.
|
|
#
|
|
# Original blog post presenting this model is found at:
|
|
# http://nvie.com/archives/323
|
|
#
|
|
# Feel free to contribute to this project at:
|
|
# http://github.com/nvie/gitflow
|
|
#
|
|
# Copyright (c) 2010 by Vincent Driessen
|
|
# Copyright (c) 2010 by Benedikt Böhm
|
|
#
|
|
|
|
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
|
|
PREFIX=$(git config --get gitflow.prefix.release || echo release/)
|
|
FLAG_FETCH=1
|
|
|
|
usage() {
|
|
echo "usage: git flow release [list] [-v]"
|
|
echo " git flow release start <version>"
|
|
echo " git flow release finish <version>"
|
|
# 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"
|
|
}
|
|
|
|
cmd_default() {
|
|
cmd_list "$@"
|
|
}
|
|
|
|
cmd_list() {
|
|
DEFINE_boolean verbose false 'verbose (more) output' v
|
|
parse_args "$@"
|
|
|
|
RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
|
|
if [ -z "$RELEASE_BRANCHES" ]; then
|
|
warn "No release branches exist."
|
|
exit 0
|
|
fi
|
|
|
|
CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
|
|
SHORT_NAMES=$(echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g")
|
|
# determine column width first
|
|
width=0
|
|
for branch in $SHORT_NAMES; do
|
|
len=$(($(echo "$branch" | wc -c) - 1))
|
|
width=$(max $width $len)
|
|
done
|
|
width=$(($width + 3))
|
|
|
|
for branch in $SHORT_NAMES; do
|
|
fullname="$PREFIX$branch"
|
|
base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
|
|
develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
|
|
branch_sha=$(git rev-parse "$fullname")
|
|
if [ "$fullname" = "$CURRENT_BRANCH" ]; then
|
|
printf "* "
|
|
else
|
|
printf " "
|
|
fi
|
|
if flag verbose; then
|
|
printf "%-${width}s" "$branch"
|
|
if [ "$branch_sha" = "$develop_sha" ]; then
|
|
printf "(no commits yet)"
|
|
else
|
|
nicename="$(git rev-parse --short $base)"
|
|
printf "(based on $nicename)"
|
|
fi
|
|
else
|
|
printf "%s" "$branch"
|
|
fi
|
|
echo
|
|
done
|
|
}
|
|
|
|
cmd_help() {
|
|
usage
|
|
exit 0
|
|
}
|
|
|
|
parse_args() {
|
|
# parse options
|
|
FLAGS "$@" || exit $?
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
# read arguments into global variables
|
|
VERSION="$1"
|
|
BRANCH="$PREFIX$VERSION"
|
|
}
|
|
|
|
require_version_arg() {
|
|
if [ "$VERSION" = "" ]; then
|
|
warn "Missing argument <version>"
|
|
usage
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
cmd_start() {
|
|
parse_args "$@"
|
|
require_version_arg
|
|
|
|
# sanity checks
|
|
gitflow_require_clean_working_tree
|
|
if [ $FLAG_FETCH -eq 1 ]; then
|
|
git fetch -q $ORIGIN $DEVELOP_BRANCH
|
|
fi
|
|
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
|
gitflow_require_branch_absent $BRANCH
|
|
|
|
# create branch
|
|
git checkout -b $BRANCH $DEVELOP_BRANCH
|
|
|
|
echo
|
|
echo "Summary of actions:"
|
|
echo "- A new branch '$BRANCH' was created, based on '$DEVELOP_BRANCH'"
|
|
echo "- You are now on branch '$BRANCH'"
|
|
echo
|
|
echo "Follow-up actions:"
|
|
echo "- Bump the version number now!"
|
|
echo "- Start committing last-minute fixes in preparing your release"
|
|
echo "- When done, run:"
|
|
echo
|
|
echo " git flow finish release '$VERSION'"
|
|
echo
|
|
}
|
|
|
|
cmd_finish() {
|
|
parse_args "$@"
|
|
require_version_arg
|
|
|
|
# sanity checks
|
|
gitflow_require_clean_working_tree
|
|
if [ $FLAG_FETCH -eq 1 ]; then
|
|
git fetch -q $ORIGIN $MASTER_BRANCH
|
|
git fetch -q $ORIGIN $DEVELOP_BRANCH
|
|
fi
|
|
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
|
|
git merge --no-ff $BRANCH
|
|
git tag $VERSION_PREFIX$VERSION
|
|
|
|
# merge into develop
|
|
git checkout $DEVELOP_BRANCH
|
|
git merge --no-ff $BRANCH
|
|
|
|
# delete branch
|
|
git branch -d $BRANCH
|
|
|
|
# TODO: Implement an optional push to master
|
|
# git push origin develop; git push origin master; git push --tags origin
|
|
|
|
echo
|
|
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 "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
|
|
echo "- Release branch '$BRANCH' has been deleted"
|
|
echo
|
|
}
|