path: root/builtin/clone.c
diff options
authorJeff King <>2013-03-25 20:26:27 (GMT)
committerJunio C Hamano <>2013-03-27 20:47:18 (GMT)
commit0433ad128c59f233046b3f8a68246ca3a8a77af8 (patch)
treef8d6980d69472867ced6b8d773aa3bcf69a33985 /builtin/clone.c
parent0aac7bb287645dd72ad8ad6b805128b8ff7f111f (diff)
clone: run check_everything_connected
When we fetch from a remote, we do a revision walk to make sure that what we received is connected to our existing history. We do not do the same check for clone, which should be able to check that we received an intact history graph. The upside of this patch is that it will make clone more resilient against propagating repository corruption. The downside is that we will now traverse "rev-list --objects --all" down to the roots, which may take some time (it is especially noticeable for a "--local --bare" clone). Note that we need to adjust t5710, which tries to make such a bogus clone. Rather than checking after the fact that our clone is bogus, we can simplify it to just make sure "git clone" reports failure. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/clone.c')
1 files changed, 26 insertions, 0 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 7d48ef3..eceaa74 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -23,6 +23,7 @@
#include "branch.h"
#include "remote.h"
#include "run-command.h"
+#include "connected.h"
* Overall FIXMEs:
@@ -485,12 +486,37 @@ static void write_followtags(const struct ref *refs, const char *msg)
+static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
+ struct ref **rm = cb_data;
+ struct ref *ref = *rm;
+ /*
+ * Skip anything missing a peer_ref, which we are not
+ * actually going to write a ref for.
+ */
+ while (ref && !ref->peer_ref)
+ ref = ref->next;
+ /* Returning -1 notes "end of list" to the caller. */
+ if (!ref)
+ return -1;
+ hashcpy(sha1, ref->old_sha1);
+ *rm = ref->next;
+ return 0;
static void update_remote_refs(const struct ref *refs,
const struct ref *mapped_refs,
const struct ref *remote_head_points_at,
const char *branch_top,
const char *msg)
+ const struct ref *rm = mapped_refs;
+ if (check_everything_connected(iterate_ref_map, 0, &rm))
+ die(_("remote did not send all necessary objects"));
if (refs) {
if (option_single_branch)