@matheusbsbs / matheus-bagliano / commits / 6315472eed
Fork 0

fetch: report local storage errors in status table

Previously, if there was an error while storing a local tracking ref, the low-level functions would report an error, but fetch's status output wouldn't indicate any problem. E.g., imagine you have an old "refs/remotes/origin/foo/bar" but upstream has deleted "foo/bar" in favor of a new branch "foo". You would get output like this: error: there are still refs under 'refs/remotes/origin/foo' From $url_of_repo * [new branch] foo -> origin/foo With this patch, the output takes into account the status of updating the local ref: error: there are still refs under 'refs/remotes/origin/foo' From $url_of_repo ! [new branch] foo -> origin/foo (unable to update local ref) Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 26, 2008 at 23:59 UTC 6315472eed9ff5f594560ddfd592ea21c665fe96
1 file changed +24 -12
builtin-fetch.c
+24 -12
@@ -233,10 +233,12 @@ static int update_local_ref(struct ref *ref,
233
234 if (!is_null_sha1(ref->old_sha1) &&
235 !prefixcmp(ref->name, "refs/tags/")) {
236 - sprintf(display, "- %-*s %-*s -> %s",
236 + int r;
237 + r = s_update_ref("updating tag", ref, 0);
238 + sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '-',
239 SUMMARY_WIDTH, "[tag update]", REFCOL_WIDTH, remote,
238 - pretty_ref);
239 - return s_update_ref("updating tag", ref, 0);
240 + pretty_ref, r ? " (unable to update local ref)" : "");
241 + return r;
242 }
243
244 current = lookup_commit_reference_gently(ref->old_sha1, 1);
@@ -244,6 +246,7 @@ static int update_local_ref(struct ref *ref,
246 if (!current || !updated) {
247 const char *msg;
248 const char *what;
249 + int r;
250 if (!strncmp(ref->name, "refs/tags/", 10)) {
251 msg = "storing tag";
252 what = "[new tag]";
@@ -253,27 +256,36 @@ static int update_local_ref(struct ref *ref,
256 what = "[new branch]";
257 }
258
256 - sprintf(display, "* %-*s %-*s -> %s", SUMMARY_WIDTH, what,
257 - REFCOL_WIDTH, remote, pretty_ref);
258 - return s_update_ref(msg, ref, 0);
259 + r = s_update_ref(msg, ref, 0);
260 + sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '*',
261 + SUMMARY_WIDTH, what, REFCOL_WIDTH, remote, pretty_ref,
262 + r ? " (unable to update local ref)" : "");
263 + return r;
264 }
265
266 if (in_merge_bases(current, &updated, 1)) {
267 char quickref[83];
268 + int r;
269 strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
270 strcat(quickref, "..");
271 strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
266 - sprintf(display, " %-*s %-*s -> %s", SUMMARY_WIDTH, quickref,
267 - REFCOL_WIDTH, remote, pretty_ref);
268 - return s_update_ref("fast forward", ref, 1);
272 + r = s_update_ref("fast forward", ref, 1);
273 + sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : ' ',
274 + SUMMARY_WIDTH, quickref, REFCOL_WIDTH, remote,
275 + pretty_ref, r ? " (unable to update local ref)" : "");
276 + return r;
277 } else if (force || ref->force) {
278 char quickref[84];
279 + int r;
280 strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
281 strcat(quickref, "...");
282 strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
274 - sprintf(display, "+ %-*s %-*s -> %s (forced update)",
275 - SUMMARY_WIDTH, quickref, REFCOL_WIDTH, remote, pretty_ref);
276 - return s_update_ref("forced-update", ref, 1);
283 + r = s_update_ref("forced-update", ref, 1);
284 + sprintf(display, "%c %-*s %-*s -> %s (%s)", r ? '!' : '+',
285 + SUMMARY_WIDTH, quickref, REFCOL_WIDTH, remote,
286 + pretty_ref,
287 + r ? "unable to update local ref" : "forced update");
288 + return r;
289 } else {
290 sprintf(display, "! %-*s %-*s -> %s (non fast forward)",
291 SUMMARY_WIDTH, "[rejected]", REFCOL_WIDTH, remote,