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

[PATCH 2/2] fetch: give a hint to the user when local refs fail to update

From
Jeff King <peff@peff.net>
Date
Jun 27, 2008, 04:01 UTC
Message-ID
<20080627040140.GB21382@sigill.intra.peff.net>
In-Reply-To
<20080627035747.GC7144@sigill.intra.peff.net>

There are basically two categories of update failures for local refs:

  1. problems outside of git, like disk full, bad
     permissions, etc.
  2. D/F conflicts on tracking branch ref names

In either case, there should already have been an error message. In case '1', hopefully enough information has already been given that the user can fix it. In the case of '2', we can hint that the user can clean up their tracking branch area by using 'git remote prune'.

Note that we don't actually know _which_ case we have, so the user will receive the hint in case 1, as well. In this case the suggestion won't do any good, but hopefully the user is smart enough to figure out that it's just a hint.

Signed-off-by: Jeff King <peff@peff.net>
---
Actually, I think there might be a third category, "bad ref format".
But that would only come from a malicious remote trying to send you a
badly formatted ref, so I think that is rare enough not to worry about
showing the extra hint there.
 builtin-fetch.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 7c16d38..97fdc51 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -181,9 +181,9 @@ static int s_update_ref(const char *action,
 	lock = lock_any_ref_for_update(ref->name,
 				       check_old ? ref->old_sha1 : NULL, 0);
 	if (!lock)
-		return 1;
+		return 2;
 	if (write_ref_sha1(lock, ref->new_sha1, msg) < 0)
-		return 1;
+		return 2;
 	return 0;
 }
 
@@ -294,7 +294,8 @@ static int update_local_ref(struct ref *ref,
 	}
 }
 
-static int store_updated_refs(const char *url, struct ref *ref_map)
+static int store_updated_refs(const char *url, const char *remote_name,
+		struct ref *ref_map)
 {
 	FILE *fp;
 	struct commit *commit;
@@ -380,6 +381,10 @@ static int store_updated_refs(const char *url, struct ref *ref_map)
 		}
 	}
 	fclose(fp);
+	if (rc & 2)
+		error("some local refs could not be updated; try running\n"
+		      " 'git remote prune %s' to remove any old, conflicting "
+		      "branches", remote_name);
 	return rc;
 }
 
@@ -450,7 +455,9 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
 	if (ret)
 		ret = transport_fetch_refs(transport, ref_map);
 	if (!ret)
-		ret |= store_updated_refs(transport->url, ref_map);
+		ret |= store_updated_refs(transport->url,
+				transport->remote->name,
+				ref_map);
 	transport_unlock_pack(transport);
 	return ret;
 }
-- 
1.5.6.1.79.g7b3a7.dirty
Previous: Jeff KingNext: Junio C Hamano
Message 9 of 13 in “bug related to branches using / in name”
  1. Simon Holm ThøgersenJun 26, 2008
  2. Jeff KingJun 27, 2008
  3. Jeff KingJun 27, 2008
  4. Simon Holm ThøgersenJun 27, 2008
  5. Jeff KingJun 27, 2008
  6. fetch: report local storage errors in status tableJeff King, Jun 27, 2008
  7. Junio C HamanoJun 27, 2008
  8. Jeff KingJun 28, 2008
  9. 2/2 fetch: give a hint to the user when local refs fail to updateJeff King, Jun 27, 2008
  10. Junio C HamanoJun 27, 2008
  11. Jeff KingJun 28, 2008
  12. Junio C HamanoJun 28, 2008
  13. Jakub NarebskiJun 28, 2008

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.