blob: e33459280ebe0b05868de83d1a13e6a338096d8d [file] [log] [blame]
Benedikt Böhm00ccea62010-01-26 12:39:36 +01001#
Vincent Driessen6c2d30b2010-01-26 22:18:36 +01002# git-flow -- A collection of Git extensions to provide high-level
3# repository operations for Vincent Driessen's branching model.
Benedikt Böhm00ccea62010-01-26 12:39:36 +01004#
5# Original blog post presenting this model is found at:
6# http://nvie.com/archives/323
7#
8# Feel free to contribute to this project at:
9# http://github.com/nvie/gitflow
10#
11# Copyright (c) 2010 by Vincent Driessen
12# Copyright (c) 2010 by Benedikt Böhm
13#
14
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010015VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
16PREFIX=$(git config --get gitflow.prefix.support || echo support/)
Vincent Driessen2acfffd2010-01-29 12:37:22 +010017FLAG_FETCH=1
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010018
Vincent Driessen3c337fb2010-02-04 11:30:18 +010019warn "note: The support subcommand is still very EXPERIMENTAL!"
20warn "note: DO NOT use it in a production situation."
21
Benedikt Böhm00ccea62010-01-26 12:39:36 +010022usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010023 echo "usage: git flow support [list] [-v]"
Vincent Driessen010252a2010-02-04 10:31:29 +010024 echo " git flow support start <version> <base>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010025}
26
Vincent Driessenb866b012010-01-28 01:01:53 +010027cmd_default() {
28 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010029}
30
Vincent Driessenb866b012010-01-28 01:01:53 +010031cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010032 DEFINE_boolean verbose false 'verbose (more) output' v
33 parse_args "$@"
34
Vincent Driessen170dc742010-01-28 00:20:51 +010035 SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
36 if [ -z "$SUPPORT_BRANCHES" ]; then
37 warn "No support branches exist."
38 exit 0
39 fi
Vincent Driessen3c337fb2010-02-04 11:30:18 +010040
41 CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
42 SHORT_NAMES=$(echo "$SUPPORT_BRANCHES" | sed "s?^$PREFIX??g")
43 # determine column width first
44 width=0
45 for branch in $SHORT_NAMES; do
46 len=$(($(echo "$branch" | wc -c) - 1))
47 width=$(max $width $len)
48 done
49 width=$(($width + 3))
50
51 for branch in $SHORT_NAMES; do
52 fullname="$PREFIX$branch"
53 base=$(git merge-base "$fullname" "$MASTER_BRANCH")
54 master_sha=$(git rev-parse "$MASTER_BRANCH")
55 branch_sha=$(git rev-parse "$fullname")
56 if [ "$fullname" = "$CURRENT_BRANCH" ]; then
57 printf "* "
58 else
59 printf " "
60 fi
61 if flag verbose; then
62 printf "%-${width}s" "$branch"
63 if [ "$branch_sha" = "$master_sha" ]; then
64 printf "(no commits yet)"
65 else
66 tagname=$(git name-rev --tags --no-undefined --name-only $base)
67 if [ "$tagname" != "" ]; then
68 nicename="$tagname"
69 else
70 nicename="$(git rev-parse --short $base)"
71 fi
72 printf "(based on $nicename)"
73 fi
74 else
75 printf "%s" "$branch"
76 fi
77 echo
78 done
Vincent Driessen170dc742010-01-28 00:20:51 +010079}
80
Benedikt Böhm00ccea62010-01-26 12:39:36 +010081cmd_help() {
82 usage
83 exit 0
84}
85
Benedikt Böhm00ccea62010-01-26 12:39:36 +010086parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010087 # parse options
88 FLAGS "$@" || exit $?
89 eval set -- "${FLAGS_ARGV}"
90
91 # read arguments into global variables
Benedikt Böhm00ccea62010-01-26 12:39:36 +010092 VERSION="$1"
Vincent Driessen010252a2010-02-04 10:31:29 +010093 BASE="$2"
Vincent Driessen3c337fb2010-02-04 11:30:18 +010094 BRANCH=$PREFIX$VERSION
95}
96
97require_version_arg() {
Benedikt Böhm00ccea62010-01-26 12:39:36 +010098 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010099 warn "Missing argument <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100100 usage
101 exit 1
102 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100103}
104
Vincent Driessen010252a2010-02-04 10:31:29 +0100105require_base_arg() {
106 if [ "$BASE" = "" ]; then
107 warn "Missing argument <base>"
108 usage
109 exit 1
110 fi
111}
112
113require_base_is_on_master() {
114 if ! git branch --contains "$BASE" 2>/dev/null \
115 | sed 's/[* ] //g' \
116 | grep -q "^$MASTER_BRANCH\$"; then
117 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
118 fi
119}
120
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100121cmd_start() {
122 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100123 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100124 require_base_arg
125 require_base_is_on_master
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100126
127 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100128 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100129
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100130 # fetch remote changes
131 if [ $FLAG_FETCH -eq 1 ]; then
132 git fetch -q $ORIGIN $BASE
133 fi
Vincent Driessen010252a2010-02-04 10:31:29 +0100134 gitflow_require_branch_absent $BRANCH
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100135
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100136 # create branch
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100137 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100138
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100139 echo
140 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100141 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100142 echo "- You are now on branch '$BRANCH'"
143 echo
144}