61
61
# expansion "$@" is changed to "$ <at>"), so don't try to use this copy:
62
62
# http://permalink.gmane.org/gmane.comp.version-control.git/247581
63
63
64
+ git_branch_alias () {
64
65
# cwd=$(git rev-parse --show-toplevel)
65
66
git=$( git rev-parse --git-dir)
66
67
if [ $? -ne 0 ]; then
67
- exit 1
68
+ return 1
68
69
fi
69
70
70
71
command=$( basename $0 )
@@ -129,7 +130,7 @@ if [ -n "${shorthelp}" ]; then
129
130
For help, use: ${command} -h
130
131
131
132
EOF
132
- exit 0
133
+ return 0
133
134
fi
134
135
135
136
if [ -n " ${help} " ]; then
@@ -169,15 +170,15 @@ this situation by first switching HEAD to <alias>'s target branch
169
170
if HEAD was currently set to <alias>.
170
171
171
172
EOF
172
- exit 0
173
+ return 0
173
174
fi
174
175
175
176
# Use the current branch by default.
176
177
if [ -z " ${branch} " ]; then
177
178
branch=$( git symbolic-ref -q HEAD)
178
179
if [ $? -ne 0 ]; then
179
180
stderr " Could not establish current HEAD."
180
- exit 1
181
+ return 1
181
182
fi
182
183
fi
183
184
@@ -191,13 +192,13 @@ symref=${symref##refs/heads/}
191
192
if [ -n " ${delete} " ]; then
192
193
if [ ! -f " ${git} /refs/heads/${symref} " ]; then
193
194
stderr " Symbolic reference refs/heads/${symref} does not exist."
194
- exit 1
195
+ return 1
195
196
fi
196
197
197
198
# Verify that it IS a symbolic reference
198
199
if ! git symbolic-ref " refs/heads/${symref} " > /dev/null; then
199
200
stderr " Error validating refs/heads/${symref} as symbolic reference."
200
- exit 1
201
+ return 1
201
202
fi
202
203
203
204
# If we currently have <symref> checked out, deleting it is bad
@@ -210,7 +211,7 @@ if [ -n "${delete}" ]; then
210
211
branch=$( git symbolic-ref -q HEAD)
211
212
if [ $? -ne 0 ]; then
212
213
stderr " Could not establish current HEAD."
213
- exit 1
214
+ return 1
214
215
fi
215
216
stdout " Switching HEAD to target branch ${branch} "
216
217
# By using git symbolic-ref HEAD to find the target ref
@@ -219,7 +220,7 @@ if [ -n "${delete}" ]; then
219
220
if ! git symbolic-ref HEAD " ${branch} " ; then
220
221
stderr " Error updating HEAD from ${symref} to ${branch} "
221
222
stderr " Aborting."
222
- exit 1
223
+ return 1
223
224
fi
224
225
fi
225
226
@@ -229,7 +230,7 @@ if [ -n "${delete}" ]; then
229
230
# the backwards-compatible command.
230
231
stdout " Deleting symbolic reference refs/heads/${symref} "
231
232
git update-ref -d --no-deref " refs/heads/${symref} "
232
- exit $?
233
+ return $?
233
234
fi
234
235
235
236
# Creating a new symbolic reference.
239
240
# the wrong way around (treating it like ln -s is a really bad idea).
240
241
if [ ! -f " ${git} /refs/heads/${branch} " ]; then
241
242
stderr " Target refs/heads/${branch} does not exist."
242
- exit 1
243
+ return 1
243
244
fi
244
245
if [ -f " ${git} /refs/heads/${symref} " ]; then
245
246
target=$( git symbolic-ref " refs/heads/${symref} " )
@@ -251,12 +252,12 @@ if [ -f "${git}/refs/heads/${symref}" ]; then
251
252
stderr " File refs/heads/${symref} already exists"
252
253
stderr " (and is not a symbolic reference!)"
253
254
fi
254
- exit 1
255
+ return 1
255
256
fi
256
257
if git show-ref --verify --heads --quiet " refs/heads/${symref} " ; then
257
258
# n.b. I'm pretty sure this is unreachable, given the previous block.
258
259
stderr " refs/heads/${symref} is a valid reference without a file!?"
259
- exit 1
260
+ return 1
260
261
fi
261
262
262
263
# The parameters are good.
@@ -266,6 +267,8 @@ if git symbolic-ref "refs/heads/${symref}" "refs/heads/${branch}"; then
266
267
stdout " ${symref} -> ${target## refs/ heads/ } "
267
268
else
268
269
stderr " Failed to create branch alias."
269
- exit 1
270
+ return 1
270
271
fi
272
+ }
271
273
274
+ git_branch_alias " $@ "
0 commit comments