forked from MeltwaterArchive/gitflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-hf-support
257 lines (230 loc) · 6.73 KB
/
git-hf-support
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env bash
#
# HubFlow - a fork of the git-flow tools to apply Vincent Driessen's
# branching model to working with GitHub
#
# Original blog post presenting this model is found at:
# http://nvie.com/git-model
#
# The HubFlow documentation is found at:
# http://datasift.github.com/gitflow/
#
# Feel free to contribute to this project at:
# http://github.com/datasift/gitflow
#
# Copyright 2010 Vincent Driessen. All rights reserved.
# Copyright 2012 MediaSift Ltd. All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of Vincent Driessen.
#
require_git_repo
require_hubflow_initialized
hubflow_load_settings
PREFIX=$(git config --get hubflow.prefix.support)
usage() {
echo "usage: git hf support [list] [-v]"
echo " git hf support start <version> <base>"
echo ""
}
cmd_default() {
cmd_list "$@"
}
cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
local support_branches
local current_branch
local short_names
support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
if [ -z "$support_branches" ]; then
warn "No support branches exist."
warn ""
warn "You can start a new support branch:"
warn ""
warn " git hf support start <name> <base>"
warn ""
exit 0
fi
current_branch=$(git_current_branch)
short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
# determine column width first
local width=0
local branch
for branch in $short_names; do
local len=${#branch}
width=$(max $width $len)
done
width=$(($width+3))
local branch
for branch in $short_names; do
local fullname=$PREFIX$branch
local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
local master_sha=$(git rev-parse "$MASTER_BRANCH")
local branch_sha=$(git rev-parse "$fullname")
if [ "$fullname" = "$current_branch" ]; then
printf "* "
else
printf " "
fi
if flag verbose; then
printf "%-${width}s" "$branch"
if [ "$branch_sha" = "$master_sha" ]; then
printf "(no commits yet)"
else
local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
local nicename
if [ "$tagname" != "" ]; then
nicename=$tagname
else
nicename=$(git rev-parse --short "$base")
fi
printf "(based on $nicename)"
fi
else
printf "%s" "$branch"
fi
echo
done
}
cmd_help() {
usage
exit 0
}
parse_args() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
VERSION=$1
BASE=$2
SUPPORT_BRANCH=$PREFIX$VERSION
}
parse_remote_name() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
REMOTE=$1
NAME=$2
SUPPORT_BRANCH=$PREFIX$NAME
}
require_version_arg() {
if [ "$VERSION" = "" ]; then
warn "Missing argument <version>"
usage
exit 1
fi
}
require_base_arg() {
if [ "$BASE" = "" ]; then
warn "Missing argument <base>"
usage
exit 1
fi
}
require_base_is_on_master() {
if ! git branch --no-color --contains "$BASE" 2>/dev/null \
| sed 's/[* ] //g' \
| grep -q "^$MASTER_BRANCH\$"; then
die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
fi
}
expand_nameprefix_arg() {
require_name_arg
local expanded_name
local exitcode
track_repo=$(hubflow_track_repo "$NAME" "$PREFIX" "$ORIGIN")
expanded_name=$(hubflow_resolve_nameprefix "$NAME" "$PREFIX")
exitcode=$?
case $exitcode in
0) NAME=$expanded_name
SUPPORT_BRANCH=$PREFIX$NAME
;;
*) exit 1 ;;
esac
}
expand_nameprefix_arg_or_current() {
if [ "$NAME" != "" ]; then
expand_nameprefix_arg
require_branch "$PREFIX$NAME"
else
use_current_support_branch_name
fi
}
name_or_current() {
if [ -z "$NAME" ]; then
use_current_support_branch_name
fi
}
use_current_support_branch_name() {
local current_branch=$(git_current_branch)
if startswith "$current_branch" "$PREFIX"; then
SUPPORT_BRANCH=$current_branch
NAME=${BRANCH#$PREFIX}
else
warn "The current HEAD is not a support branch."
warn "Please specify a <name> argument."
exit 1
fi
}
cmd_start() {
DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
parse_args "$@"
require_version_arg
require_base_arg
require_base_is_on_master
# sanity checks
require_clean_working_tree
require_remote_available
if flag fetch ; then
hubflow_fetch_latest_changes_from_origin
fi
require_branch_absent "$ORIGIN/$SUPPORT_BRANCH"
require_branch_absent "$SUPPORT_BRANCH"
# if the origin branch counterpart exists, assert that the local branch
# isn't behind it (to avoid unnecessary rebasing)
if git_branch_exists "$ORIGIN/$MASTER_BRANCH"; then
require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
fi
# create branch
if ! git checkout -b "$SUPPORT_BRANCH" "$BASE"; then
die "Could not create support branch '$SUPPORT_BRANCH'"
fi
# push it back up to remote repo
hubflow_push_latest_changes_to_origin
echo
echo "Summary of actions:"
echo "- A new branch '$SUPPORT_BRANCH' was created, based on '$BASE'"
echo "- The branch '$SUPPORT_BRANCH' has been pushed up to '$ORIGIN/$SUPPORT_BRANCH'"
echo "- You are now on branch '$SUPPORT_BRANCH'"
echo ""
echo "Now, start committing your support fixes. When done, use:"
echo
echo " git hf release start <version> $SUPPORT_BRANCH"
echo
echo "to create a release branch for testing, packaging, and deployment."
}