blob: 1357d1fa3860d971cf67e8b8c06f67822233a848 [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#
Vincent Driessend72acba2010-04-04 16:10:17 +020011# Copyright 2010 Vincent Driessen. All rights reserved.
12#
13# Redistribution and use in source and binary forms, with or without
14# modification, are permitted provided that the following conditions are met:
15#
16# 1. Redistributions of source code must retain the above copyright notice,
17# this list of conditions and the following disclaimer.
18#
19# 2. Redistributions in binary form must reproduce the above copyright
20# notice, this list of conditions and the following disclaimer in the
21# documentation and/or other materials provided with the distribution.
22#
23# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
24# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#
34# The views and conclusions contained in the software and documentation are
35# those of the authors and should not be interpreted as representing official
36# policies, either expressed or implied, of Vincent Driessen.
Benedikt Böhm00ccea62010-01-26 12:39:36 +010037#
38
Vincent Driessen7832d6e2010-02-21 21:31:03 +010039require_git_repo
40require_gitflow_initialized
Vincent Driessend72e4ac2010-02-16 21:33:51 +010041gitflow_load_settings
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010042VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
Vincent Driessenc1598bf2010-02-20 16:52:48 +010043PREFIX=$(git config --get gitflow.prefix.support)
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010044
Vincent Driessen3c337fb2010-02-04 11:30:18 +010045warn "note: The support subcommand is still very EXPERIMENTAL!"
46warn "note: DO NOT use it in a production situation."
47
Benedikt Böhm00ccea62010-01-26 12:39:36 +010048usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010049 echo "usage: git flow support [list] [-v]"
Vincent Driessena2e41162010-02-24 01:37:07 +010050 echo " git flow support start [-F] <version> <base>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010051}
52
Vincent Driessenb866b012010-01-28 01:01:53 +010053cmd_default() {
54 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010055}
56
Vincent Driessenb866b012010-01-28 01:01:53 +010057cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010058 DEFINE_boolean verbose false 'verbose (more) output' v
59 parse_args "$@"
60
Vincent Driessenf46e2902010-02-15 23:01:52 +010061 local support_branches
62 local current_branch
63 local short_names
Vincent Driessen7832d6e2010-02-21 21:31:03 +010064 support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010065 if [ -z "$support_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010066 warn "No support branches exist."
67 exit 0
68 fi
Vincent Driessen27592dd2010-02-06 14:45:39 +010069 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
Vincent Driessen68845232010-02-10 00:43:21 +010070 short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010071
Vincent Driessen3c337fb2010-02-04 11:30:18 +010072 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010073 local width=0
74 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010075 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010076 local len=${#branch}
Vincent Driessen3c337fb2010-02-04 11:30:18 +010077 width=$(max $width $len)
78 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010079 width=$(($width+3))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010080
Vincent Driessenf46e2902010-02-15 23:01:52 +010081 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010082 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010083 local fullname=$PREFIX$branch
84 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
85 local master_sha=$(git rev-parse "$MASTER_BRANCH")
86 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010087 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010088 printf "* "
89 else
90 printf " "
91 fi
92 if flag verbose; then
93 printf "%-${width}s" "$branch"
94 if [ "$branch_sha" = "$master_sha" ]; then
95 printf "(no commits yet)"
96 else
Vincent Driessenf46e2902010-02-15 23:01:52 +010097 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
98 local nicename
Vincent Driessen3c337fb2010-02-04 11:30:18 +010099 if [ "$tagname" != "" ]; then
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100100 nicename=$tagname
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100101 else
Vincent Driessena4dd2232010-02-10 00:34:59 +0100102 nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100103 fi
104 printf "(based on $nicename)"
105 fi
106 else
107 printf "%s" "$branch"
108 fi
109 echo
110 done
Vincent Driessen170dc742010-01-28 00:20:51 +0100111}
112
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100113cmd_help() {
114 usage
115 exit 0
116}
117
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100118parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100119 # parse options
120 FLAGS "$@" || exit $?
121 eval set -- "${FLAGS_ARGV}"
122
123 # read arguments into global variables
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100124 VERSION=$1
125 BASE=$2
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100126 BRANCH=$PREFIX$VERSION
127}
128
129require_version_arg() {
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100130 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100131 warn "Missing argument <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100132 usage
133 exit 1
134 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100135}
136
Vincent Driessen010252a2010-02-04 10:31:29 +0100137require_base_arg() {
138 if [ "$BASE" = "" ]; then
139 warn "Missing argument <base>"
140 usage
141 exit 1
142 fi
143}
144
145require_base_is_on_master() {
146 if ! git branch --contains "$BASE" 2>/dev/null \
147 | sed 's/[* ] //g' \
148 | grep -q "^$MASTER_BRANCH\$"; then
149 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
150 fi
151}
152
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100153cmd_start() {
Vincent Driessenca73caf2010-02-07 19:46:38 +0100154 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100155 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100156 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100157 require_base_arg
158 require_base_is_on_master
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100159
160 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100161 require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100162
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100163 # fetch remote changes
Vincent Driessenca73caf2010-02-07 19:46:38 +0100164 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100165 git fetch -q "$ORIGIN" "$BASE"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100166 fi
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100167 require_branch_absent "$BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100168
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100169 # create branch
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100170 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100171
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100172 echo
173 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100174 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100175 echo "- You are now on branch '$BRANCH'"
176 echo
177}