Merge master.kernel.org:/pub/scm/linux/kernel/git/chrisw/git
[git/jnareb-git.git] / git-clone-script
blob4f80ade21cdd1ff82ddc2d3b9ba730a45952bc66
1 #!/bin/sh
3 # Copyright (c) 2005, Linus Torvalds
4 # Copyright (c) 2005, Junio C Hamano
5 #
6 # Clone a repository into a different directory that does not yet exist.
8 usage() {
9 echo >&2 "* git clone [-l] <repo> <dir>"
10 exit 1
13 use_local=no
14 while
15 case "$#,$1" in
16 0,*) break ;;
17 *,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local) use_local=yes ;;
18 *,-*) usage ;;
19 *) break ;;
20 esac
22 shift
23 done
25 repo="$1"
26 dir="$2"
27 mkdir "$dir" &&
28 D=$(
29 (cd "$dir" && git-init-db && pwd)
30 ) &&
31 test -d "$D" || usage
33 # We do local magic only when the user tells us to.
34 case "$use_local" in
35 yes)
36 ( cd "$repo/objects" ) || {
37 repo="$repo/.git"
38 ( cd "$repo/objects" ) || {
39 echo >&2 "-l flag seen but $repo is not local."
40 exit 1
44 # See if we can hardlink and drop "l" if not.
45 sample_file=$(cd "$repo" && \
46 find objects -type f -print | sed -e 1q)
48 # objects directory should not be empty since we are cloning!
49 test -f "$repo/$sample_file" || exit
52 if ln "$repo/$sample_file" "$D/.git/objects/sample" 2>/dev/null
53 then
54 l=l
55 fi &&
56 rm -f "$D/.git/objects/sample" &&
57 cp -r$l "$repo/objects" "$D/.git/" || exit 1
59 # Make a duplicate of refs and HEAD pointer
60 HEAD=
61 if test -f "$repo/HEAD"
62 then
63 HEAD=HEAD
65 tar Ccf "$repo" - refs $HEAD | tar Cxf "$D/.git" - || exit 1
66 exit 0
68 esac
70 cd "$D" && git clone-pack "$repo"