Skip to contentSkip to conversation

tag: support configuring --sort via .gitconfig

PATCH In review Jacob Keller 2 participants 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH v10 1/1 tag: support configuring --sort via .gitconfig

Add support for configuring default sort ordering for git tags. Command line option will override this configured value, using the exact same syntax.

---
Based on what's in Junio's tree, this patch includes some minor changes to fix up other non-error reporting changes included in previous versions. The other patches in his tree already match so we can leave them as they are.

 Documentation/config.txt  |  5 ++++ 
 Documentation/git-tag.txt |  5 +++-
 builtin/tag.c             | 68 ++++++++++++++++++++++++++++++++++-------------
 t/t7004-tag.sh            | 36 +++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 19 deletions(-)
Documentation/config.txt +5 -0
index 9f467d3820a4..9d4f249606b3 100644
@@ -2351,6 +2351,11 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+tag.sort::
+	This variable controls the sort ordering of tags when displayed by
+	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
+	value of this variable will be used as the default.
+
 tar.umask::
 	This variable can be used to restrict the permission bits of
 	tar archive entries.  The default is 0002, which turns off the
Documentation/git-tag.txt +4 -1
index b424a1bc48bb..320908369f06 100644
@@ -99,7 +99,9 @@ OPTIONS
 	Sort in a specific order. Supported type is "refname"
 	(lexicographic order), "version:refname" or "v:refname" (tag
 	names are treated as versions). Prepend "-" to reverse sort
-	order.
+	order. When this option is not given, the sort order defaults to the
+	value configured for the 'tag.sort' variable if it exists, or
+	lexicographic order otherwise. See linkgit:git-config[1].
 
 --column[=<options>]::
 --no-column::
@@ -317,6 +319,7 @@ include::date-formats.txt[]
 SEE ALSO
 --------
 linkgit:git-check-ref-format[1].
+linkgit:git-config[1].
 
 GIT
 ---
builtin/tag.c +50 -18

108 lines not on this page · raw message

t/t7004-tag.sh +36 -0
index 66010b0e7066..036665308841 100755
@@ -1423,6 +1423,42 @@ test_expect_success 'reverse lexical sort' '
 	test_cmp expect actual
 '
 
+test_expect_success 'configured lexical sort' '
+	git config tag.sort "v:refname" &&
+	git tag -l "foo*" >actual &&
+	cat >expect <<-\EOF &&
+	foo1.3
+	foo1.6
+	foo1.10
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'option override configured sort' '
+	git tag -l --sort=-refname "foo*" >actual &&
+	cat >expect <<-\EOF &&
+	foo1.6
+	foo1.3
+	foo1.10
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'invalid sort parameter on command line' '
+	test_must_fail git tag -l --sort=notvalid "foo*" >actual
+'
+
+test_expect_success 'invalid sort parameter in configuratoin' '
+	git config tag.sort "v:notvalid" &&
+	git tag -l "foo*" >actual &&
+	cat >expect <<-\EOF &&
+	foo1.10
+	foo1.3
+	foo1.6
+	EOF
+	test_cmp expect actual
+'
+
 run_with_limited_stack () {
 	(ulimit -s 64 && "$@")
 }
Signature · 1 line
2.0.1.475.g9b8d714
#2 lore raw
Quoted 1 line · Jacob E

Just a ping on the status of this patch?

I wrote that v10 needs to be picked up in the last "What's cooking", I think I did so already and pushed out the result somewhere between 'master' and 'pu'.