git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 14/14] clone: give advice on how to resume a failed clone

From
Jeff King <peff@peff.net>
Date
Nov 10, 2011, 07:56 UTC
Message-ID
<20111110075654.GN27950@sigill.intra.peff.net>
In-Reply-To
<20111110074330.GA27925@sigill.intra.peff.net>

When clone fails, we usually delete the partial directory. However, if cloning was fetching a bundle, that is resumable and we should consider those results precious.

This patch detects when a partial bundle is present, preserves the directory, and gives the user some advice about how to resume.

Signed-off-by: Jeff King <peff@peff.net>
---
We could make "git clone ..." automatically resume, but I'm a little
nervous about that. I wrote a patch that did so, and it did work, but
there are a lot of little hiccups as we violate the assumption that the
directory didn't already exist (e.g., it writes multiple fetch refspec
lines to the config).

But more importantly, I really worry about destroying the safety valve of not overwriting an existing directory. Yes, we can check to see that it is a git directory and that it has a partially-downloaded bundle file. But that could also describe an existing git repo with unstaged changes. And you sure don't want to "checkout -f" over them.

So I'd rather at least start with giving the user some advice and having them explicitly say "yeah, I do want to resume this".

 builtin/clone.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index efe8b6c..c242e20 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -392,6 +392,36 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
 	return ret;
 }
 
+static int git_dir_is_resumable(const char *dir)
+{
+	const char *objects = mkpath("%s/objects", dir);
+	DIR *dh = opendir(objects);
+	struct dirent *de;
+
+	if (!dh)
+		return 0;
+
+	while ((de = readdir(dh))) {
+		if (!prefixcmp(de->d_name, "tmp_bundle_")) {
+			closedir(dh);
+			return 1;
+		}
+	}
+
+	closedir(dh);
+	return 0;
+}
+
+static void give_resume_advice(void)
+{
+	advise("Cloning failed, but partial results were saved.");
+	advise("You can resume the fetch with:");
+	advise("  git fetch");
+	if (!option_bare)
+		advise("  git checkout %s",
+		       option_branch ? option_branch : "master");
+}
+
 static const char *junk_work_tree;
 static const char *junk_git_dir;
 static pid_t junk_pid;
@@ -402,6 +432,10 @@ static void remove_junk(void)
 	if (getpid() != junk_pid)
 		return;
 	if (junk_git_dir) {
+		if (git_dir_is_resumable(junk_git_dir)) {
+			give_resume_advice();
+			return;
+		}
 		strbuf_addstr(&sb, junk_git_dir);
 		remove_dir_recursively(&sb, 0);
 		strbuf_reset(&sb);
-- 
1.7.7.2.7.g9f96f
Previous: Jeff KingNext: Junio C Hamano
Message 18 of 23 in “resumable network bundles”
  1. 0/14 resumable network bundlesJeff King, Nov 10, 2011
  2. Jeff KingNov 10, 2011
  3. 01/14 t/lib-httpd: check for NO_CURLJeff King, Nov 10, 2011
  4. 02/14 http: turn off curl signalsJeff King, Nov 10, 2011
  5. Daniel StenbergNov 10, 2011
  6. Jeff KingNov 11, 2011
  7. 03/14 http: refactor http_request functionJeff King, Nov 10, 2011
  8. 04/14 http: add a public function for arbitrary-callback requestJeff King, Nov 10, 2011
  9. 05/14 remote-curl: use http callback for requesting refsJeff King, Nov 10, 2011
  10. 06/14 transport: factor out bundle to ref list conversionJeff King, Nov 10, 2011
  11. 07/14 bundle: add is_bundle_buf helperJeff King, Nov 10, 2011
  12. 08/14 remote-curl: free "discovery" objectJeff King, Nov 10, 2011
  13. 09/14 remote-curl: auto-detect bundles when fetching refsJeff King, Nov 10, 2011
  14. 10/14 remote-curl: try base $URL after $URL/info/refsJeff King, Nov 10, 2011
  15. 11/14 progress: allow pure-throughput progress metersJeff King, Nov 10, 2011
  16. 12/14 remote-curl: show progress for bundle downloadsJeff King, Nov 10, 2011
  17. 13/14 remote-curl: resume interrupted bundle transfersJeff King, Nov 10, 2011
  18. 14/14 clone: give advice on how to resume a failed cloneJeff King, Nov 10, 2011
  19. Junio C HamanoNov 10, 2011
  20. Jeff KingNov 11, 2011
  21. David Michael BarrNov 11, 2011
  22. Tay Ray ChuanNov 12, 2011
  23. Jeff KingNov 12, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.