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] <repo> <dir>"
14 (cd "$1" && (cd .git
; pwd)) 2> /dev
/null
21 *,-l|
*,--l|
*,--lo|
*,--loc|
*,--loca|
*,--local) use_local
=yes ;;
29 # Turn the source into an absolute path if
33 if base
=$
(get_repo_base
"$repo"); then
41 (cd "$dir" && git-init-db
&& pwd)
45 # We do local magic only when the user tells us to.
46 case "$local,$use_local" in
48 ( cd "$repo/objects" ) ||
{
50 ( cd "$repo/objects" ) ||
{
51 echo >&2 "-l flag seen but $repo is not local."
56 # See if we can hardlink and drop "l" if not.
57 sample_file
=$
(cd "$repo" && \
58 find objects
-type f
-print |
sed -e 1q
)
60 # objects directory should not be empty since we are cloning!
61 test -f "$repo/$sample_file" ||
exit
64 if ln "$repo/$sample_file" "$D/.git/objects/sample" 2>/dev
/null
68 rm -f "$D/.git/objects/sample" &&
69 cp -r$l "$repo/objects" "$D/.git/" ||
exit 1
71 # Make a duplicate of refs and HEAD pointer
73 if test -f "$repo/HEAD"
77 tar Ccf
"$repo" - refs
$HEAD |
tar Cxf
"$D/.git" - ||
exit 1
82 cd "$D" && git clone-pack
"$repo"