Skip to content

Commit 3b51222

Browse files
draenoggitster
authored andcommitted
for-each-ref: Fix sort with multiple keys
The linked list describing sort options was not correctly set up in opt_parse_sort. In the result, contrary to the documentation, only the last of multiple --sort options to git-for-each-ref was taken into account. This commit fixes it. Signed-off-by: Kacper Kornet <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 912072d commit 3b51222

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

builtin/for-each-ref.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,9 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
962962
if (!arg) /* should --no-sort void the list ? */
963963
return -1;
964964

965-
*sort_tail = s = xcalloc(1, sizeof(*s));
965+
s = xcalloc(1, sizeof(*s));
966+
s->next = *sort_tail;
967+
*sort_tail = s;
966968

967969
if (*arg == '-') {
968970
s->reverse = 1;

t/t6300-for-each-ref.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ cat >expected <<\EOF
461461
90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <[email protected]> refs/tags/bogo
462462
EOF
463463

464-
test_expect_failure 'Verify sort with multiple keys' '
464+
test_expect_success 'Verify sort with multiple keys' '
465465
git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
466466
refs/tags/bogo refs/tags/master > actual &&
467467
test_cmp expected actual

0 commit comments

Comments
 (0)