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] [-q] [-u <upload-pack>] <repo> <dir>"
14 (cd "$1" && (cd .git ; pwd)) 2> /dev/null
23 *,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local) use_local=yes ;;
24 *,-q|*,--quiet) quiet=-q ;;
25 1,-u|1,--upload-pack) usage ;;
28 upload_pack="--exec=$1" ;;
36 # Turn the source into an absolute path if
40 if base=$(get_repo_base "$repo"); then
48 (cd "$dir" && git-init-db && pwd)
52 # We do local magic only when the user tells us to.
53 case "$local,$use_local" in
55 ( cd "$repo/objects" ) || {
56 echo >&2 "-l flag seen but $repo is not local."
60 # See if we can hardlink and drop "l" if not.
61 sample_file=$(cd "$repo" && \
62 find objects -type f -print | sed -e 1q)
64 # objects directory should not be empty since we are cloning!
65 test -f "$repo/$sample_file" || exit
68 if ln "$repo/$sample_file" "$D/.git/objects/sample" 2>/dev/null
72 rm -f "$D/.git/objects/sample" &&
74 find objects -type f -print |
75 cpio -puamd$l "$D/.git/" || exit 1
77 # Make a duplicate of refs and HEAD pointer
79 if test -f "$repo/HEAD"
83 tar Ccf "$repo" - refs $HEAD | tar Cxf "$D/.git" - || exit 1
88 rsync $quiet -avz --ignore-existing "$repo/objects/" "$D/.git/objects/" &&
89 rsync $quiet -avz --ignore-existing "$repo/refs/" "$D/.git/refs/"
92 git-clone-dumb-http "$repo" "$D"
95 echo "Somebody should define smarter http server protocol" >&2
105 cd "$D" && case "$upload_pack" in
106 '') git-clone-pack $quiet "$repo" ;;
107 *) git-clone-pack $quiet "$upload_pack" "$repo" ;;
115 mkdir -p "$D/.git/branches/" &&
116 rm -f "$D/.git/branches/origin" &&
117 echo "$repo" >"$D/.git/branches/origin"