summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorAaron Schrab <aaron@schrab.com>2013-04-09 18:22:00 -0400
committerJunio C Hamano <gitster@pobox.com>2013-04-09 15:40:00 -0700
commitb552b56df2c13885a67ca9ec9f76c21d3b7e2cde (patch)
tree5c6d062ab0f30792e6ec97e08d402f85299abd7d /builtin
parent0658569eb03e743ef46abd06abd9d0d81d53e72c (diff)
downloadgit-b552b56df2c13885a67ca9ec9f76c21d3b7e2cde.tar.gz
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/clone.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 0a1e0bf5a4..58fee9874f 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -232,11 +232,21 @@ static void strip_trailing_slashes(char *dir)
static int add_one_reference(struct string_list_item *item, void *cb_data)
{
char *ref_git;
+ const char *repo;
struct strbuf alternate = STRBUF_INIT;
- /* Beware: real_path() and mkpath() return static buffer */
+ /* Beware: read_gitfile(), real_path() and mkpath() return static buffer */
ref_git = xstrdup(real_path(item->string));
- if (is_directory(mkpath("%s/.git/objects", ref_git))) {
+
+ repo = read_gitfile(ref_git);
+ if (!repo)
+ repo = read_gitfile(mkpath("%s/.git", ref_git));
+ if (repo) {
+ free(ref_git);
+ ref_git = xstrdup(repo);
+ }
+
+ if (!repo && is_directory(mkpath("%s/.git/objects", ref_git))) {
char *ref_git_git = mkpathdup("%s/.git", ref_git);
free(ref_git);
ref_git = ref_git_git;