2010-01-26 11:39:36 +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
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2010-02-16 20:33:51 +00:00
|
|
|
gitflow_require_git_repo
|
2010-02-20 15:52:48 +00:00
|
|
|
gitflow_require_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.support)
|
2010-01-27 23:51:15 +00:00
|
|
|
|
2010-02-04 10:30:18 +00:00
|
|
|
warn "note: The support subcommand is still very EXPERIMENTAL!"
|
|
|
|
warn "note: DO NOT use it in a production situation."
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
usage() {
|
2010-02-04 10:30:18 +00:00
|
|
|
echo "usage: git flow support [list] [-v]"
|
2010-02-04 09:31:29 +00:00
|
|
|
echo " git flow support start <version> <base>"
|
2010-01-26 11:39:36 +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 support_branches
|
|
|
|
local current_branch
|
|
|
|
local short_names
|
2010-02-16 19:57:35 +00:00
|
|
|
support_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
|
2010-02-06 13:45:39 +00:00
|
|
|
if [ -z "$support_branches" ]; then
|
2010-01-27 23:20:51 +00:00
|
|
|
warn "No support branches exist."
|
|
|
|
exit 0
|
|
|
|
fi
|
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 "$support_branches" | sed "s ^$PREFIX g")
|
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" "$MASTER_BRANCH")
|
|
|
|
local master_sha=$(git rev-parse "$MASTER_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" = "$master_sha" ]; then
|
|
|
|
printf "(no commits yet)"
|
|
|
|
else
|
2010-02-15 22:01:52 +00:00
|
|
|
local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
|
|
|
|
local nicename
|
2010-02-04 10:30:18 +00:00
|
|
|
if [ "$tagname" != "" ]; then
|
2010-02-09 23:18:08 +00:00
|
|
|
nicename=$tagname
|
2010-02-04 10:30:18 +00:00
|
|
|
else
|
2010-02-09 23:34:59 +00:00
|
|
|
nicename=$(git rev-parse --short "$base")
|
2010-02-04 10:30:18 +00:00
|
|
|
fi
|
|
|
|
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-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
|
|
|
|
BASE=$2
|
2010-02-04 10:30:18 +00:00
|
|
|
BRANCH=$PREFIX$VERSION
|
|
|
|
}
|
|
|
|
|
|
|
|
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_arg() {
|
|
|
|
if [ "$BASE" = "" ]; then
|
|
|
|
warn "Missing argument <base>"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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-26 11:39:36 +00:00
|
|
|
parse_args "$@"
|
2010-02-04 10:30:18 +00:00
|
|
|
require_version_arg
|
2010-02-04 09:31:29 +00:00
|
|
|
require_base_arg
|
|
|
|
require_base_is_on_master
|
2010-01-26 11:39:36 +00:00
|
|
|
|
|
|
|
# sanity checks
|
2010-01-29 09:30:40 +00:00
|
|
|
gitflow_require_clean_working_tree
|
2010-01-26 11:39:36 +00:00
|
|
|
|
2010-01-29 11:37:22 +00:00
|
|
|
# fetch remote changes
|
2010-02-07 18:46:38 +00:00
|
|
|
if flag fetch; then
|
2010-02-09 23:34:59 +00:00
|
|
|
git fetch -q "$ORIGIN" "$BASE"
|
2010-01-29 11:37:22 +00:00
|
|
|
fi
|
2010-02-09 23:34:59 +00:00
|
|
|
gitflow_require_branch_absent "$BRANCH"
|
2010-01-29 11:37:22 +00:00
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
# create branch
|
2010-02-04 10:30:18 +00:00
|
|
|
git checkout -b "$BRANCH" "$BASE"
|
2010-01-26 11:39:36 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
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
|
|
|
|
}
|