Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 255 lines (225 sloc) 7.402 kb
093a147 @nvie Added header comments to all files.
nvie authored
1 #
6c2d30b @nvie Structurally replace gitflow by git-flow, as a true git extension.
nvie 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 #
093a147 @nvie Added header comments to all files.
nvie authored
5 # Original blog post presenting this model is found at:
6 # http://nvie.com/archives/323
00ccea6 @hollow refactor the whole thing
hollow authored
7 #
093a147 @nvie Added header comments to all files.
nvie authored
8 # Feel free to contribute to this project at:
9 # http://github.com/nvie/gitflow
10 #
11 # Copyright (c) 2010 by Vincent Driessen
00ccea6 @hollow refactor the whole thing
hollow authored
12 # Copyright (c) 2010 by Benedikt Böhm
093a147 @nvie Added header comments to all files.
nvie authored
13 #
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
14
d72e4ac @nvie Rewrite the way git-flow initialized its variables in git-flow and as…
nvie authored
15 gitflow_require_git_repo
c1598bf @nvie Added function gitflow_require_initialized(), to assert that the gitflow
nvie authored
16 gitflow_require_initialized
d72e4ac @nvie Rewrite the way git-flow initialized its variables in git-flow and as…
nvie authored
17 gitflow_load_settings
49dd62b @hollow refactor git config calls to global variables
hollow authored
18 VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
c1598bf @nvie Added function gitflow_require_initialized(), to assert that the gitflow
nvie authored
19 PREFIX=$(git config --get gitflow.prefix.release)
49dd62b @hollow refactor git config calls to global variables
hollow authored
20
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
21 usage() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
22 echo "usage: git flow release [list] [-v]"
170dc74 @nvie Refactored the feature, release and support subcommands, too.
nvie authored
23 echo " git flow release start <version>"
24 echo " git flow release finish <version>"
696b9eb @nvie Functionally implement the creation/finishing of release branches.
nvie authored
25 # TODO
26 #echo ""
27 #echo "options:"
28 #echo "--option Explanation"
29 #echo ""
30 #echo "start-only options:"
31 #echo "--bump <script>"
32 #echo " Run the given script to auto-update the version number"
33 #echo ""
34 #echo "finish-only options:"
35 #echo "--push Push to the origin repo when finished"
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
36 }
37
170dc74 @nvie Refactored the feature, release and support subcommands, too.
nvie authored
38 cmd_default() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
nvie authored
39 cmd_list "$@"
00ccea6 @hollow refactor the whole thing
hollow authored
40 }
41
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
nvie authored
42 cmd_list() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
43 DEFINE_boolean verbose false 'verbose (more) output' v
44 parse_args "$@"
45
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
46 local release_branches
47 local current_branch
48 local short_names
21c7aa9 @nvie Don't store remote and local branch names in shell variables, but query
nvie authored
49 release_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
27592dd @nvie Tidy up:
nvie authored
50 if [ -z "$release_branches" ]; then
170dc74 @nvie Refactored the feature, release and support subcommands, too.
nvie authored
51 warn "No release branches exist."
52 exit 0
53 fi
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
54
27592dd @nvie Tidy up:
nvie authored
55 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
6884523 @nvie Use space (' ') instead of '?' as a pattern terminator.
nvie authored
56 short_names=$(echo "$release_branches" | sed "s ^$PREFIX g")
27592dd @nvie Tidy up:
nvie authored
57
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
58 # determine column width first
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
59 local width=0
60 local branch
27592dd @nvie Tidy up:
nvie authored
61 for branch in $short_names; do
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
62 local len=${#branch}
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
63 width=$(max $width $len)
64 done
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
65 width=$(($width+3))
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
66
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
67 local branch
27592dd @nvie Tidy up:
nvie authored
68 for branch in $short_names; do
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
69 local fullname=$PREFIX$branch
70 local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
71 local develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
72 local branch_sha=$(git rev-parse "$fullname")
27592dd @nvie Tidy up:
nvie authored
73 if [ "$fullname" = "$current_branch" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
74 printf "* "
75 else
76 printf " "
77 fi
78 if flag verbose; then
79 printf "%-${width}s" "$branch"
80 if [ "$branch_sha" = "$develop_sha" ]; then
81 printf "(no commits yet)"
82 else
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
83 local nicename=$(git rev-parse --short "$base")
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
84 printf "(based on $nicename)"
85 fi
86 else
87 printf "%s" "$branch"
88 fi
89 echo
90 done
170dc74 @nvie Refactored the feature, release and support subcommands, too.
nvie authored
91 }
92
00ccea6 @hollow refactor the whole thing
hollow authored
93 cmd_help() {
94 usage
95 exit 0
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
96 }
97
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
nvie authored
98 parse_args() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
99 # parse options
100 FLAGS "$@" || exit $?
101 eval set -- "${FLAGS_ARGV}"
102
103 # read arguments into global variables
c5fcc01 @nvie Do not quote variable assignments.
nvie authored
104 VERSION=$1
105 BRANCH=$PREFIX$VERSION
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
106 }
107
108 require_version_arg() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
nvie authored
109 if [ "$VERSION" = "" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
110 warn "Missing argument <version>"
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
nvie authored
111 usage
112 exit 1
113 fi
114 }
115
010252a @nvie Added an optional <base> argument to all start subactions.
nvie authored
116 require_base_is_on_develop() {
117 if ! git branch --contains "$BASE" 2>/dev/null \
118 | sed 's/[* ] //g' \
119 | grep -q "^$DEVELOP_BRANCH\$"; then
120 die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'."
121 fi
122 }
123
6d64d2c @nvie Add check to disallow creation of a new release/hotfix branch when there
nvie authored
124 require_no_existing_release_branches() {
21c7aa9 @nvie Don't store remote and local branch names in shell variables, but query
nvie authored
125 local release_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
6d64d2c @nvie Add check to disallow creation of a new release/hotfix branch when there
nvie authored
126 local first_branch=$(echo ${release_branches} | head -n1)
127 first_branch=${first_branch#$PREFIX}
128 [ -z "$release_branches" ] || \
129 die "There is an existing release branch ($first_branch). Finish that one first."
130 }
131
00ccea6 @hollow refactor the whole thing
hollow authored
132 cmd_start() {
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
nvie authored
133 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
134 parse_args "$@"
c5fcc01 @nvie Do not quote variable assignments.
nvie authored
135 BASE=${2:-$DEVELOP_BRANCH}
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
136 require_version_arg
010252a @nvie Added an optional <base> argument to all start subactions.
nvie authored
137 require_base_is_on_develop
6d64d2c @nvie Add check to disallow creation of a new release/hotfix branch when there
nvie authored
138 require_no_existing_release_branches
3d41255 @nvie Add checks for all the commands, to assure we're working in a clean a…
nvie authored
139
00ccea6 @hollow refactor the whole thing
hollow authored
140 # sanity checks
4838644 @nvie Replace gitflow_check_ prefixes by gitflow_require_ prefixes, for con…
nvie authored
141 gitflow_require_clean_working_tree
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
142 gitflow_require_branch_absent "$BRANCH"
143 gitflow_require_tag_absent "$VERSION_PREFIX$VERSION"
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
nvie authored
144 if flag fetch; then
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
145 git fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
nvie authored
146 fi
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
147 gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
3d41255 @nvie Add checks for all the commands, to assure we're working in a clean a…
nvie authored
148
00ccea6 @hollow refactor the whole thing
hollow authored
149 # create branch
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
150 git checkout -b "$BRANCH" "$BASE"
696b9eb @nvie Functionally implement the creation/finishing of release branches.
nvie authored
151
00ccea6 @hollow refactor the whole thing
hollow authored
152 echo
696b9eb @nvie Functionally implement the creation/finishing of release branches.
nvie authored
153 echo "Summary of actions:"
010252a @nvie Added an optional <base> argument to all start subactions.
nvie authored
154 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
00ccea6 @hollow refactor the whole thing
hollow authored
155 echo "- You are now on branch '$BRANCH'"
156 echo
696b9eb @nvie Functionally implement the creation/finishing of release branches.
nvie authored
157 echo "Follow-up actions:"
158 echo "- Bump the version number now!"
159 echo "- Start committing last-minute fixes in preparing your release"
160 echo "- When done, run:"
00ccea6 @hollow refactor the whole thing
hollow authored
161 echo
010252a @nvie Added an optional <base> argument to all start subactions.
nvie authored
162 echo " git flow release finish '$VERSION'"
00ccea6 @hollow refactor the whole thing
hollow authored
163 echo
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
164 }
165
00ccea6 @hollow refactor the whole thing
hollow authored
166 cmd_finish() {
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
nvie authored
167 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
nvie authored
168 DEFINE_boolean sign false "sign the release tag cryptographically" s
169 DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u
170 DEFINE_string message "" "use the given tag message" m
ddba2df @nvie Fix spacing issues.
nvie authored
171 DEFINE_boolean push false "push to $ORIGIN after performing finish" p
6809f0e @zerotao Added push option (-p) to hotfix and release
zerotao authored
172
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
173 parse_args "$@"
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
nvie authored
174 require_version_arg
3d41255 @nvie Add checks for all the commands, to assure we're working in a clean a…
nvie authored
175
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
nvie authored
176 # handle flags that imply other flags
177 if [ "$FLAGS_signingkey" != "" ]; then
178 FLAGS_sign=$FLAGS_TRUE
179 fi
180
00ccea6 @hollow refactor the whole thing
hollow authored
181 # sanity checks
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
182 gitflow_require_branch "$BRANCH"
4838644 @nvie Replace gitflow_check_ prefixes by gitflow_require_ prefixes, for con…
nvie authored
183 gitflow_require_clean_working_tree
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
nvie authored
184 if flag fetch; then
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
185 git fetch -q "$ORIGIN" "$MASTER_BRANCH" || \
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
nvie authored
186 die "Could not fetch $MASTER_BRANCH from $ORIGIN."
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
187 git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" || \
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
nvie authored
188 die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
nvie authored
189 fi
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
190 gitflow_require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
191 gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
3d41255 @nvie Add checks for all the commands, to assure we're working in a clean a…
nvie authored
192
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
nvie authored
193 # try to merge into master
194 # in case a previous attempt to finish this release branch has failed,
195 # but the merge into master was successful, we skip it now
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
196 if ! gitflow_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
197 git checkout "$MASTER_BRANCH" || \
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
nvie authored
198 die "Could not check out $MASTER_BRANCH."
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
199 git merge --no-ff "$BRANCH" || \
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
nvie authored
200 die "There were merge conflicts."
201 # TODO: What do we do now?
202 fi
203
204 # try to tag the release
205 # in case a previous attempt to finish this release branch has failed,
206 # but the tag was set successful, we skip it now
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
207 local tagname=$VERSION_PREFIX$VERSION
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
208 if ! gitflow_tag_exists "$tagname"; then
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
nvie authored
209 local opts="-a"
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
nvie authored
210 flag sign && opts="$opts -s"
211 [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
212 [ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
213 git tag $opts "$tagname" || \
214 die "Tagging failed. Please run finish again to retry."
215 fi
216
217 # try to merge into develop
218 # in case a previous attempt to finish this release branch has failed,
219 # but the merge into develop was successful, we skip it now
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
220 if ! gitflow_is_branch_merged_into "$BRANCH" "$DEVELOP_BRANCH"; then
221 git checkout "$DEVELOP_BRANCH" || \
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
nvie authored
222 die "Could not check out $DEVELOP_BRANCH."
d29e315 @nvie Annotated the code with some TODO-notes.
nvie authored
223
224 # TODO: Actually, accounting for 'git describe' pays, so we should
225 # ideally git merge --no-ff $tagname here, instead!
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
226 git merge --no-ff "$BRANCH" || \
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
nvie authored
227 die "There were merge conflicts."
228 # TODO: What do we do now?
229 fi
00ccea6 @hollow refactor the whole thing
hollow authored
230
231 # delete branch
a4dd223 @nvie Quote all variables in function/program arguments.
nvie authored
232 git branch -d "$BRANCH"
696b9eb @nvie Functionally implement the creation/finishing of release branches.
nvie authored
233
ddba2df @nvie Fix spacing issues.
nvie authored
234 if flag push; then
235 git push "$ORIGIN" "$DEVELOP_BRANCH" || \
236 die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
237 git push "$ORIGIN" "$MASTER_BRANCH" || \
238 die "Could not push to $MASTER_BRANCH from $ORIGIN."
239 git push --tags "$ORIGIN" || \
240 die "Could not push tags to $ORIGIN."
241 fi
696b9eb @nvie Functionally implement the creation/finishing of release branches.
nvie authored
242
00ccea6 @hollow refactor the whole thing
hollow authored
243 echo
696b9eb @nvie Functionally implement the creation/finishing of release branches.
nvie authored
244 echo "Summary of actions:"
350e715 @hollow make origin configurable
hollow authored
245 echo "- Latest objects have been fetched from '$ORIGIN'"
4a864fb @hollow make master and develop branch names configurable
hollow authored
246 echo "- Release branch has been merged into '$MASTER_BRANCH'"
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
nvie authored
247 echo "- The release was tagged '$tagname'"
4a864fb @hollow make master and develop branch names configurable
hollow authored
248 echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
00ccea6 @hollow refactor the whole thing
hollow authored
249 echo "- Release branch '$BRANCH' has been deleted"
ddba2df @nvie Fix spacing issues.
nvie authored
250 if flag push; then
251 echo "- '$DEVELOP_BRANCH', '$MASTER_BRANCH' and tags have been pushed to '$ORIGIN'"
252 fi
00ccea6 @hollow refactor the whole thing
hollow authored
253 echo
f7f687c @nvie Also add basic skeleton implementation for the gitflow-feature and gi…
nvie authored
254 }
Something went wrong with that request. Please try again.