blob: 1f5918fef45c7b0280b805ae810febbd1badd953 [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/)
17
Vincent Driessen3c337fb2010-02-04 11:30:18 +010018warn "note: The support subcommand is still very EXPERIMENTAL!"
19warn "note: DO NOT use it in a production situation."
20
Benedikt Böhm00ccea62010-01-26 12:39:36 +010021usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010022 echo "usage: git flow support [list] [-v]"
Vincent Driessen010252a2010-02-04 10:31:29 +010023 echo " git flow support start <version> <base>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010024}
25
Vincent Driessenb866b012010-01-28 01:01:53 +010026cmd_default() {
27 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010028}
29
Vincent Driessenb866b012010-01-28 01:01:53 +010030cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010031 DEFINE_boolean verbose false 'verbose (more) output' v
32 parse_args "$@"
33
Vincent Driessen27592dd2010-02-06 14:45:39 +010034 typeset support_branches
35 typeset current_branch
36 typeset short_names
Vincent Driessenc5fcc012010-02-10 00:18:08 +010037 support_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010038 if [ -z "$support_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010039 warn "No support branches exist."
40 exit 0
41 fi
Vincent Driessen27592dd2010-02-06 14:45:39 +010042 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
43 short_names=$(echo "$support_branches" | sed "s?^$PREFIX??g")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010044
Vincent Driessen3c337fb2010-02-04 11:30:18 +010045 # determine column width first
Vincent Driessen27592dd2010-02-06 14:45:39 +010046 typeset -i width=0
47 typeset branch
48 for branch in $short_names; do
49 typeset -i len=$(($(echo "$branch" | wc -c) - 1))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010050 width=$(max $width $len)
51 done
Vincent Driessen27592dd2010-02-06 14:45:39 +010052 width=width+3
Vincent Driessen3c337fb2010-02-04 11:30:18 +010053
Vincent Driessen27592dd2010-02-06 14:45:39 +010054 typeset branch
55 for branch in $short_names; do
Vincent Driessenc5fcc012010-02-10 00:18:08 +010056 typeset fullname=$PREFIX$branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010057 typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH")
58 typeset master_sha=$(git rev-parse "$MASTER_BRANCH")
59 typeset branch_sha=$(git rev-parse "$fullname")
60 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010061 printf "* "
62 else
63 printf " "
64 fi
65 if flag verbose; then
66 printf "%-${width}s" "$branch"
67 if [ "$branch_sha" = "$master_sha" ]; then
68 printf "(no commits yet)"
69 else
Vincent Driessena4dd2232010-02-10 00:34:59 +010070 typeset tagname=$(git name-rev --tags --no-undefined --name-only "$base")
Vincent Driessen27592dd2010-02-06 14:45:39 +010071 typeset nicename
Vincent Driessen3c337fb2010-02-04 11:30:18 +010072 if [ "$tagname" != "" ]; then
Vincent Driessenc5fcc012010-02-10 00:18:08 +010073 nicename=$tagname
Vincent Driessen3c337fb2010-02-04 11:30:18 +010074 else
Vincent Driessena4dd2232010-02-10 00:34:59 +010075 nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010076 fi
77 printf "(based on $nicename)"
78 fi
79 else
80 printf "%s" "$branch"
81 fi
82 echo
83 done
Vincent Driessen170dc742010-01-28 00:20:51 +010084}
85
Benedikt Böhm00ccea62010-01-26 12:39:36 +010086cmd_help() {
87 usage
88 exit 0
89}
90
Benedikt Böhm00ccea62010-01-26 12:39:36 +010091parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010092 # parse options
93 FLAGS "$@" || exit $?
94 eval set -- "${FLAGS_ARGV}"
95
96 # read arguments into global variables
Vincent Driessenc5fcc012010-02-10 00:18:08 +010097 VERSION=$1
98 BASE=$2
Vincent Driessen3c337fb2010-02-04 11:30:18 +010099 BRANCH=$PREFIX$VERSION
100}
101
102require_version_arg() {
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100103 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100104 warn "Missing argument <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100105 usage
106 exit 1
107 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100108}
109
Vincent Driessen010252a2010-02-04 10:31:29 +0100110require_base_arg() {
111 if [ "$BASE" = "" ]; then
112 warn "Missing argument <base>"
113 usage
114 exit 1
115 fi
116}
117
118require_base_is_on_master() {
119 if ! git branch --contains "$BASE" 2>/dev/null \
120 | sed 's/[* ] //g' \
121 | grep -q "^$MASTER_BRANCH\$"; then
122 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
123 fi
124}
125
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100126cmd_start() {
Vincent Driessenca73caf2010-02-07 19:46:38 +0100127 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100128 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100129 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100130 require_base_arg
131 require_base_is_on_master
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100132
133 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100134 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100135
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100136 # fetch remote changes
Vincent Driessenca73caf2010-02-07 19:46:38 +0100137 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100138 git fetch -q "$ORIGIN" "$BASE"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100139 fi
Vincent Driessena4dd2232010-02-10 00:34:59 +0100140 gitflow_require_branch_absent "$BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100141
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100142 # create branch
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100143 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100144
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100145 echo
146 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100147 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100148 echo "- You are now on branch '$BRANCH'"
149 echo
150}