1#!/bin/sh 2# 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. 7 8usage() { 9echo>&2"* git clone [-l] <repo> <dir>" 10exit1 11} 12 13use_local=no 14while 15case"$#,$1"in 160,*)break;; 17*,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local) use_local=yes;; 18*,-*) usage ;; 19*)break;; 20esac 21do 22shift 23done 24 25repo="$1" 26dir="$2" 27mkdir"$dir"&& 28D=$( 29(cd"$dir"&& git-init-db&&pwd) 30) && 31test -d"$D"|| usage 32 33# We do local magic only when the user tells us to. 34case"$use_local"in 35yes) 36(cd"$repo/objects") || { 37 repo="$repo/.git" 38(cd"$repo/objects") || { 39echo>&2"-l flag seen but$repois not local." 40exit1 41} 42} 43 44# See if we can hardlink and drop "l" if not. 45 sample_file=$(cd"$repo"&& \ 46find objects -type f -print|sed-e1q) 47 48# objects directory should not be empty since we are cloning! 49test -f"$repo/$sample_file"||exit 50 51 l= 52ifln"$repo/$sample_file""$D/.git/objects/sample"2>/dev/null 53then 54 l=l 55fi&& 56rm-f"$D/.git/objects/sample"&& 57cp-r$l"$repo/objects""$D/.git/"||exit1 58 59# Make a duplicate of refs and HEAD pointer 60 HEAD= 61iftest -f"$repo/HEAD" 62then 63 HEAD=HEAD 64fi 65tar Ccf "$repo"- refs $HEAD|tar Cxf "$D/.git"- ||exit1 66exit0 67;; 68esac 69 70cd"$D"&& git clone-pack"$repo"