remote rm/prune: print a message when writing packed-refs fails

Until v2.1.0-rc0~22^2~11 (refs.c: add an err argument to repack_without_refs, 2014-06-20), repack_without_refs forgot to provide an error message when commit_packed_refs fails. Even today, it only provides a message for callers that pass a non-NULL err parameter. Internal callers in refs.c pass non-NULL err but "git remote" does not. That means that "git remote rm" and "git remote prune" can fail without printing a message about why. Fix them by passing in a non-NULL err parameter and printing the returned message. This is the last caller to a ref handling function passing err == NULL. A later patch can drop support for err == NULL, avoiding such problems in the future. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ronnie Sahlberg committed Sep 11, 2014 at 08:42 UTC 2ebb49ca8ac34afb0ffe00e4bceac73e8c825ef1
1 file changed +11 -4
builtin/remote.c
+11 -4
@@ -749,13 +749,16 @@ static int mv(int argc, const char **argv)
749
750 static int remove_branches(struct string_list *branches)
751 {
752 + struct strbuf err = STRBUF_INIT;
753 const char **branch_names;
754 int i, result = 0;
755
756 branch_names = xmalloc(branches->nr * sizeof(*branch_names));
757 for (i = 0; i < branches->nr; i++)
758 branch_names[i] = branches->items[i].string;
758 - result |= repack_without_refs(branch_names, branches->nr, NULL);
759 + if (repack_without_refs(branch_names, branches->nr, &err))
760 + result |= error("%s", err.buf);
761 + strbuf_release(&err);
762 free(branch_names);
763
764 for (i = 0; i < branches->nr; i++) {
@@ -1332,9 +1335,13 @@ static int prune_remote(const char *remote, int dry_run)
1335 delete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));
1336 for (i = 0; i < states.stale.nr; i++)
1337 delete_refs[i] = states.stale.items[i].util;
1335 - if (!dry_run)
1336 - result |= repack_without_refs(delete_refs,
1337 - states.stale.nr, NULL);
1338 + if (!dry_run) {
1339 + struct strbuf err = STRBUF_INIT;
1340 + if (repack_without_refs(delete_refs, states.stale.nr,
1341 + &err))
1342 + result |= error("%s", err.buf);
1343 + strbuf_release(&err);
1344 + }
1345 free(delete_refs);
1346 }
1347