diff options
-rw-r--r-- | ref-filter.c | 7 | ||||
-rwxr-xr-x | t/t6300-for-each-ref.sh | 54 |
2 files changed, 53 insertions, 8 deletions
diff --git a/ref-filter.c b/ref-filter.c index 05a62914ca..2dc046ffb6 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2141,7 +2141,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru if (va->value < vb->value) cmp = -1; else if (va->value == vb->value) - cmp = cmp_fn(a->refname, b->refname); + cmp = 0; else cmp = 1; } @@ -2160,7 +2160,10 @@ static int compare_refs(const void *a_, const void *b_, void *ref_sorting) if (cmp) return cmp; } - return 0; + s = ref_sorting; + return s && s->ignore_case ? + strcasecmp(a->refname, b->refname) : + strcmp(a->refname, b->refname); } void ref_sorting_icase_all(struct ref_sorting *sorting, int flag) diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index b347bba087..abf34d6e8e 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -583,17 +583,59 @@ test_atom refs/tags/signed-long contents "subject line body contents $sig" -cat >expected <<EOF -$(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo -$(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master -EOF +test_expect_success 'set up multiple-sort tags' ' + for when in 100000 200000 + do + for email in user1 user2 + do + for ref in ref1 ref2 + do + GIT_COMMITTER_DATE="@$when +0000" \ + GIT_COMMITTER_EMAIL="$email@example.com" \ + git tag -m "tag $ref-$when-$email" \ + multi-$ref-$when-$email || return 1 + done + done + done +' test_expect_success 'Verify sort with multiple keys' ' - git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \ - refs/tags/bogo refs/tags/master > actual && + cat >expected <<-\EOF && + 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 + 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 + 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 + 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 + 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 + 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 + 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 + 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 + EOF + git for-each-ref \ + --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ + --sort=-refname \ + --sort=taggeremail \ + --sort=taggerdate \ + "refs/tags/multi-*" >actual && test_cmp expected actual ' +test_expect_success 'equivalent sorts fall back on refname' ' + cat >expected <<-\EOF && + 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 + 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 + 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 + 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 + 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 + 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 + 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 + 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 + EOF + git for-each-ref \ + --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ + --sort=taggerdate \ + "refs/tags/multi-*" >actual && + test_cmp expected actual +' test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' ' test_when_finished "git checkout master" && |