diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-06-21 06:02:47 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-06-21 06:02:47 -0700 |
commit | 1623191be4ec91b3d2fb5ef85b1e77b7adef24af (patch) | |
tree | 04449ccec1fad6e41f38890511a3e57ba23f70aa /builtin | |
parent | 8718e875080767f2c8d06c55c3fb5a6dddf0e5a0 (diff) | |
parent | 0e9716e65e40883759082b35e90113d0d0c8f7a6 (diff) | |
download | git-1623191be4ec91b3d2fb5ef85b1e77b7adef24af.tar.gz git-1623191be4ec91b3d2fb5ef85b1e77b7adef24af.tar.xz |
Merge branch 'sm/branch-broken-ref'
* sm/branch-broken-ref:
branch: don't fail listing branches if one of the commits wasn't found
branch: exit status now reflects if branch listing finds an error
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/branch.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index f594af0b3..87976f092 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -257,9 +257,15 @@ static char *resolve_symref(const char *src, const char *prefix) return xstrdup(dst); } +struct append_ref_cb { + struct ref_list *ref_list; + int ret; +}; + static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { - struct ref_list *ref_list = (struct ref_list*)(cb_data); + struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data); + struct ref_list *ref_list = cb->ref_list; struct ref_item *newitem; struct commit *commit; int kind, i; @@ -293,8 +299,10 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags, commit = NULL; if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) { commit = lookup_commit_reference_gently(sha1, 1); - if (!commit) - return error("branch '%s' does not point at a commit", refname); + if (!commit) { + cb->ret = error("branch '%s' does not point at a commit", refname); + return 0; + } /* Filter with with_commit if specified */ if (!is_descendant_of(commit, ref_list->with_commit)) @@ -484,9 +492,10 @@ static void show_detached(struct ref_list *ref_list) } } -static void print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit) +static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit) { int i; + struct append_ref_cb cb; struct ref_list ref_list; memset(&ref_list, 0, sizeof(ref_list)); @@ -496,7 +505,9 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str ref_list.with_commit = with_commit; if (merge_filter != NO_FILTER) init_revisions(&ref_list.revs, NULL); - for_each_rawref(append_ref, &ref_list); + cb.ref_list = &ref_list; + cb.ret = 0; + for_each_rawref(append_ref, &cb); if (merge_filter != NO_FILTER) { struct commit *filter; filter = lookup_commit_reference_gently(merge_filter_ref, 0); @@ -527,6 +538,11 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str } free_ref_list(&ref_list); + + if (cb.ret) + error("some refs could not be read"); + + return cb.ret; } static void rename_branch(const char *oldname, const char *newname, int force) @@ -679,7 +695,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) if (delete) return delete_branches(argc, argv, delete > 1, kinds); else if (argc == 0) - print_ref_list(kinds, detached, verbose, abbrev, with_commit); + return print_ref_list(kinds, detached, verbose, abbrev, with_commit); else if (rename && (argc == 1)) rename_branch(head, argv[0], rename > 1); else if (rename && (argc == 2)) |