27592dd732
- Lower-cased all local variable names - Explicitly typeset all local variable names, to prevent issues with setting/overriding variables in the global namespace. - Explicitly typed integer types as integer (typeset -i) to enable simpler arithmetic calculations on them.
183 lines
4.4 KiB
Text
183 lines
4.4 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.hotfix || echo hotfix/)
|
|
FLAG_FETCH=1
|
|
|
|
usage() {
|
|
echo "usage: git flow hotfix [list] [-v]"
|
|
echo " git flow hotfix start <version> [<base>]"
|
|
echo " git flow hotfix finish <version>"
|
|
}
|
|
|
|
cmd_default() {
|
|
cmd_list "$@"
|
|
}
|
|
|
|
cmd_list() {
|
|
DEFINE_boolean verbose false 'verbose (more) output' v
|
|
parse_args "$@"
|
|
|
|
typeset hotfix_branches
|
|
typeset current_branch
|
|
typeset short_names
|
|
hotfix_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
|
|
if [ -z "$hotfix_branches" ]; then
|
|
warn "No hotfix branches exist."
|
|
exit 0
|
|
fi
|
|
current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
|
|
short_names=$(echo "$hotfix_branches" | sed "s?^$PREFIX??g")
|
|
|
|
# determine column width first
|
|
typeset -i width=0
|
|
typeset branch
|
|
for branch in $short_names; do
|
|
typeset -i len=$(($(echo "$branch" | wc -c) - 1))
|
|
width=$(max $width $len)
|
|
done
|
|
width=width+3
|
|
|
|
typeset branch
|
|
for branch in $short_names; do
|
|
typeset fullname="$PREFIX$branch"
|
|
typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH")
|
|
typeset master_sha=$(git rev-parse "$MASTER_BRANCH")
|
|
typeset 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" = "$master_sha" ]; then
|
|
printf "(no commits yet)"
|
|
else
|
|
typeset tagname=$(git name-rev --tags --no-undefined --name-only $base)
|
|
typeset nicename
|
|
if [ "$tagname" != "" ]; then
|
|
nicename="$tagname"
|
|
else
|
|
nicename="$(git rev-parse --short $base)"
|
|
fi
|
|
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
|
|
}
|
|
|
|
require_base_is_on_master() {
|
|
if ! git branch --contains "$BASE" 2>/dev/null \
|
|
| sed 's/[* ] //g' \
|
|
| grep -q "^$MASTER_BRANCH\$"; then
|
|
die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
|
|
fi
|
|
}
|
|
|
|
cmd_start() {
|
|
parse_args "$@"
|
|
BASE="${2:-$MASTER_BRANCH}"
|
|
require_version_arg
|
|
require_base_is_on_master
|
|
|
|
# sanity checks
|
|
gitflow_require_clean_working_tree
|
|
if [ $FLAG_FETCH -eq 1 ]; then
|
|
git fetch -q $ORIGIN $MASTER_BRANCH
|
|
fi
|
|
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
|
|
gitflow_require_branch_absent $BRANCH
|
|
|
|
# create branch
|
|
git checkout -b $BRANCH $BASE
|
|
|
|
echo
|
|
echo "Summary of actions:"
|
|
echo "- A new branch '$BRANCH' was created, based on '$BASE'"
|
|
echo "- You are now on branch '$BRANCH'"
|
|
echo
|
|
echo "Follow-up actions:"
|
|
echo "- Bump the version number now!"
|
|
echo "- Start committing your hot fixes"
|
|
echo "- When done, run:"
|
|
echo
|
|
echo " git flow hotfix finish '$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 if we fixed a master issue
|
|
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 "- Hotfix branch has been merged into '$MASTER_BRANCH'"
|
|
echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
|
|
echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
|
|
echo "- Hotfix branch '$BRANCH' has been deleted"
|
|
echo
|
|
}
|