]> Pileus Git - ~andy/git/blobdiff - builtin/clone.c
Merge branch 'jk/git-dir-lookup'
[~andy/git] / builtin / clone.c
index 379cafa63faf2300c9564cde312c02a11c01f593..7559f62bc7a846ecb8f8d085e8bf5c3e6d4df2cd 100644 (file)
@@ -107,7 +107,7 @@ static const char *argv_submodule[] = {
 
 static char *get_repo_path(const char *repo, int *is_bundle)
 {
-       static char *suffix[] = { "/.git", ".git", "" };
+       static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
        static char *bundle_suffix[] = { ".bundle", "" };
        struct stat st;
        int i;
@@ -117,7 +117,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
                path = mkpath("%s%s", repo, suffix[i]);
                if (stat(path, &st))
                        continue;
-               if (S_ISDIR(st.st_mode)) {
+               if (S_ISDIR(st.st_mode) && is_git_directory(path)) {
                        *is_bundle = 0;
                        return xstrdup(absolute_path(path));
                } else if (S_ISREG(st.st_mode) && st.st_size > 8) {
@@ -232,9 +232,6 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
 {
        char *ref_git;
        struct strbuf alternate = STRBUF_INIT;
-       struct remote *remote;
-       struct transport *transport;
-       const struct ref *extra;
 
        /* Beware: real_path() and mkpath() return static buffer */
        ref_git = xstrdup(real_path(item->string));
@@ -249,14 +246,6 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
        strbuf_addf(&alternate, "%s/objects", ref_git);
        add_to_alternates_file(alternate.buf);
        strbuf_release(&alternate);
-
-       remote = remote_get(ref_git);
-       transport = transport_get(remote, ref_git);
-       for (extra = transport_get_remote_refs(transport); extra;
-            extra = extra->next)
-               add_extra_ref(extra->name, extra->old_sha1, 0);
-
-       transport_disconnect(transport);
        free(ref_git);
        return 0;
 }
@@ -472,11 +461,10 @@ static void write_remote_refs(const struct ref *local_refs)
        for (r = local_refs; r; r = r->next) {
                if (!r->peer_ref)
                        continue;
-               add_extra_ref(r->peer_ref->name, r->old_sha1, 0);
+               add_packed_ref(r->peer_ref->name, r->old_sha1);
        }
 
        pack_refs(PACK_REFS_ALL);
-       clear_extra_refs();
 }
 
 static void write_followtags(const struct ref *refs, const char *msg)
@@ -501,7 +489,6 @@ static void update_remote_refs(const struct ref *refs,
                               const char *msg)
 {
        if (refs) {
-               clear_extra_refs();
                write_remote_refs(mapped_refs);
                if (option_single_branch)
                        write_followtags(refs, msg);
@@ -814,28 +801,28 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        }
 
        refs = transport_get_remote_refs(transport);
-       mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;
 
-       /*
-        * transport_get_remote_refs() may return refs with null sha-1
-        * in mapped_refs (see struct transport->get_refs_list
-        * comment). In that case we need fetch it early because
-        * remote_head code below relies on it.
-        *
-        * for normal clones, transport_get_remote_refs() should
-        * return reliable ref set, we can delay cloning until after
-        * remote HEAD check.
-        */
-       for (ref = refs; ref; ref = ref->next)
-               if (is_null_sha1(ref->old_sha1)) {
-                       complete_refs_before_fetch = 0;
-                       break;
-               }
+       if (refs) {
+               mapped_refs = wanted_peer_refs(refs, refspec);
+               /*
+                * transport_get_remote_refs() may return refs with null sha-1
+                * in mapped_refs (see struct transport->get_refs_list
+                * comment). In that case we need fetch it early because
+                * remote_head code below relies on it.
+                *
+                * for normal clones, transport_get_remote_refs() should
+                * return reliable ref set, we can delay cloning until after
+                * remote HEAD check.
+                */
+               for (ref = refs; ref; ref = ref->next)
+                       if (is_null_sha1(ref->old_sha1)) {
+                               complete_refs_before_fetch = 0;
+                               break;
+                       }
 
-       if (!is_local && !complete_refs_before_fetch && refs)
-               transport_fetch_refs(transport, mapped_refs);
+               if (!is_local && !complete_refs_before_fetch)
+                       transport_fetch_refs(transport, mapped_refs);
 
-       if (refs) {
                remote_head = find_ref_by_name(refs, "HEAD");
                remote_head_points_at =
                        guess_remote_head(remote_head, mapped_refs, 0);
@@ -853,6 +840,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        }
        else {
                warning(_("You appear to have cloned an empty repository."));
+               mapped_refs = NULL;
                our_head_points_at = NULL;
                remote_head_points_at = NULL;
                remote_head = NULL;