Skip to content

Commit

Permalink
fetch: give a hint to the user when local refs fail to update
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 30, 2008
1 parent 6315472 commit f3cb169
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f3cb169

Please sign in to comment.