{"thread":{"id":"56488","subject":"git tag -h fatal error with global tag.sort config","startedAt":"2021-09-12T11:29:01Z","lastAt":"2021-10-18T05:24:32Z","messageCount":5,"participants":["Bagas Sanjaya","SZEDER Gábor","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"435628","messageId":"0daf6907-b472-a756-1240-4c78f8f4d37e@gmail.com","threadId":"56488","inReplyTo":null,"subject":"git tag -h fatal error with global tag.sort config","fromName":"Bagas Sanjaya","fromEmail":"bagasdotme@gmail.com","sentAt":"2021-09-12T11:28:54Z","receivedAt":"2021-09-12T11:29:01Z","isPatch":false,"sender":{"key":"bagasdotme@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40219486?v=4"},"body":"Hi,\n\nI stumbled on Debian bug report [1], and I can reproduce the bug.\n\nIn global config (~/.gitconfig), I set:\n\n```\n[tag]\n\tsort = creatordate\n```\n\nWhen I run `git tag -h` inside a Git repository (such as git.git), \ninstead of usage summary, I got:\n\n```\nfatal: not a git repository, but the field 'creatordate' requires access \nto object data\n```\n\nBut plain `git tag` works fine.\n\nThis bug occurs on v2.33.0 as well as version in the original bug report \n(v2.26.0-rc2) and v2.25.1.\n\n[1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=954811\n\n-- \nAn old man doll... just what I always wanted! - Clara\n"},{"id":"435645","messageId":"20210912132757.GC76263@szeder.dev","threadId":"56488","inReplyTo":"0daf6907-b472-a756-1240-4c78f8f4d37e@gmail.com","subject":"Re: git tag -h fatal error with global tag.sort config","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-09-12T13:27:57Z","receivedAt":"2021-09-12T13:28:03Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Sun, Sep 12, 2021 at 06:28:54PM +0700, Bagas Sanjaya wrote:\n> I stumbled on Debian bug report [1], and I can reproduce the bug.\n> \n> In global config (~/.gitconfig), I set:\n> \n> ```\n> [tag]\n> \tsort = creatordate\n> ```\n> \n> When I run `git tag -h` inside a Git repository (such as git.git), instead\n> of usage summary, I got:\n> \n> ```\n> fatal: not a git repository, but the field 'creatordate' requires access to\n> object data\n> ```\n> \n> But plain `git tag` works fine.\n> \n> This bug occurs on v2.33.0 as well as version in the original bug report\n> (v2.26.0-rc2) and v2.25.1.\n> \n> [1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=954811\n\nInteresting.  It bisects to 47bd3d0c14 (ref-filter: don't look for\nobjects when outside of a repository, 2018-11-14), which, based on the\nerror message, kind of makes sense, because 'git tag' uses the general\nref-filter sorting facility.  Now, even if 'git tag -h' is executed in\na repository, since 99caeed05d (Let 'git <command> -h' show usage\nwithout a git dir, 2009-11-09) run_builtin() special-cases the '-h'\noption and does not call setup_git_directory(), so cmd_tag() and\neverything invoked from within will mistakenly think that there is no\nrepository.  And cmd_tag() parses the config before parsing the\noptions (of course, otherwise command line options couldn't override\nthe config), so it hits this die() before parse_options would get a\nchange to act on the '-h' option.\n\nNow, 'git branch' uses the same ref-filter sorting, but the equivalent\n'git -c branch.sort=creatordate branch -h' command does show the usage\nas expected.  The relevant difference between cmd_branch() and\ncmd_tag() is that the former special-cases the '-h' option as well\njust before it would call git_config().  Doing the same in cmd_tag()\nlike in the patch below seems to fix this issue, but I'm not sure that\nthis is the right fix.\n\n\n  ---  >8  ---\n\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 065b6bf093..31b8cc4600 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -485,6 +485,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \n \tsetup_ref_filter_porcelain_msg();\n \n+\tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n+\t\tusage_with_options(git_tag_usage, options);\n+\n \tgit_config(git_tag_config, sorting_tail);\n \n \tmemset(&opt, 0, sizeof(opt));\n\n"},{"id":"435655","messageId":"YT5zrWVlplgE/PWJ@coredump.intra.peff.net","threadId":"56488","inReplyTo":"20210912132757.GC76263@szeder.dev","subject":"Re: git tag -h fatal error with global tag.sort config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-09-12T21:39:57Z","receivedAt":"2021-09-12T21:40:01Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Sep 12, 2021 at 03:27:57PM +0200, SZEDER Gábor wrote:\n\n> Interesting.  It bisects to 47bd3d0c14 (ref-filter: don't look for\n> objects when outside of a repository, 2018-11-14), which, based on the\n> error message, kind of makes sense, because 'git tag' uses the general\n> ref-filter sorting facility.  Now, even if 'git tag -h' is executed in\n> a repository, since 99caeed05d (Let 'git <command> -h' show usage\n> without a git dir, 2009-11-09) run_builtin() special-cases the '-h'\n> option and does not call setup_git_directory(), so cmd_tag() and\n> everything invoked from within will mistakenly think that there is no\n> repository.  And cmd_tag() parses the config before parsing the\n> options (of course, otherwise command line options couldn't override\n> the config), so it hits this die() before parse_options would get a\n> change to act on the '-h' option.\n> \n> Now, 'git branch' uses the same ref-filter sorting, but the equivalent\n> 'git -c branch.sort=creatordate branch -h' command does show the usage\n> as expected.  The relevant difference between cmd_branch() and\n> cmd_tag() is that the former special-cases the '-h' option as well\n> just before it would call git_config().  Doing the same in cmd_tag()\n> like in the patch below seems to fix this issue, but I'm not sure that\n> this is the right fix.\n> \n> \n>   ---  >8  ---\n> \n> diff --git a/builtin/tag.c b/builtin/tag.c\n> index 065b6bf093..31b8cc4600 100644\n> --- a/builtin/tag.c\n> +++ b/builtin/tag.c\n> @@ -485,6 +485,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n>  \n>  \tsetup_ref_filter_porcelain_msg();\n>  \n> +\tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n> +\t\tusage_with_options(git_tag_usage, options);\n> +\n>  \tgit_config(git_tag_config, sorting_tail);\n>  \n>  \tmemset(&opt, 0, sizeof(opt));\n\nI think part of the problem is that git_tag_config() is pretty eager to\nparse the ref format. You can similarly see:\n\n  $ git -c tag.sort=foobar tag -h\n  fatal: unknown field name: foobar\n\nIf git_tag_config() just kept strings, and then we later fed them to\na parser (when we knew they were needed), that would be an appropriate\ntime to bail.\n\nWe do something similar with verify_ref_format(); it is just a string\nuntil we know we are ready to use it. But here, the format that is being\nused for sorting gets fed early to parse_ref_sorting(). I guess it is a\nbit more complicated, because it is generating a linked list. But maybe\nit could generate a list of to-be-parsed entries, with a function like\nverify_sort_format() to validate them.\n\n-Peff\n"},{"id":"435690","messageId":"f6673745-a6da-60b5-0782-349b6b76608b@gmail.com","threadId":"56488","inReplyTo":"20210912132757.GC76263@szeder.dev","subject":"Re: git tag -h fatal error with global tag.sort config","fromName":"Bagas Sanjaya","fromEmail":"bagasdotme@gmail.com","sentAt":"2021-09-13T04:37:11Z","receivedAt":"2021-09-13T04:37:19Z","isPatch":false,"sender":{"key":"bagasdotme@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40219486?v=4"},"body":"On 12/09/21 20.27, SZEDER Gábor wrote:\n> Now, 'git branch' uses the same ref-filter sorting, but the equivalent\n> 'git -c branch.sort=creatordate branch -h' command does show the usage\n> as expected.  The relevant difference between cmd_branch() and\n> cmd_tag() is that the former special-cases the '-h' option as well\n> just before it would call git_config().  Doing the same in cmd_tag()\n> like in the patch below seems to fix this issue, but I'm not sure that\n> this is the right fix.\n\nAlso note: specifying the config above as local config (in .git/config) \ndoesn't trigger the error.\n\n-- \nAn old man doll... just what I always wanted! - Clara\n"},{"id":"438978","messageId":"cc1b7611-8ec1-db29-1678-f45ba08d9b68@gmail.com","threadId":"56488","inReplyTo":"20210912132757.GC76263@szeder.dev","subject":"Re: git tag -h fatal error with global tag.sort config","fromName":"Bagas Sanjaya","fromEmail":"bagasdotme@gmail.com","sentAt":"2021-10-18T05:24:26Z","receivedAt":"2021-10-18T05:24:32Z","isPatch":false,"sender":{"key":"bagasdotme@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40219486?v=4"},"body":"On 12/09/21 20.27, SZEDER Gábor wrote:\n> Interesting.  It bisects to 47bd3d0c14 (ref-filter: don't look for\n> objects when outside of a repository, 2018-11-14), which, based on the\n> error message, kind of makes sense, because 'git tag' uses the general\n> ref-filter sorting facility.  Now, even if 'git tag -h' is executed in\n> a repository, since 99caeed05d (Let 'git <command> -h' show usage\n> without a git dir, 2009-11-09) run_builtin() special-cases the '-h'\n> option and does not call setup_git_directory(), so cmd_tag() and\n> everything invoked from within will mistakenly think that there is no\n> repository.  And cmd_tag() parses the config before parsing the\n> options (of course, otherwise command line options couldn't override\n> the config), so it hits this die() before parse_options would get a\n> change to act on the '-h' option.\n> \n> Now, 'git branch' uses the same ref-filter sorting, but the equivalent\n> 'git -c branch.sort=creatordate branch -h' command does show the usage\n> as expected.  The relevant difference between cmd_branch() and\n> cmd_tag() is that the former special-cases the '-h' option as well\n> just before it would call git_config().  Doing the same in cmd_tag()\n> like in the patch below seems to fix this issue, but I'm not sure that\n> this is the right fix.\n> \n> \n>    ---  >8  ---\n> \n> diff --git a/builtin/tag.c b/builtin/tag.c\n> index 065b6bf093..31b8cc4600 100644\n> --- a/builtin/tag.c\n> +++ b/builtin/tag.c\n> @@ -485,6 +485,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n>   \n>   \tsetup_ref_filter_porcelain_msg();\n>   \n> +\tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n> +\t\tusage_with_options(git_tag_usage, options);\n> +\n>   \tgit_config(git_tag_config, sorting_tail);\n>   \n>   \tmemset(&opt, 0, sizeof(opt));\n> \n\nSorry for long reply.\n\nPatch applied and usage help appears.\n\nBut when I do `./bin-wrappers/git tag -h`, I don't see `usage:` header, \nand instead show the help starting from `-F`.\n\n-- \nAn old man doll... just what I always wanted! - Clara\n"}]}