@matheusbsbs / matheus-bagliano / commits / 8a1a120c55
Fork 0

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>

Junio C Hamano committed Jan 14, 2006 at 16:00 UTC 8a1a120c55a67c3193e136a06826585711717399
2 files changed +63 -27
Documentation/git-clone.txt
+23 -1
@@ -9,7 +9,7 @@ git-clone - Clones a repository.
9 SYNOPSIS
10 --------
11 [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>]
13 <repository> [<directory>]
14
15 DESCRIPTION
@@ -58,6 +58,12 @@ OPTIONS
58 -n::
59 No checkout of HEAD is performed after the clone is complete.
60
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 +
67 -o <name>::
68 Instead of using the branch name 'origin' to keep track
69 of the upstream repository, use <name> instead. Note
@@ -103,6 +109,22 @@ $ cd copy
109 $ git show-branch
110 ------------
111
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 +
128 Author
129 ------
130 Written by Linus Torvalds <torvalds@osdl.org>
git-clone.sh
+40 -26
@@ -9,7 +9,7 @@
9 unset CDPATH
10
11 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>]"
13 exit 1
14 }
15
@@ -53,11 +53,15 @@ use_local=no
53 local_shared=no
54 no_checkout=
55 upload_pack=
56 +naked=
57 origin=origin
58 while
59 case "$#,$1" in
60 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 ;;
65 *,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local) use_local=yes ;;
66 *,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared)
67 local_shared=yes; use_local=yes ;;
@@ -81,6 +85,9 @@ do
85 shift
86 done
87
88 +# --naked implies --no-checkout
89 +test -z "$naked" || no_checkout=yes
90 +
91 # Turn the source into an absolute path if
92 # it is local
93 repo="$1"
@@ -95,10 +102,17 @@ dir="$2"
102 [ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*/||g')
103 [ -e "$dir" ] && echo "$dir already exists." && usage
104 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
116
117 # We do local magic only when the user tells us to.
118 case "$local,$use_local" in
@@ -118,21 +132,21 @@ yes,yes)
132 test -f "$repo/$sample_file" || exit
133
134 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
136 then
137 l=l
138 fi &&
125 - rm -f "$D/.git/objects/sample" &&
139 + rm -f "$GIT_DIR/objects/sample" &&
140 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
142 ;;
143 yes)
130 - mkdir -p "$D/.git/objects/info"
144 + mkdir -p "$GIT_DIR/objects/info"
145 {
146 test -f "$repo/objects/info/alternates" &&
147 cat "$repo/objects/info/alternates";
148 echo "$repo/objects"
135 - } >"$D/.git/objects/info/alternates"
149 + } >"$GIT_DIR/objects/info/alternates"
150 ;;
151 esac
152
@@ -143,27 +157,27 @@ yes,yes)
157 HEAD=HEAD
158 fi
159 (cd "$repo" && tar cf - refs $HEAD) |
146 - (cd "$D/.git" && tar xf -) || exit 1
160 + (cd "$GIT_DIR" && tar xf -) || exit 1
161 ;;
162 *)
163 case "$repo" in
164 rsync://*)
165 rsync $quiet -av --ignore-existing \
152 - --exclude info "$repo/objects/" "$D/.git/objects/" &&
166 + --exclude info "$repo/objects/" "$GIT_DIR/objects/" &&
167 rsync $quiet -av --ignore-existing \
154 - --exclude info "$repo/refs/" "$D/.git/refs/" || exit
168 + --exclude info "$repo/refs/" "$GIT_DIR/refs/" || exit
169
170 # Look at objects/info/alternates for rsync -- http will
171 # support it natively and git native ones will do it on the
172 # remote end. Not having that file is not a crime.
173 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"
177 then
178 ( cd "$D" &&
179 . git-parse-remote &&
166 - resolve_alternates "$repo" <"./.git/TMP_ALT" ) |
180 + resolve_alternates "$repo" <"$GIT_DIR/TMP_ALT" ) |
181 while read alt
182 do
183 case "$alt" in 'bad alternate: '*) die "$alt";; esac
@@ -171,9 +185,9 @@ yes,yes)
185 '') echo >&2 "Getting alternate: $alt" ;;
186 esac
187 rsync $quiet -av --ignore-existing \
174 - --exclude info "$alt" "$D/.git/objects" || exit
188 + --exclude info "$alt" "$GIT_DIR/objects" || exit
189 done
176 - rm -f "$D/.git/TMP_ALT"
190 + rm -f "$GIT_DIR/TMP_ALT"
191 fi
192 ;;
193 http://*)
@@ -194,25 +208,25 @@ esac
208
209 cd "$D" || exit
210
197 -if test -f ".git/HEAD"
211 +if test -f "$GIT_DIR/HEAD"
212 then
213 head_points_at=`git-symbolic-ref HEAD`
214 case "$head_points_at" in
215 refs/heads/*)
216 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" \
219 "URL: $repo
220 Pull: $head_points_at:$origin" &&
221 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) |
223 while read ref
224 do
211 - head=`expr "$ref" : '.git/refs/heads/\(.*\)'` &&
225 + head=`expr "$ref" : 'refs/heads/\(.*\)'` &&
226 test "$head_points_at" = "$head" ||
227 test "$origin" = "$head" ||
228 echo "Pull: ${head}:${head}"
215 - done >>.git/remotes/origin
229 + done >>"$GIT_DIR/remotes/origin"
230 esac
231
232 case "$no_checkout" in