99unset CDPATH
1010
1111usage () {
12- echo >&2 " Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-o <name>] [-n] <repo> [<dir>]"
12+ echo >&2 " Usage: $0 [--naked] [- l [-s]] [-q] [-u <upload-pack>] [-o <name>] [-n] <repo> [<dir>]"
1313 exit 1
1414}
1515
@@ -53,11 +53,15 @@ use_local=no
5353local_shared=no
5454no_checkout=
5555upload_pack=
56+ naked=
5657origin=origin
5758while
5859 case " $# ,$1 " in
5960 0,* ) break ;;
60- * ,-n) no_checkout=yes ;;
61+ * ,-n|* ,--no|* ,--no-|* ,--no-c|* ,--no-ch|* ,--no-che|* ,--no-chec|\
62+ * ,--no-check|* ,--no-checko|* ,--no-checkou|* ,--no-checkout)
63+ no_checkout=yes ;;
64+ * ,--na|* ,--nak|* ,--nake|* ,--naked) naked=yes ;;
6165 * ,-l|* ,--l|* ,--lo|* ,--loc|* ,--loca|* ,--local) use_local=yes ;;
6266 * ,-s|* ,--s|* ,--sh|* ,--sha|* ,--shar|* ,--share|* ,--shared)
6367 local_shared=yes; use_local=yes ;;
8185 shift
8286done
8387
88+ # --naked implies --no-checkout
89+ test -z " $naked " || no_checkout=yes
90+
8491# Turn the source into an absolute path if
8592# it is local
8693repo=" $1 "
@@ -95,10 +102,17 @@ dir="$2"
95102[ -z " $dir " ] && dir=$( echo " $repo " | sed -e ' s|/$||' -e ' s|:*/*\.git$||' -e ' s|.*/||g' )
96103[ -e " $dir " ] && echo " $dir already exists." && usage
97104mkdir -p " $dir " &&
98- D=$(
99- (cd " $dir " && git-init-db && pwd)
100- ) &&
101- test -d " $D " || usage
105+ D=$( cd " $dir " && pwd) &&
106+ case " $naked " in
107+ yes) GIT_DIR=" $D " ;;
108+ * ) GIT_DIR=" $D /.git" ;;
109+ esac && export GIT_DIR && git-init-db || usage
110+ case " $naked " in
111+ yes)
112+ GIT_DIR=" $D " ;;
113+ * )
114+ GIT_DIR=" $D /.git" ;;
115+ esac
102116
103117# We do local magic only when the user tells us to.
104118case " $local ,$use_local " in
@@ -118,21 +132,21 @@ yes,yes)
118132 test -f " $repo /$sample_file " || exit
119133
120134 l=
121- if ln " $repo /$sample_file " " $D /.git /objects/sample" 2> /dev/null
135+ if ln " $repo /$sample_file " " $GIT_DIR /objects/sample" 2> /dev/null
122136 then
123137 l=l
124138 fi &&
125- rm -f " $D /.git /objects/sample" &&
139+ rm -f " $GIT_DIR /objects/sample" &&
126140 cd " $repo " &&
127- find objects -depth -print | cpio -puamd$l " $D /.git /" || exit 1
141+ find objects -depth -print | cpio -puamd$l " $GIT_DIR /" || exit 1
128142 ;;
129143 yes)
130- mkdir -p " $D /.git /objects/info"
144+ mkdir -p " $GIT_DIR /objects/info"
131145 {
132146 test -f " $repo /objects/info/alternates" &&
133147 cat " $repo /objects/info/alternates" ;
134148 echo " $repo /objects"
135- } > " $D /.git /objects/info/alternates"
149+ } > " $GIT_DIR /objects/info/alternates"
136150 ;;
137151 esac
138152
@@ -143,37 +157,37 @@ yes,yes)
143157 HEAD=HEAD
144158 fi
145159 (cd " $repo " && tar cf - refs $HEAD ) |
146- (cd " $D /.git " && tar xf -) || exit 1
160+ (cd " $GIT_DIR " && tar xf -) || exit 1
147161 ;;
148162* )
149163 case " $repo " in
150164 rsync://* )
151165 rsync $quiet -av --ignore-existing \
152- --exclude info " $repo /objects/" " $D /.git /objects/" &&
166+ --exclude info " $repo /objects/" " $GIT_DIR /objects/" &&
153167 rsync $quiet -av --ignore-existing \
154- --exclude info " $repo /refs/" " $D /.git /refs/" || exit
168+ --exclude info " $repo /refs/" " $GIT_DIR /refs/" || exit
155169
156170 # Look at objects/info/alternates for rsync -- http will
157171 # support it natively and git native ones will do it on the
158172 # remote end. Not having that file is not a crime.
159173 rsync -q " $repo /objects/info/alternates" \
160- " $D /.git /TMP_ALT" 2> /dev/null ||
161- rm -f " $D /.git /TMP_ALT"
162- if test -f " $D /.git /TMP_ALT"
174+ " $GIT_DIR /TMP_ALT" 2> /dev/null ||
175+ rm -f " $GIT_DIR /TMP_ALT"
176+ if test -f " $GIT_DIR /TMP_ALT"
163177 then
164178 ( cd " $D " &&
165179 . git-parse-remote &&
166- resolve_alternates " $repo " < " ./.git /TMP_ALT" ) |
180+ resolve_alternates " $repo " < " $GIT_DIR /TMP_ALT" ) |
167181 while read alt
168182 do
169183 case " $alt " in ' bad alternate: ' * ) die " $alt " ;; esac
170184 case " $quiet " in
171185 ' ' ) echo >&2 " Getting alternate: $alt " ;;
172186 esac
173187 rsync $quiet -av --ignore-existing \
174- --exclude info " $alt " " $D /.git /objects" || exit
188+ --exclude info " $alt " " $GIT_DIR /objects" || exit
175189 done
176- rm -f " $D /.git /TMP_ALT"
190+ rm -f " $GIT_DIR /TMP_ALT"
177191 fi
178192 ;;
179193 http://* )
@@ -194,25 +208,25 @@ esac
194208
195209cd " $D " || exit
196210
197- if test -f " .git /HEAD"
211+ if test -f " $GIT_DIR /HEAD"
198212then
199213 head_points_at=` git-symbolic-ref HEAD`
200214 case " $head_points_at " in
201215 refs/heads/* )
202216 head_points_at=` expr " $head_points_at " : ' refs/heads/\(.*\)' `
203- mkdir -p .git /remotes &&
204- echo > .git /remotes/origin \
217+ mkdir -p " $GIT_DIR /remotes" &&
218+ echo > " $GIT_DIR /remotes/origin" \
205219 " URL: $repo
206220Pull: $head_points_at :$origin " &&
207221 git-update-ref " refs/heads/$origin " $( git-rev-parse HEAD) &&
208- find .git/ refs/heads -type f -print |
222+ (cd " $GIT_DIR " && find " refs/heads" -type f -print) |
209223 while read ref
210224 do
211- head=` expr " $ref " : ' .git/ refs/heads/\(.*\)' ` &&
225+ head=` expr " $ref " : ' refs/heads/\(.*\)' ` &&
212226 test " $head_points_at " = " $head " ||
213227 test " $origin " = " $head " ||
214228 echo " Pull: ${head} :${head} "
215- done >> .git /remotes/origin
229+ done >> " $GIT_DIR /remotes/origin"
216230 esac
217231
218232 case " $no_checkout " in
0 commit comments