Skip to content

Commit 8a1a120

Browse files
author
Junio C Hamano
committed
clone: --naked option.
The new option --naked is to help creating a naked repository for public consumption. $ git clone -l -s --naked \ /pub/scm/.../torvalds/linux-2.6.git subproj-2.6.git is equivalent to this sequence: $ git clone -l -s -n /pub/scm/.../torvalds/linux-2.6.git temp $ mv temp/.git subproj-2.6.git $ rmdir temp Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 9e9b267 commit 8a1a120

File tree

2 files changed

+63
-27
lines changed

2 files changed

+63
-27
lines changed

Documentation/git-clone.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-clone - Clones a repository.
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git-clone' [-l [-s]] [-q] [-n] [-o <name>] [-u <upload-pack>]
12+
'git-clone' [-l [-s]] [-q] [-n] [--naked] [-o <name>] [-u <upload-pack>]
1313
<repository> [<directory>]
1414

1515
DESCRIPTION
@@ -58,6 +58,12 @@ OPTIONS
5858
-n::
5959
No checkout of HEAD is performed after the clone is complete.
6060

61+
--naked::
62+
Make a 'naked' GIT repository. That is, instead of
63+
creating `<directory>` and placing the administrative
64+
files in `<directory>/.git`, make the `<directory>`
65+
itself the `$GIT_DIR`. This implies `-n` option.
66+
6167
-o <name>::
6268
Instead of using the branch name 'origin' to keep track
6369
of the upstream repository, use <name> instead. Note
@@ -103,6 +109,22 @@ $ cd copy
103109
$ git show-branch
104110
------------
105111

112+
113+
Create a naked repository to publish your changes to the public::
114+
+
115+
------------
116+
$ git clone --naked -l /home/proj/.git /pub/scm/proj.git
117+
------------
118+
119+
120+
Create a repository on the kernel.org machine that borrows from Linus::
121+
+
122+
------------
123+
$ git clone --naked -l -s /pub/scm/.../torvalds/linux-2.6.git \
124+
/pub/scm/.../me/subsys-2.6.git
125+
------------
126+
127+
106128
Author
107129
------
108130
Written by Linus Torvalds <torvalds@osdl.org>

git-clone.sh

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
unset CDPATH
1010

1111
usage() {
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
5353
local_shared=no
5454
no_checkout=
5555
upload_pack=
56+
naked=
5657
origin=origin
5758
while
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 ;;
@@ -81,6 +85,9 @@ do
8185
shift
8286
done
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
8693
repo="$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
97104
mkdir -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.
104118
case "$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

195209
cd "$D" || exit
196210

197-
if test -f ".git/HEAD"
211+
if test -f "$GIT_DIR/HEAD"
198212
then
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
206220
Pull: $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

Comments
 (0)