clone: Allow repo using gitfile as a reference
Try reading gitfile files when processing --reference options to clone. This will allow, among other things, using a submodule checked out with a recent version of git as a reference repository without requiring the user to have internal knowledge of submodule layout. Signed-off-by: Aaron Schrab <aaron@schrab.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Aaron Schrab committed
Apr 9, 2013 at 18:22 UTC
b552b56df2c13885a67ca9ec9f76c21d3b7e2cde
2 files changed
+25
-2
builtin/clone.c
+12
-2
@@ -232,11 +232,21 @@ static void strip_trailing_slashes(char *dir)
232
static int add_one_reference(struct string_list_item *item, void *cb_data)
233
{
234
char *ref_git;
235
+ const char *repo;
236
struct strbuf alternate = STRBUF_INIT;
237
237
- /* Beware: real_path() and mkpath() return static buffer */
238
+ /* Beware: read_gitfile(), real_path() and mkpath() return static buffer */
239
ref_git = xstrdup(real_path(item->string));
239
- if (is_directory(mkpath("%s/.git/objects", ref_git))) {
240
+
241
+ repo = read_gitfile(ref_git);
242
+ if (!repo)
243
+ repo = read_gitfile(mkpath("%s/.git", ref_git));
244
+ if (repo) {
245
+ free(ref_git);
246
+ ref_git = xstrdup(repo);
247
+ }
248
+
249
+ if (!repo && is_directory(mkpath("%s/.git/objects", ref_git))) {
250
char *ref_git_git = mkpathdup("%s/.git", ref_git);
251
free(ref_git);
252
ref_git = ref_git_git;
t/t5700-clone-reference.sh
+13
@@ -185,4 +185,17 @@ test_expect_success 'fetch with incomplete alternates' '
185
! grep " want $tag_object" "$U.K"
186
'
187
188
+test_expect_success 'clone using repo with gitfile as a reference' '
189
+ git clone --separate-git-dir=L A M &&
190
+ git clone --reference=M A N &&
191
+ echo "$base_dir/L/objects" >expected &&
192
+ test_cmp expected "$base_dir/N/.git/objects/info/alternates"
193
+'
194
+
195
+test_expect_success 'clone using repo pointed at by gitfile as reference' '
196
+ git clone --reference=M/.git A O &&
197
+ echo "$base_dir/L/objects" >expected &&
198
+ test_cmp expected "$base_dir/O/.git/objects/info/alternates"
199
+'
200
+
201
test_done