36
36
clone_tmp="$GIT_DIR/clone-tmp" &&
37
37
mkdir -p "$clone_tmp" || exit 1
38
38
if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
39
"`git-repo-config --bool http.noEPSV`" = true ]; then
39
"`git-config --bool http.noEPSV`" = true ]; then
40
40
curl_extra_args="${curl_extra_args} --disable-epsv"
42
42
http_fetch "$1/info/refs" "$clone_tmp/refs" ||
43
43
die "Cannot get remote repository information.
44
44
Perhaps git-update-server-info needs to be run there?"
45
test "z$quiet" = z && v=-v || v=
45
46
while read sha1 refname
47
48
name=`expr "z$refname" : 'zrefs/\(.*\)'` &&
53
yes,* | ,heads/* | ,tags/*) ;;
51
56
if test -n "$use_separate_remote" &&
52
57
branch_name=`expr "z$name" : 'zheads/\(.*\)'`
58
git-http-fetch -v -a -w "$tname" "$name" "$1/" || exit 1
63
git-http-fetch $v -a -w "$tname" "$sha1" "$1" || exit 1
59
64
done <"$clone_tmp/refs"
60
65
rm -fr "$clone_tmp"
61
66
http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
62
67
rm -f "$GIT_DIR/REMOTE_HEAD"
65
# Read git-fetch-pack -k output and store the remote branches.
67
use File::Path qw(mkpath);
68
use File::Basename qw(dirname);
69
my $git_dir = $ARGV[0];
70
my $use_separate_remote = $ARGV[1];
71
my $origin = $ARGV[2];
73
my $branch_top = ($use_separate_remote ? "remotes/$origin" : "heads");
77
my ($sha1, $name, $top) = @_;
78
$name = "$git_dir/refs/$top/$name";
79
mkpath(dirname($name));
85
open FH, "<", "$git_dir/CLONE_HEAD";
87
my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
88
next if ($name =~ /\^\173/);
89
if ($name eq "HEAD") {
90
open O, ">", "$git_dir/REMOTE_HEAD";
95
if ($name =~ s/^refs\/heads\///) {
96
store($sha1, $name, $branch_top);
99
if ($name =~ s/^refs\/tags\///) {
100
store($sha1, $name, $tag_top);
157
124
1,-u|1,--upload-pack) usage ;;
158
125
*,-u|*,--upload-pack)
160
upload_pack="--exec=$1" ;;
127
upload_pack="--upload-pack=$1" ;;
129
upload_pack=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
169
142
test -n "$repo" ||
170
143
die 'you must specify a repository to clone.'
172
# --bare implies --no-checkout
145
# --bare implies --no-checkout and --no-separate-remote
173
146
if test yes = "$bare"
175
148
if test yes = "$origin_override"
177
150
die '--bare and --origin $origin options are incompatible.'
179
if test t = "$use_separate_remote"
181
die '--bare and --use-separate-remote options are incompatible.'
186
156
if test -z "$origin"
209
179
GIT_DIR="$D/.git" ;;
210
esac && export GIT_DIR && git-init-db ${template+"$template"} || usage
180
esac && export GIT_DIR && git-init ${template+"$template"} || usage
212
182
if test -n "$reference"
214
185
if test -d "$reference"
216
187
if test -d "$reference/.git/objects"
218
reference="$reference/.git"
189
ref_git="$reference/.git"
190
elif test -d "$reference/objects"
220
reference=$(cd "$reference" && pwd)
221
echo "$reference/objects" >"$GIT_DIR/objects/info/alternates"
222
(cd "$reference" && tar cf - refs) |
223
(cd "$GIT_DIR/refs" &&
224
mkdir reference-tmp &&
195
if test -n "$ref_git"
197
ref_git=$(cd "$ref_git" && pwd)
198
echo "$ref_git/objects" >"$GIT_DIR/objects/info/alternates"
200
GIT_DIR="$ref_git" git for-each-ref \
201
--format='%(objectname) %(*objectname)'
206
git update-ref "refs/reference-tmp/$a" "$a"
208
git update-ref "refs/reference-tmp/$b" "$b"
228
211
die "reference repository '$reference' is not a local directory."
304
295
case "$upload_pack" in
305
'') git-fetch-pack --all -k $quiet "$repo" ;;
306
*) git-fetch-pack --all -k $quiet "$upload_pack" "$repo" ;;
296
'') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
297
*) git-fetch-pack --all -k $quiet "$upload_pack" $depth $no_progress "$repo" ;;
307
298
esac >"$GIT_DIR/CLONE_HEAD" ||
308
299
die "fetch-pack from '$repo' failed."
315
306
if test -f "$GIT_DIR/CLONE_HEAD"
317
308
# Read git-fetch-pack -k output and store the remote branches.
318
@@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" ||
309
if [ -n "$use_separate_remote" ]
311
branch_top="remotes/$origin"
322
destname="REMOTE_HEAD" ;;
324
destname="refs/$branch_top/${name#refs/heads/}" ;;
326
destname="refs/$tag_top/${name#refs/tags/}" ;;
330
git-update-ref -m "clone: from $repo" "$destname" "$sha1" ""
331
done < "$GIT_DIR/CLONE_HEAD"
324
336
if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
326
# Figure out which remote branch HEAD points at.
327
case "$use_separate_remote" in
328
'') remote_top=refs/heads ;;
329
*) remote_top="refs/remotes/$origin" ;;
338
# a non-bare repository is always in separate-remote layout
339
remote_top="refs/remotes/$origin"
332
340
head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
333
341
case "$head_sha1" in
365
# Write out remotes/$origin file, and update our "$head_points_at".
373
# Write out remote.$origin config, and update our "$head_points_at".
366
374
case "$head_points_at" in
368
mkdir -p "$GIT_DIR/remotes" &&
376
# Local default branch
369
377
git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
370
case "$use_separate_remote" in
371
t) origin_track="$remote_top/$head_points_at"
372
git-update-ref HEAD "$head_sha1" ;;
373
*) origin_track="$remote_top/$origin"
374
git-update-ref "refs/heads/$origin" "$head_sha1" ;;
376
echo >"$GIT_DIR/remotes/$origin" \
378
Pull: refs/heads/$head_points_at:$origin_track" &&
379
(cd "$GIT_DIR/$remote_top" && find . -type f -print) |
382
name=`expr "$dotslref" : './\(.*\)'`
383
if test "z$head_points_at" = "z$name"
387
if test "$use_separate_remote" = '' &&
388
test "z$origin" = "z$name"
392
echo "Pull: refs/heads/${name}:$remote_top/${name}"
393
done >>"$GIT_DIR/remotes/$origin" &&
394
case "$use_separate_remote" in
396
rm -f "refs/remotes/$origin/HEAD"
397
git-symbolic-ref "refs/remotes/$origin/HEAD" \
398
"refs/remotes/$origin/$head_points_at"
379
# Tracking branch for the primary branch at the remote.
380
origin_track="$remote_top/$head_points_at" &&
381
git-update-ref HEAD "$head_sha1" &&
384
git-config remote."$origin".url "$repo" &&
386
# Set up the mappings to track the remote branches.
387
git-config remote."$origin".fetch \
388
"+refs/heads/*:$remote_top/*" '^$' &&
389
rm -f "refs/remotes/$origin/HEAD"
390
git-symbolic-ref "refs/remotes/$origin/HEAD" \
391
"refs/remotes/$origin/$head_points_at" &&
393
git-config branch."$head_points_at".remote "$origin" &&
394
git-config branch."$head_points_at".merge "refs/heads/$head_points_at"
402
397
case "$no_checkout" in
404
test "z$quiet" = z && v=-v || v=
399
test "z$quiet" = z -a "z$no_progress" = z && v=-v || v=
405
400
git-read-tree -m -u $v HEAD HEAD