diff options
-rw-r--r-- | builtin/branch.c | 2 | ||||
-rw-r--r-- | builtin/for-each-ref.c | 2 | ||||
-rw-r--r-- | builtin/tag.c | 2 | ||||
-rw-r--r-- | ref-filter.c | 6 | ||||
-rw-r--r-- | ref-filter.h | 2 | ||||
-rwxr-xr-x | t/t6300-for-each-ref.sh | 40 |
6 files changed, 51 insertions, 3 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index 0c55f7f065..5f4e8f7aa7 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -711,7 +711,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) */ if (!sorting) sorting = ref_default_sorting(); - sorting->ignore_case = icase; + ref_sorting_icase_all(sorting, icase); print_ref_list(&filter, sorting, &format); print_columns(&output, colopts, NULL); string_list_clear(&output, 0); diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index e931be9ce4..312142923c 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -71,7 +71,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) if (!sorting) sorting = ref_default_sorting(); - sorting->ignore_case = icase; + ref_sorting_icase_all(sorting, icase); filter.ignore_case = icase; filter.name_patterns = argv; diff --git a/builtin/tag.c b/builtin/tag.c index 02f6bd1279..8903c851ea 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -465,7 +465,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) } if (!sorting) sorting = ref_default_sorting(); - sorting->ignore_case = icase; + ref_sorting_icase_all(sorting, icase); filter.ignore_case = icase; if (cmdmode == 'l') { int ret; diff --git a/ref-filter.c b/ref-filter.c index 5de616befe..05a62914ca 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2163,6 +2163,12 @@ static int compare_refs(const void *a_, const void *b_, void *ref_sorting) return 0; } +void ref_sorting_icase_all(struct ref_sorting *sorting, int flag) +{ + for (; sorting; sorting = sorting->next) + sorting->ignore_case = !!flag; +} + void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array) { QSORT_S(array->items, array->nr, compare_refs, sorting); diff --git a/ref-filter.h b/ref-filter.h index 85c8ebc3b9..87082cbf46 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -109,6 +109,8 @@ void ref_array_clear(struct ref_array *array); int verify_ref_format(struct ref_format *format); /* Sort the given ref_array as per the ref_sorting provided */ void ref_array_sort(struct ref_sorting *sort, struct ref_array *array); +/* Set the ignore_case flag for all elements of a sorting list */ +void ref_sorting_icase_all(struct ref_sorting *sorting, int flag); /* Based on the given format and quote_style, fill the strbuf */ int format_ref_array_item(struct ref_array_item *info, const struct ref_format *format, diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 97bfbee6e8..b347bba087 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -828,4 +828,44 @@ test_expect_success 'for-each-ref --ignore-case ignores case' ' test_cmp expect actual ' +test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' ' + # name refs numerically to avoid case-insensitive filesystem conflicts + nr=0 && + for email in a A b B + do + for subject in a A b B + do + GIT_COMMITTER_EMAIL="$email@example.com" \ + git tag -m "tag $subject" icase-$(printf %02d $nr) && + nr=$((nr+1))|| + return 1 + done + done && + git for-each-ref --ignore-case \ + --format="%(taggeremail) %(subject) %(refname)" \ + --sort=refname \ + --sort=subject \ + --sort=taggeremail \ + refs/tags/icase-* >actual && + cat >expect <<-\EOF && + <a@example.com> tag a refs/tags/icase-00 + <a@example.com> tag A refs/tags/icase-01 + <A@example.com> tag a refs/tags/icase-04 + <A@example.com> tag A refs/tags/icase-05 + <a@example.com> tag b refs/tags/icase-02 + <a@example.com> tag B refs/tags/icase-03 + <A@example.com> tag b refs/tags/icase-06 + <A@example.com> tag B refs/tags/icase-07 + <b@example.com> tag a refs/tags/icase-08 + <b@example.com> tag A refs/tags/icase-09 + <B@example.com> tag a refs/tags/icase-12 + <B@example.com> tag A refs/tags/icase-13 + <b@example.com> tag b refs/tags/icase-10 + <b@example.com> tag B refs/tags/icase-11 + <B@example.com> tag b refs/tags/icase-14 + <B@example.com> tag B refs/tags/icase-15 + EOF + test_cmp expect actual +' + test_done |