blob: 1bdbaedc070653b296be92f230ec7c242a445b0a [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
Vincent Driessend72e4ac2010-02-16 21:33:51 +010015gitflow_require_git_repo
16gitflow_load_settings
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010017VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
18PREFIX=$(git config --get gitflow.prefix.support || echo support/)
19
Vincent Driessen3c337fb2010-02-04 11:30:18 +010020warn "note: The support subcommand is still very EXPERIMENTAL!"
21warn "note: DO NOT use it in a production situation."
22
Benedikt Böhm00ccea62010-01-26 12:39:36 +010023usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010024 echo "usage: git flow support [list] [-v]"
Vincent Driessen010252a2010-02-04 10:31:29 +010025 echo " git flow support start <version> <base>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010026}
27
Vincent Driessenb866b012010-01-28 01:01:53 +010028cmd_default() {
29 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010030}
31
Vincent Driessenb866b012010-01-28 01:01:53 +010032cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010033 DEFINE_boolean verbose false 'verbose (more) output' v
34 parse_args "$@"
35
Vincent Driessenf46e2902010-02-15 23:01:52 +010036 local support_branches
37 local current_branch
38 local short_names
Vincent Driessen21c7aa92010-02-16 20:57:35 +010039 support_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010040 if [ -z "$support_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010041 warn "No support branches exist."
42 exit 0
43 fi
Vincent Driessen27592dd2010-02-06 14:45:39 +010044 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
Vincent Driessen68845232010-02-10 00:43:21 +010045 short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010046
Vincent Driessen3c337fb2010-02-04 11:30:18 +010047 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010048 local width=0
49 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010050 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010051 local len=${#branch}
Vincent Driessen3c337fb2010-02-04 11:30:18 +010052 width=$(max $width $len)
53 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010054 width=$(($width+3))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010055
Vincent Driessenf46e2902010-02-15 23:01:52 +010056 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010057 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010058 local fullname=$PREFIX$branch
59 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
60 local master_sha=$(git rev-parse "$MASTER_BRANCH")
61 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010062 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010063 printf "* "
64 else
65 printf " "
66 fi
67 if flag verbose; then
68 printf "%-${width}s" "$branch"
69 if [ "$branch_sha" = "$master_sha" ]; then
70 printf "(no commits yet)"
71 else
Vincent Driessenf46e2902010-02-15 23:01:52 +010072 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
73 local nicename
Vincent Driessen3c337fb2010-02-04 11:30:18 +010074 if [ "$tagname" != "" ]; then
Vincent Driessenc5fcc012010-02-10 00:18:08 +010075 nicename=$tagname
Vincent Driessen3c337fb2010-02-04 11:30:18 +010076 else
Vincent Driessena4dd2232010-02-10 00:34:59 +010077 nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010078 fi
79 printf "(based on $nicename)"
80 fi
81 else
82 printf "%s" "$branch"
83 fi
84 echo
85 done
Vincent Driessen170dc742010-01-28 00:20:51 +010086}
87
Benedikt Böhm00ccea62010-01-26 12:39:36 +010088cmd_help() {
89 usage
90 exit 0
91}
92
Benedikt Böhm00ccea62010-01-26 12:39:36 +010093parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010094 # parse options
95 FLAGS "$@" || exit $?
96 eval set -- "${FLAGS_ARGV}"
97
98 # read arguments into global variables
Vincent Driessenc5fcc012010-02-10 00:18:08 +010099 VERSION=$1
100 BASE=$2
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100101 BRANCH=$PREFIX$VERSION
102}
103
104require_version_arg() {
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100105 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100106 warn "Missing argument <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100107 usage
108 exit 1
109 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100110}
111
Vincent Driessen010252a2010-02-04 10:31:29 +0100112require_base_arg() {
113 if [ "$BASE" = "" ]; then
114 warn "Missing argument <base>"
115 usage
116 exit 1
117 fi
118}
119
120require_base_is_on_master() {
121 if ! git branch --contains "$BASE" 2>/dev/null \
122 | sed 's/[* ] //g' \
123 | grep -q "^$MASTER_BRANCH\$"; then
124 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
125 fi
126}
127
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100128cmd_start() {
Vincent Driessenca73caf2010-02-07 19:46:38 +0100129 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100130 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100131 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100132 require_base_arg
133 require_base_is_on_master
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100134
135 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100136 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100137
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100138 # fetch remote changes
Vincent Driessenca73caf2010-02-07 19:46:38 +0100139 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100140 git fetch -q "$ORIGIN" "$BASE"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100141 fi
Vincent Driessena4dd2232010-02-10 00:34:59 +0100142 gitflow_require_branch_absent "$BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100143
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100144 # create branch
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100145 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100146
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100147 echo
148 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100149 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100150 echo "- You are now on branch '$BRANCH'"
151 echo
152}