@matheusbsbs / matheus-bagliano / commits / f3cb169bc9
Fork 0

fetch: give a hint to the user when local refs fail to update

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 27, 2008 at 00:01 UTC f3cb169bc9822e39a3efe637602b829cb338a213
1 file changed +11 -4
builtin-fetch.c
+11 -4
@@ -181,9 +181,9 @@ static int s_update_ref(const char *action,
181 lock = lock_any_ref_for_update(ref->name,
182 check_old ? ref->old_sha1 : NULL, 0);
183 if (!lock)
184 - return 1;
184 + return 2;
185 if (write_ref_sha1(lock, ref->new_sha1, msg) < 0)
186 - return 1;
186 + return 2;
187 return 0;
188 }
189
@@ -294,7 +294,8 @@ static int update_local_ref(struct ref *ref,
294 }
295 }
296
297 -static int store_updated_refs(const char *url, struct ref *ref_map)
297 +static int store_updated_refs(const char *url, const char *remote_name,
298 + struct ref *ref_map)
299 {
300 FILE *fp;
301 struct commit *commit;
@@ -380,6 +381,10 @@ static int store_updated_refs(const char *url, struct ref *ref_map)
381 }
382 }
383 fclose(fp);
384 + if (rc & 2)
385 + error("some local refs could not be updated; try running\n"
386 + " 'git remote prune %s' to remove any old, conflicting "
387 + "branches", remote_name);
388 return rc;
389 }
390
@@ -450,7 +455,9 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
455 if (ret)
456 ret = transport_fetch_refs(transport, ref_map);
457 if (!ret)
453 - ret |= store_updated_refs(transport->url, ref_map);
458 + ret |= store_updated_refs(transport->url,
459 + transport->remote->name,
460 + ref_map);
461 transport_unlock_pack(transport);
462 return ret;
463 }