Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 185 lines (165 sloc) 5.162 kB
00ccea6 @hollow refactor the whole thing
hollow authored
1 #
6c2d30b @nvie Structurally replace gitflow by git-flow, as a true git extension.
authored
2 # git-flow -- A collection of Git extensions to provide high-level
3 # repository operations for Vincent Driessen's branching model.
00ccea6 @hollow refactor the whole thing
hollow authored
4 #
5 # Original blog post presenting this model is found at:
ddb350b @nvie Change the URL of the original blog post.
authored
6 # http://nvie.com/git-model
00ccea6 @hollow refactor the whole thing
hollow authored
7 #
8 # Feel free to contribute to this project at:
9 # http://github.com/nvie/gitflow
10 #
d72acba @nvie Added inline license terms to all source files.
authored
11 # 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.
00ccea6 @hollow refactor the whole thing
hollow authored
37 #
38
dc902ed @pcragone Added 'init()' function to git-flow-{feature,release,hotfix,support},…
pcragone authored
39 init() {
40 require_git_repo
41 require_gitflow_initialized
42 gitflow_load_settings
43 VERSION_PREFIX=$(eval "echo `git config --get gitflow.prefix.versiontag`")
44 PREFIX=$(git config --get gitflow.prefix.support)
45 }
49dd62b @hollow refactor git config calls to global variables
hollow authored
46
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
47 warn "note: The support subcommand is still very EXPERIMENTAL!"
48 warn "note: DO NOT use it in a production situation."
49
00ccea6 @hollow refactor the whole thing
hollow authored
50 usage() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
51 echo "usage: git flow support [list] [-v]"
a2e4116 @nvie Document all available flags in all of the subcommand synopsis texts.
authored
52 echo " git flow support start [-F] <version> <base>"
00ccea6 @hollow refactor the whole thing
hollow authored
53 }
54
170dc74 @nvie Refactored the feature, release and support subcommands, too.
authored
55 cmd_default() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
56 cmd_list "$@"
00ccea6 @hollow refactor the whole thing
hollow authored
57 }
58
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
59 cmd_list() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
60 DEFINE_boolean verbose false 'verbose (more) output' v
61 parse_args "$@"
62
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
63 local support_branches
64 local current_branch
65 local short_names
7832d6e @nvie Better naming of common functions categorizing them into common,
authored
66 support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
27592dd @nvie Tidy up:
authored
67 if [ -z "$support_branches" ]; then
170dc74 @nvie Refactored the feature, release and support subcommands, too.
authored
68 warn "No support branches exist."
b681b45 @Zoramite Adding extra instructions when running the list option without any co…
Zoramite authored
69 warn ""
70 warn "You can start a new support branch:"
71 warn ""
72 warn " git flow support start <name> <base>"
4de01f2 @Zoramite Adding an extra line to the output for extra spacing.
Zoramite authored
73 warn ""
170dc74 @nvie Refactored the feature, release and support subcommands, too.
authored
74 exit 0
75 fi
cf3da5a @adamgibbins Fixed incorrect color flag
adamgibbins authored
76 current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
6884523 @nvie Use space (' ') instead of '?' as a pattern terminator.
authored
77 short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
78
79 # determine column width first
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
80 local width=0
81 local branch
27592dd @nvie Tidy up:
authored
82 for branch in $short_names; do
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
83 local len=${#branch}
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
84 width=$(max $width $len)
85 done
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
86 width=$(($width+3))
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
87
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
88 local branch
27592dd @nvie Tidy up:
authored
89 for branch in $short_names; do
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
90 local fullname=$PREFIX$branch
91 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
92 local master_sha=$(git rev-parse "$MASTER_BRANCH")
93 local branch_sha=$(git rev-parse "$fullname")
27592dd @nvie Tidy up:
authored
94 if [ "$fullname" = "$current_branch" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
95 printf "* "
96 else
97 printf " "
98 fi
99 if flag verbose; then
100 printf "%-${width}s" "$branch"
101 if [ "$branch_sha" = "$master_sha" ]; then
102 printf "(no commits yet)"
103 else
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
104 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
105 local nicename
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
106 if [ "$tagname" != "" ]; then
c5fcc01 @nvie Do not quote variable assignments.
authored
107 nicename=$tagname
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
108 else
a4dd223 @nvie Quote all variables in function/program arguments.
authored
109 nicename=$(git rev-parse --short "$base")
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
110 fi
111 printf "(based on $nicename)"
112 fi
113 else
114 printf "%s" "$branch"
115 fi
116 echo
117 done
170dc74 @nvie Refactored the feature, release and support subcommands, too.
authored
118 }
119
00ccea6 @hollow refactor the whole thing
hollow authored
120 cmd_help() {
121 usage
122 exit 0
123 }
124
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
125 parse_args() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
126 # parse options
127 FLAGS "$@" || exit $?
128 eval set -- "${FLAGS_ARGV}"
129
130 # read arguments into global variables
c5fcc01 @nvie Do not quote variable assignments.
authored
131 VERSION=$1
132 BASE=$2
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
133 BRANCH=$PREFIX$VERSION
134 }
135
136 require_version_arg() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
137 if [ "$VERSION" = "" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
138 warn "Missing argument <version>"
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
139 usage
140 exit 1
141 fi
142 }
143
010252a @nvie Added an optional <base> argument to all start subactions.
authored
144 require_base_arg() {
145 if [ "$BASE" = "" ]; then
146 warn "Missing argument <base>"
147 usage
148 exit 1
149 fi
150 }
151
152 require_base_is_on_master() {
cf3da5a @adamgibbins Fixed incorrect color flag
adamgibbins authored
153 if ! git branch --no-color --contains "$BASE" 2>/dev/null \
010252a @nvie Added an optional <base> argument to all start subactions.
authored
154 | sed 's/[* ] //g' \
155 | grep -q "^$MASTER_BRANCH\$"; then
156 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
157 fi
158 }
159
00ccea6 @hollow refactor the whole thing
hollow authored
160 cmd_start() {
de95e00 @nvie Change the default behaviour of all scripts to NOT fetch.
authored
161 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
00ccea6 @hollow refactor the whole thing
hollow authored
162 parse_args "$@"
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
163 require_version_arg
010252a @nvie Added an optional <base> argument to all start subactions.
authored
164 require_base_arg
165 require_base_is_on_master
00ccea6 @hollow refactor the whole thing
hollow authored
166
167 # sanity checks
7832d6e @nvie Better naming of common functions categorizing them into common,
authored
168 require_clean_working_tree
00ccea6 @hollow refactor the whole thing
hollow authored
169
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
170 # fetch remote changes
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
authored
171 if flag fetch; then
15aab26 @jeromebaum Use git_do where appropriate
jeromebaum authored
172 git_do fetch -q "$ORIGIN" "$BASE"
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
173 fi
7832d6e @nvie Better naming of common functions categorizing them into common,
authored
174 require_branch_absent "$BRANCH"
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
175
00ccea6 @hollow refactor the whole thing
hollow authored
176 # create branch
15aab26 @jeromebaum Use git_do where appropriate
jeromebaum authored
177 git_do checkout -b "$BRANCH" "$BASE"
00ccea6 @hollow refactor the whole thing
hollow authored
178
179 echo
180 echo "Summary of actions:"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
181 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
00ccea6 @hollow refactor the whole thing
hollow authored
182 echo "- You are now on branch '$BRANCH'"
183 echo
184 }
Something went wrong with that request. Please try again.