blob: 9403c12c131c8ddcdf28b89172c6ff2687d05772 [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 Driessen7832d6e2010-02-21 21:31:03 +010015require_git_repo
16require_gitflow_initialized
Vincent Driessend72e4ac2010-02-16 21:33:51 +010017gitflow_load_settings
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010018VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
Vincent Driessenc1598bf2010-02-20 16:52:48 +010019PREFIX=$(git config --get gitflow.prefix.support)
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010020
Vincent Driessen3c337fb2010-02-04 11:30:18 +010021warn "note: The support subcommand is still very EXPERIMENTAL!"
22warn "note: DO NOT use it in a production situation."
23
Benedikt Böhm00ccea62010-01-26 12:39:36 +010024usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010025 echo "usage: git flow support [list] [-v]"
Vincent Driessena2e41162010-02-24 01:37:07 +010026 echo " git flow support start [-F] <version> <base>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010027}
28
Vincent Driessenb866b012010-01-28 01:01:53 +010029cmd_default() {
30 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010031}
32
Vincent Driessenb866b012010-01-28 01:01:53 +010033cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010034 DEFINE_boolean verbose false 'verbose (more) output' v
35 parse_args "$@"
36
Vincent Driessenf46e2902010-02-15 23:01:52 +010037 local support_branches
38 local current_branch
39 local short_names
Vincent Driessen7832d6e2010-02-21 21:31:03 +010040 support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010041 if [ -z "$support_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010042 warn "No support branches exist."
43 exit 0
44 fi
Vincent Driessen27592dd2010-02-06 14:45:39 +010045 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
Vincent Driessen68845232010-02-10 00:43:21 +010046 short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010047
Vincent Driessen3c337fb2010-02-04 11:30:18 +010048 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010049 local width=0
50 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010051 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010052 local len=${#branch}
Vincent Driessen3c337fb2010-02-04 11:30:18 +010053 width=$(max $width $len)
54 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010055 width=$(($width+3))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010056
Vincent Driessenf46e2902010-02-15 23:01:52 +010057 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010058 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010059 local fullname=$PREFIX$branch
60 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
61 local master_sha=$(git rev-parse "$MASTER_BRANCH")
62 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010063 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010064 printf "* "
65 else
66 printf " "
67 fi
68 if flag verbose; then
69 printf "%-${width}s" "$branch"
70 if [ "$branch_sha" = "$master_sha" ]; then
71 printf "(no commits yet)"
72 else
Vincent Driessenf46e2902010-02-15 23:01:52 +010073 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
74 local nicename
Vincent Driessen3c337fb2010-02-04 11:30:18 +010075 if [ "$tagname" != "" ]; then
Vincent Driessenc5fcc012010-02-10 00:18:08 +010076 nicename=$tagname
Vincent Driessen3c337fb2010-02-04 11:30:18 +010077 else
Vincent Driessena4dd2232010-02-10 00:34:59 +010078 nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010079 fi
80 printf "(based on $nicename)"
81 fi
82 else
83 printf "%s" "$branch"
84 fi
85 echo
86 done
Vincent Driessen170dc742010-01-28 00:20:51 +010087}
88
Benedikt Böhm00ccea62010-01-26 12:39:36 +010089cmd_help() {
90 usage
91 exit 0
92}
93
Benedikt Böhm00ccea62010-01-26 12:39:36 +010094parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010095 # parse options
96 FLAGS "$@" || exit $?
97 eval set -- "${FLAGS_ARGV}"
98
99 # read arguments into global variables
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100100 VERSION=$1
101 BASE=$2
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100102 BRANCH=$PREFIX$VERSION
103}
104
105require_version_arg() {
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100106 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100107 warn "Missing argument <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100108 usage
109 exit 1
110 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100111}
112
Vincent Driessen010252a2010-02-04 10:31:29 +0100113require_base_arg() {
114 if [ "$BASE" = "" ]; then
115 warn "Missing argument <base>"
116 usage
117 exit 1
118 fi
119}
120
121require_base_is_on_master() {
122 if ! git branch --contains "$BASE" 2>/dev/null \
123 | sed 's/[* ] //g' \
124 | grep -q "^$MASTER_BRANCH\$"; then
125 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
126 fi
127}
128
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100129cmd_start() {
Vincent Driessenca73caf2010-02-07 19:46:38 +0100130 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100131 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100132 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100133 require_base_arg
134 require_base_is_on_master
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100135
136 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100137 require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100138
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100139 # fetch remote changes
Vincent Driessenca73caf2010-02-07 19:46:38 +0100140 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100141 git fetch -q "$ORIGIN" "$BASE"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100142 fi
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100143 require_branch_absent "$BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100144
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100145 # create branch
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100146 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100147
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100148 echo
149 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100150 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100151 echo "- You are now on branch '$BRANCH'"
152 echo
153}