3 # Copyright (c) 2005, Linus Torvalds
4 # Copyright (c) 2005, Junio C Hamano
6 # Clone a repository into a different directory that does not yet exist.
9 echo >&2 "* git clone [-l [-s]] [-q] [-u <upload-pack>] <repo> <dir>"
14 (cd "$1" && (cd .git
; pwd)) 2> /dev
/null
17 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
22 # $1 = Remote, $2 = Local
23 curl
-nsf $curl_extra_args "$1" >"$2"
27 # $1 - remote, $2 - local
29 clone_tmp
='.git/clone-tmp' &&
30 mkdir
-p "$clone_tmp" ||
exit 1
31 http_fetch
"$1/info/refs" "$clone_tmp/refs" &&
32 http_fetch
"$1/objects/info/packs" "$clone_tmp/packs" ||
{
33 echo >&2 "Cannot get remote repository information.
34 Perhaps git-update-server-info needs to be run there?"
44 idx
=`expr "$name" : '\(.*\)\.pack'`.idx
45 http_fetch
"$1/objects/pack/$name" ".git/objects/pack/$name" &&
46 http_fetch
"$1/objects/pack/$idx" ".git/objects/pack/$idx" &&
47 git-verify-pack
".git/objects/pack/$idx" ||
exit 1
48 done <"$clone_tmp/packs"
50 while read sha1 refname
52 name
=`expr "$refname" : 'refs/\(.*\)'` &&
53 git-http-pull
-v -a -w "$name" "$name" "$1/" ||
exit 1
54 done <"$clone_tmp/refs"
65 *,-l|
*,--l|
*,--lo|
*,--loc|
*,--loca|
*,--local) use_local
=yes ;;
66 *,-s|
*,--s|
*,--sh|
*,--sha|
*,--shar|
*,--share|
*,--shared)
68 *,-q|
*,--quiet) quiet
=-q ;;
69 1,-u|
1,--upload-pack) usage
;;
72 upload_pack
="--exec=$1" ;;
80 # Turn the source into an absolute path if
84 if base
=$
(get_repo_base
"$repo"); then
92 (cd "$dir" && git-init-db
&& pwd)
96 # We do local magic only when the user tells us to.
97 case "$local,$use_local" in
99 ( cd "$repo/objects" ) ||
{
100 echo >&2 "-l flag seen but $repo is not local."
104 case "$local_shared" in
106 # See if we can hardlink and drop "l" if not.
107 sample_file
=$
(cd "$repo" && \
108 find objects
-type f
-print |
sed -e 1q
)
110 # objects directory should not be empty since we are cloning!
111 test -f "$repo/$sample_file" ||
exit
114 if ln "$repo/$sample_file" "$D/.git/objects/sample" 2>/dev
/null
118 rm -f "$D/.git/objects/sample" &&
120 find objects
-type f
-print |
121 cpio -puamd$l "$D/.git/" ||
exit 1
124 mkdir
-p "$D/.git/objects/info"
126 test -f "$repo/objects/info/alternates" &&
127 cat "$repo/objects/info/alternates";
129 } >"$D/.git/objects/info/alternates"
133 # Make a duplicate of refs and HEAD pointer
135 if test -f "$repo/HEAD"
139 tar Ccf
"$repo" - refs
$HEAD |
tar Cxf
"$D/.git" - ||
exit 1
144 rsync
$quiet -avz --ignore-existing "$repo/objects/" "$D/.git/objects/" &&
145 rsync
$quiet -avz --ignore-existing "$repo/refs/" "$D/.git/refs/"
148 clone_dumb_http
"$repo" "$D"
151 cd "$D" && case "$upload_pack" in
152 '') git-clone-pack
$quiet "$repo" ;;
153 *) git-clone-pack
$quiet "$upload_pack" "$repo" ;;
161 mkdir
-p "$D/.git/remotes/" &&
162 rm -f "$D/.git/remotes/origin" &&
163 echo >"$D/.git/remotes/origin" \