1#!/bin/sh 2 3usage () { 4echo"usage:" $@ 5exit127 6} 7 8die () { 9echo $@ 10exit128 11} 12 13iftest$#-lt2||test$#-gt3 14then 15 usage "$0<repository> <new_workdir> [<branch>]" 16fi 17 18orig_git=$1 19new_workdir=$2 20branch=$3 21 22# want to make sure that what is pointed to has a .git directory ... 23test -d"$orig_git/.git"|| die "\"$orig_git\"is not a git repository!" 24 25# don't link to a workdir 26iftest -L"$orig_git/.git/config" 27then 28 die "\"$orig_git\"is a working directory only, please specify" \ 29"a complete repository." 30fi 31 32# make sure the the links use full paths 33orig_git=$(cd "$orig_git"; pwd) 34 35# create the workdir 36mkdir-p"$new_workdir/.git"|| die "unable to create\"$new_workdir\"!" 37 38# create the links to the original repo. explictly exclude index, HEAD and 39# logs/HEAD from the list since they are purely related to the current working 40# directory, and should not be shared. 41for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache 42do 43case$xin 44*/*) 45mkdir-p"$(dirname "$new_workdir/.git/$x")" 46;; 47esac 48ln-s"$orig_git/.git/$x""$new_workdir/.git/$x" 49done 50 51# now setup the workdir 52cd"$new_workdir" 53# copy the HEAD from the original repository as a default branch 54cp"$orig_git/.git/HEAD" .git/HEAD 55# checkout the branch (either the same as HEAD from the original repository, or 56# the one that was asked for) 57git checkout -f$branch