{"thread":{"id":"40186","subject":"[PATCH] tag: teach -n to override tag.sort configuration","startedAt":"2015-08-26T21:15:00Z","lastAt":"2015-08-26T21:15:00Z","messageCount":1,"participants":["Jacob Keller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"268757","messageId":"1440623700-29324-1-git-send-email-jacob.e.keller@intel.com","threadId":"40186","inReplyTo":null,"subject":"[PATCH] tag: teach -n to override tag.sort configuration","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2015-08-26T21:15:00Z","receivedAt":"2015-08-26T21:15:00Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\ngit tag -n will always fail if tag.sort is set to a sort other than the\ndefault \"refname\" setting. Teach git tag to have -n override the\nconfiguration setting when -n is used, instead of failing with\n\nfatal: --sort and -n incompatible\n\nsince the user probably sets tag.sort once as a default and would expect\n-n to override this setting.\n\nAs a consequence, -n and --sort will always be incompatible now, even if\nthe --sort is \"--sort=refname\" which is essentially a no-op and\npreviously was acceptable. No sane user should be doing such.\n\nAdd a test to document that --sort and -n are incompatible. Add a\nfurther test to show that tag.sort should be ignored if -n is\nconfigured.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n\nI wasn't sure who to Cc for this, since I wrote the tag.sort code.\nNoticed this when I tried to use -n option, and it kept failing. Maybe\nthis isn't the best way to implement this. I could replace how we read\ntag.sort and grab it using git_config_get_string or something after we\nparse the command line options. But this seemed like the easiest way.\n\n builtin/tag.c  | 11 +++++++++--\n t/t7004-tag.sh | 15 +++++++++++++++\n 2 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 471d6b1ab884..83f94bd7f833 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -33,6 +33,7 @@ static const char * const git_tag_usage[] = {\n #define REVERSE_SORT    0x8000\n \n static int tag_sort;\n+static int cmd_line_sort = 0;\n \n struct tag_filter {\n \tconst char **patterns;\n@@ -559,6 +560,8 @@ static int parse_opt_sort(const struct option *opt, const char *arg, int unset)\n {\n \tint *sort = opt->value;\n \n+\tcmd_line_sort = 1;\n+\n \treturn parse_sort_string(NULL, arg, sort);\n }\n \n@@ -647,8 +650,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\t\tcopts.padding = 2;\n \t\t\trun_column_filter(colopts, &copts);\n \t\t}\n-\t\tif (lines != -1 && tag_sort)\n-\t\t\tdie(_(\"--sort and -n are incompatible\"));\n+\t\tif (lines != -1) {\n+\t\t\tif (cmd_line_sort)\n+\t\t\t\tdie(_(\"--sort and -n are incompatible\"));\n+\t\t\telse\n+\t\t\t\ttag_sort = 0;\n+\t\t}\n \t\tret = list_tags(argv, lines == -1 ? 0 : lines, with_commit, tag_sort);\n \t\tif (column_active(colopts))\n \t\t\tstop_column_filter();\ndiff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\nindex d31788cc6ce6..92a8f1b4670c 100755\n--- a/t/t7004-tag.sh\n+++ b/t/t7004-tag.sh\n@@ -1392,6 +1392,21 @@ test_expect_success 'multiple --points-at are OR-ed together' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'listing tag with -n --sort=<sort> should fail' '\n+\ttest_must_fail git tag --sort=refname -n\n+'\n+\n+test_expect_success 'listing tag with -n and tag.sort must not fail' '\n+\techo \"tag-one-line    A msg\" >expect &&\n+\tgit -c tag.sort=\"v:refname\" tag -n1 -l | grep \"^tag-one-line\" >actual &&\n+\ttest_cmp expect actual &&\n+\techo \"tag-lines       tag line one\" >expect &&\n+\techo \"    tag line two\" >>expect &&\n+\techo \"    tag line three\" >>expect &&\n+\tgit -c tag.sort=\"v:refname\" tag -n3 -l | grep \"^ *tag.line\" >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'lexical sort' '\n \tgit tag foo1.3 &&\n \tgit tag foo1.6 &&\n-- \n2.5.0.280.g4aaba03\n"}]}