git-clone: define die() and use it.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Dmitry V. Levin committed
Oct 20, 2006 at 23:38 UTC
87b787ac77e0d8f81468dcba2a39c9d0287870c3
1 file changed
+24
-37
git-clone.sh
+24
-37
@@ -8,11 +8,15 @@
8
# See git-sh-setup why.
9
unset CDPATH
10
11
-usage() {
12
- echo >&2 "Usage: $0 [--template=<template_directory>] [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]"
11
+die() {
12
+ echo >&2 "$@"
13
exit 1
14
}
15
16
+usage() {
17
+ die "Usage: $0 [--template=<template_directory>] [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]"
18
+}
19
+
20
get_repo_base() {
21
(cd "$1" && (cd .git ; pwd)) 2> /dev/null
22
}
@@ -35,11 +39,9 @@ clone_dumb_http () {
39
"`git-repo-config --bool http.noEPSV`" = true ]; then
40
curl_extra_args="${curl_extra_args} --disable-epsv"
41
fi
38
- http_fetch "$1/info/refs" "$clone_tmp/refs" || {
39
- echo >&2 "Cannot get remote repository information.
42
+ http_fetch "$1/info/refs" "$clone_tmp/refs" ||
43
+ die "Cannot get remote repository information.
44
Perhaps git-update-server-info needs to be run there?"
41
- exit 1;
42
- }
45
while read sha1 refname
46
do
47
name=`expr "z$refname" : 'zrefs/\(.*\)'` &&
@@ -143,17 +145,12 @@ while
145
'')
146
usage ;;
147
*/*)
146
- echo >&2 "'$2' is not suitable for an origin name"
147
- exit 1
148
+ die "'$2' is not suitable for an origin name"
149
esac
149
- git-check-ref-format "heads/$2" || {
150
- echo >&2 "'$2' is not suitable for a branch name"
151
- exit 1
152
- }
153
- test -z "$origin_override" || {
154
- echo >&2 "Do not give more than one --origin options."
155
- exit 1
156
- }
150
+ git-check-ref-format "heads/$2" ||
151
+ die "'$2' is not suitable for a branch name"
152
+ test -z "$origin_override" ||
153
+ die "Do not give more than one --origin options."
154
origin_override=yes
155
origin="$2"; shift
156
;;
@@ -169,24 +166,19 @@ do
166
done
167
168
repo="$1"
172
-if test -z "$repo"
173
-then
174
- echo >&2 'you must specify a repository to clone.'
175
- exit 1
176
-fi
169
+test -n "$repo" ||
170
+ die 'you must specify a repository to clone.'
171
172
# --bare implies --no-checkout
173
if test yes = "$bare"
174
then
175
if test yes = "$origin_override"
176
then
183
- echo >&2 '--bare and --origin $origin options are incompatible.'
184
- exit 1
177
+ die '--bare and --origin $origin options are incompatible.'
178
fi
179
if test t = "$use_separate_remote"
180
then
188
- echo >&2 '--bare and --use-separate-remote options are incompatible.'
189
- exit 1
181
+ die '--bare and --use-separate-remote options are incompatible.'
182
fi
183
no_checkout=yes
184
fi
@@ -206,7 +198,7 @@ fi
198
dir="$2"
199
# Try using "humanish" part of source repo if user didn't specify one
200
[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
209
-[ -e "$dir" ] && echo "$dir already exists." && usage
201
+[ -e "$dir" ] && die "destination directory '$dir' already exists."
202
mkdir -p "$dir" &&
203
D=$(cd "$dir" && pwd) &&
204
trap 'err=$?; cd ..; rm -rf "$D"; exit $err' 0
@@ -233,7 +225,7 @@ then
225
cd reference-tmp &&
226
tar xf -)
227
else
236
- echo >&2 "$reference: not a local directory." && usage
228
+ die "reference repository '$reference' is not a local directory."
229
fi
230
fi
231
@@ -242,10 +234,8 @@ rm -f "$GIT_DIR/CLONE_HEAD"
234
# We do local magic only when the user tells us to.
235
case "$local,$use_local" in
236
yes,yes)
245
- ( cd "$repo/objects" ) || {
246
- echo >&2 "-l flag seen but $repo is not local."
247
- exit 1
248
- }
237
+ ( cd "$repo/objects" ) ||
238
+ die "-l flag seen but repository '$repo' is not local."
239
240
case "$local_shared" in
241
no)
@@ -307,18 +297,15 @@ yes,yes)
297
then
298
clone_dumb_http "$repo" "$D"
299
else
310
- echo >&2 "http transport not supported, rebuild Git with curl support"
311
- exit 1
300
+ die "http transport not supported, rebuild Git with curl support"
301
fi
302
;;
303
*)
304
case "$upload_pack" in
305
'') git-fetch-pack --all -k $quiet "$repo" ;;
306
*) git-fetch-pack --all -k $quiet "$upload_pack" "$repo" ;;
318
- esac >"$GIT_DIR/CLONE_HEAD" || {
319
- echo >&2 "fetch-pack from '$repo' failed."
320
- exit 1
321
- }
307
+ esac >"$GIT_DIR/CLONE_HEAD" ||
308
+ die "fetch-pack from '$repo' failed."
309
;;
310
esac
311
;;