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
24 *,-l|
*,--l|
*,--lo|
*,--loc|
*,--loca|
*,--local) use_local
=yes ;;
25 *,-s|
*,--s|
*,--sh|
*,--sha|
*,--shar|
*,--share|
*,--shared)
27 *,-q|
*,--quiet) quiet
=-q ;;
28 1,-u|
1,--upload-pack) usage
;;
31 upload_pack
="--exec=$1" ;;
39 # Turn the source into an absolute path if
43 if base
=$
(get_repo_base
"$repo"); then
51 (cd "$dir" && git-init-db
&& pwd)
55 # We do local magic only when the user tells us to.
56 case "$local,$use_local" in
58 ( cd "$repo/objects" ) ||
{
59 echo >&2 "-l flag seen but $repo is not local."
63 case "$local_shared" in
65 # See if we can hardlink and drop "l" if not.
66 sample_file
=$
(cd "$repo" && \
67 find objects
-type f
-print |
sed -e 1q
)
69 # objects directory should not be empty since we are cloning!
70 test -f "$repo/$sample_file" ||
exit
73 if ln "$repo/$sample_file" "$D/.git/objects/sample" 2>/dev
/null
77 rm -f "$D/.git/objects/sample" &&
79 find objects
-type f
-print |
80 cpio -puamd$l "$D/.git/" ||
exit 1
83 mkdir
-p "$D/.git/objects/info"
84 echo "$repo/objects" >"$D/.git/objects/info/alternates"
88 # Make a duplicate of refs and HEAD pointer
90 if test -f "$repo/HEAD"
94 tar Ccf
"$repo" - refs
$HEAD |
tar Cxf
"$D/.git" - ||
exit 1
99 rsync
$quiet -avz --ignore-existing "$repo/objects/" "$D/.git/objects/" &&
100 rsync
$quiet -avz --ignore-existing "$repo/refs/" "$D/.git/refs/"
103 git-clone-dumb-http
"$repo" "$D"
106 echo "Somebody should define smarter http server protocol" >&2
116 cd "$D" && case "$upload_pack" in
117 '') git-clone-pack
$quiet "$repo" ;;
118 *) git-clone-pack
$quiet "$upload_pack" "$repo" ;;
126 mkdir
-p "$D/.git/branches/" &&
127 rm -f "$D/.git/branches/origin" &&
128 echo "$repo" >"$D/.git/branches/origin"