Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 226 lines (199 sloc) 6.446 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:
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
ab3dc49 @nvie Fix: respect the VERSION_PREFIX in hotfix releases, too.
authored
15 VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
49dd62b @hollow refactor git config calls to global variables
hollow authored
16 PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
17
00ccea6 @hollow refactor the whole thing
hollow authored
18 usage() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
19 echo "usage: git flow hotfix [list] [-v]"
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored
20 echo " git flow hotfix start <version> [<base>]"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
21 echo " git flow hotfix finish <version>"
00ccea6 @hollow refactor the whole thing
hollow authored
22 }
23
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored
24 cmd_default() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
25 cmd_list "$@"
00ccea6 @hollow refactor the whole thing
hollow authored
26 }
27
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
28 cmd_list() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
29 DEFINE_boolean verbose false 'verbose (more) output' v
30 parse_args "$@"
31
27592dd @nvie Tidy up:
authored
32 typeset hotfix_branches
33 typeset current_branch
34 typeset short_names
35 hotfix_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
36 if [ -z "$hotfix_branches" ]; then
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored
37 warn "No hotfix branches exist."
38 exit 0
39 fi
27592dd @nvie Tidy up:
authored
40 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
41 short_names=$(echo "$hotfix_branches" | sed "s?^$PREFIX??g")
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
42
43 # determine column width first
27592dd @nvie Tidy up:
authored
44 typeset -i width=0
45 typeset branch
46 for branch in $short_names; do
47 typeset -i len=$(($(echo "$branch" | wc -c) - 1))
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
48 width=$(max $width $len)
49 done
27592dd @nvie Tidy up:
authored
50 width=width+3
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
51
27592dd @nvie Tidy up:
authored
52 typeset branch
53 for branch in $short_names; do
54 typeset fullname="$PREFIX$branch"
55 typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH")
56 typeset master_sha=$(git rev-parse "$MASTER_BRANCH")
57 typeset branch_sha=$(git rev-parse "$fullname")
58 if [ "$fullname" = "$current_branch" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
59 printf "* "
60 else
61 printf " "
62 fi
63 if flag verbose; then
64 printf "%-${width}s" "$branch"
65 if [ "$branch_sha" = "$master_sha" ]; then
66 printf "(no commits yet)"
67 else
27592dd @nvie Tidy up:
authored
68 typeset tagname=$(git name-rev --tags --no-undefined --name-only $base)
69 typeset nicename
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
70 if [ "$tagname" != "" ]; then
71 nicename="$tagname"
72 else
73 nicename="$(git rev-parse --short $base)"
74 fi
75 printf "(based on $nicename)"
76 fi
77 else
78 printf "%s" "$branch"
79 fi
80 echo
81 done
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored
82 }
83
00ccea6 @hollow refactor the whole thing
hollow authored
84 cmd_help() {
85 usage
86 exit 0
87 }
88
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
89 parse_args() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
90 # parse options
91 FLAGS "$@" || exit $?
92 eval set -- "${FLAGS_ARGV}"
93
94 # read arguments into global variables
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
95 VERSION="$1"
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
96 BRANCH=$PREFIX$VERSION
97 }
98
99 require_version_arg() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
100 if [ "$VERSION" = "" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
101 warn "Missing argument <version>"
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
102 usage
103 exit 1
104 fi
105 }
106
010252a @nvie Added an optional <base> argument to all start subactions.
authored
107 require_base_is_on_master() {
108 if ! git branch --contains "$BASE" 2>/dev/null \
109 | sed 's/[* ] //g' \
110 | grep -q "^$MASTER_BRANCH\$"; then
111 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
112 fi
113 }
114
00ccea6 @hollow refactor the whole thing
hollow authored
115 cmd_start() {
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
authored
116 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
00ccea6 @hollow refactor the whole thing
hollow authored
117 parse_args "$@"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
118 BASE="${2:-$MASTER_BRANCH}"
119 require_version_arg
120 require_base_is_on_master
00ccea6 @hollow refactor the whole thing
hollow authored
121
122 # sanity checks
4838644 @nvie Replace gitflow_check_ prefixes by gitflow_require_ prefixes, for con…
authored
123 gitflow_require_clean_working_tree
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
authored
124 gitflow_require_branch_absent $BRANCH
125 gitflow_require_tag_absent $VERSION_PREFIX$VERSION
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
authored
126 if flag fetch; then
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
127 git fetch -q $ORIGIN $MASTER_BRANCH
128 fi
350e715 @hollow make origin configurable
hollow authored
129 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
00ccea6 @hollow refactor the whole thing
hollow authored
130
131 # create branch
132 git checkout -b $BRANCH $BASE
133
134 echo
135 echo "Summary of actions:"
136 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
137 echo "- You are now on branch '$BRANCH'"
138 echo
139 echo "Follow-up actions:"
140 echo "- Bump the version number now!"
141 echo "- Start committing your hot fixes"
142 echo "- When done, run:"
143 echo
010252a @nvie Added an optional <base> argument to all start subactions.
authored
144 echo " git flow hotfix finish '$VERSION'"
00ccea6 @hollow refactor the whole thing
hollow authored
145 echo
146 }
147
148 cmd_finish() {
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
authored
149 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
150 DEFINE_boolean sign false "sign the release tag cryptographically" s
151 DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u
152 DEFINE_string message "" "use the given tag message" m
00ccea6 @hollow refactor the whole thing
hollow authored
153 parse_args "$@"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
154 require_version_arg
00ccea6 @hollow refactor the whole thing
hollow authored
155
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
authored
156 # handle flags that imply other flags
157 if [ "$FLAGS_signingkey" != "" ]; then
158 FLAGS_sign=$FLAGS_TRUE
159 fi
160
00ccea6 @hollow refactor the whole thing
hollow authored
161 # sanity checks
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
authored
162 gitflow_require_branch $BRANCH
4838644 @nvie Replace gitflow_check_ prefixes by gitflow_require_ prefixes, for con…
authored
163 gitflow_require_clean_working_tree
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
authored
164 if flag fetch; then
1a2868b @nvie Add tag annotation and tag signing to both release and hotfix.
authored
165 git fetch -q $ORIGIN $MASTER_BRANCH || \
166 die "Could not fetch $MASTER_BRANCH from $ORIGIN."
167 git fetch -q $ORIGIN $DEVELOP_BRANCH || \
168 die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
169 fi
350e715 @hollow make origin configurable
hollow authored
170 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
171 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
00ccea6 @hollow refactor the whole thing
hollow authored
172
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
authored
173 # try to merge into master
174 # in case a previous attempt to finish this release branch has failed,
175 # but the merge into master was successful, we skip it now
176 if ! gitflow_is_branch_merged_into $BRANCH $MASTER_BRANCH; then
177 git checkout $MASTER_BRANCH || \
178 die "Could not check out $MASTER_BRANCH."
179 git merge --no-ff $BRANCH || \
180 die "There were merge conflicts."
181 # TODO: What do we do now?
182 fi
183
184 # try to tag the release
185 # in case a previous attempt to finish this release branch has failed,
186 # but the tag was set successful, we skip it now
187 typeset tagname=$VERSION_PREFIX$VERSION
188 if ! gitflow_tag_exists $tagname; then
189 typeset opts="-a"
190 flag sign && opts="$opts -s"
191 [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
192 [ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
193 git tag $opts "$VERSION_PREFIX$VERSION" || \
194 die "Tagging failed. Please run finish again to retry."
195 fi
196
197 # try to merge into develop
198 # in case a previous attempt to finish this release branch has failed,
199 # but the merge into develop was successful, we skip it now
200 if ! gitflow_is_branch_merged_into $BRANCH $DEVELOP_BRANCH; then
201 git checkout $DEVELOP_BRANCH || \
202 die "Could not check out $DEVELOP_BRANCH."
203
d29e315 @nvie Annotated the code with some TODO-notes.
authored
204 # TODO: Actually, accounting for 'git describe' pays, so we should
205 # ideally git merge --no-ff $tagname here, instead!
5fa4758 @nvie Made the finishing of release/hotfix branches fail-safe. When a
authored
206 git merge --no-ff $BRANCH || \
207 die "There were merge conflicts."
208 # TODO: What do we do now?
209 fi
00ccea6 @hollow refactor the whole thing
hollow authored
210
211 # delete branch
212 git branch -d $BRANCH
213
214 # TODO: Implement an optional push to master
215 # git push origin develop; git push origin master; git push --tags origin
216
217 echo
218 echo "Summary of actions:"
350e715 @hollow make origin configurable
hollow authored
219 echo "- Latest objects have been fetched from '$ORIGIN'"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
220 echo "- Hotfix branch has been merged into '$MASTER_BRANCH'"
ab3dc49 @nvie Fix: respect the VERSION_PREFIX in hotfix releases, too.
authored
221 echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
222 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
00ccea6 @hollow refactor the whole thing
hollow authored
223 echo "- Hotfix branch '$BRANCH' has been deleted"
224 echo
225 }
Something went wrong with that request. Please try again.