tag: teach -n to override tag.sort configuration
PATCH 1/1 tag: teach -n to override tag.sort configuration
From: Jacob Keller <[email protected]>
git tag -n will always fail if tag.sort is set to a sort other than the default "refname" setting. Teach git tag to have -n override the configuration setting when -n is used, instead of failing with
fatal: --sort and -n incompatible
since the user probably sets tag.sort once as a default and would expect -n to override this setting.
As a consequence, -n and --sort will always be incompatible now, even if the --sort is "--sort=refname" which is essentially a no-op and previously was acceptable. No sane user should be doing such.
Add a test to document that --sort and -n are incompatible. Add a further test to show that tag.sort should be ignored if -n is configured.
---
I wasn't sure who to Cc for this, since I wrote the tag.sort code. Noticed this when I tried to use -n option, and it kept failing. Maybe this isn't the best way to implement this. I could replace how we read tag.sort and grab it using git_config_get_string or something after we parse the command line options. But this seemed like the easiest way.
builtin/tag.c | 11 +++++++++-- t/t7004-tag.sh | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-)
builtin/tag.c +9 -2
@@ -33,6 +33,7 @@ static const char * const git_tag_usage[] = {#define REVERSE_SORT 0x8000static int tag_sort; +static int cmd_line_sort =0 ;struct tag_filter {const char **patterns;
@@ -559,6 +560,8 @@ static int parse_opt_sort(const struct option *opt, const char *arg, int unset) {int *sort = opt->value; + cmd_line_sort =1 ; +return parse_sort_string (NULL , arg, sort); }
@@ -647,8 +650,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix) copts.padding =2 ;run_column_filter (colopts, &copts); } -if (lines !=-1 && tag_sort) -die (_ ("--sort and -n are incompatible" )); +if (lines !=-1 ) { +if (cmd_line_sort) +die (_ ("--sort and -n are incompatible" )); +else + tag_sort =0 ; + } ret =list_tags (argv, lines ==-1 ?0 : lines, with_commit, tag_sort);if (column_active (colopts))stop_column_filter ();
t/t7004-tag.sh +15 -0
@@ -1392,6 +1392,21 @@ test_expect_success 'multiple --points-at are OR-ed together' ' test_cmp expect actual ' +test_expect_success 'listing tag with -n --sort=<sort> should fail' ' + test_must_fail git tag --sort=refname -n +' + +test_expect_success 'listing tag with -n and tag.sort must not fail' ' + echo "tag-one-line A msg" >expect && + git -c tag.sort="v:refname" tag -n1 -l | grep "^tag-one-line" >actual && + test_cmp expect actual && + echo "tag-lines tag line one" >expect && + echo " tag line two" >>expect && + echo " tag line three" >>expect && + git -c tag.sort="v:refname" tag -n3 -l | grep "^ *tag.line" >actual && + test_cmp expect actual +' + test_expect_success 'lexical sort' ' git tag foo1.3 && git tag foo1.6 &&
Signature · 1 line
2.5.0.280.g4aaba03