{"thread":{"id":"62513","subject":"Unexpected effect of log.showSignature on tformat:%H.","startedAt":"2024-11-19T09:23:59Z","lastAt":"2024-11-21T09:08:51Z","messageCount":5,"participants":["Niels Möller","Junio C Hamano","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"507575","messageId":"87cyirtweq.fsf@localhost","threadId":"62513","inReplyTo":null,"subject":"Unexpected effect of log.showSignature on tformat:%H.","fromName":"Niels Möller","fromEmail":"nisse@glasklarteknik.se","sentAt":"2024-11-19T09:17:33Z","receivedAt":"2024-11-19T09:23:59Z","isPatch":false,"sender":{"key":"nisse@glasklarteknik.se","avatar":null},"body":"I had expected the output of git show -s --format='tformat:%H' to be\nalways the same, and was surprised to find that scripts using this\nconstruction started to fail after I set log.showSignature true.\n\nSee filled out bugreport form below, including a repro script.\n\nRegards,\n/Niels Möller\n\nThank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n  git config --global log.showSignature true\n\n  I'm trying this out to get to see in git log which commits are\n  signed.\n\nWhat did you expect to happen? (Expected behavior)\n\n  That git show -s --format='tformat:%H' SOME_COMMIT\n  should still output the commit hash and nothing more. \n\nWhat happened instead? (Actual behavior)\n\n  I get an extra \"No signature\" line in the output (on stdout, not\n  stderr), when looking at a signed commit.\n\nWhat's different between what you expected and what actually happened?\n\n  The extra output line.\n\nAnything else you want to add:\n\nHere's a small script to reproduce the problem:\n\n-----8<-----\n#! /bin/sh\n\nset -eu\n\nexport GIT_CONFIG_GLOBAL=\"$(pwd)/git.config\"\ngit config --global log.showSignature true\n\ngit clone https://git.glasklar.is/glasklar/trust/audit-log.git\ncd audit-log\n\nhash=$(git show -s --format='tformat:%H' e36424e5688572c196d658a5df8c04c20de7606a)\n\necho \"Hash is: |$hash|\"\n-----8<-----\n\nThis is what it looks when I run it:\n\n-----8<-----\n$ ./repro.sh \nCloning into 'audit-log'...\nremote: Enumerating objects: 143, done.\nremote: Counting objects: 100% (8/8), done.\nremote: Compressing objects: 100% (8/8), done.\nremote: Total 143 (delta 1), reused 0 (delta 0), pack-reused 135 (from 1)\nReceiving objects: 100% (143/143), 347.00 MiB | 107.22 MiB/s, done.\nResolving deltas: 100% (59/59), done.\nerror: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification\nHash is: |No signature\ne36424e5688572c196d658a5df8c04c20de7606a|\n-----8<-----\n\nI would have expected the output\n\nHash is: |e36424e5688572c196d658a5df8c04c20de7606a|\n\n[System Info]\ngit version:\ngit version 2.39.5\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 6.1.0-26-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.112-1 (2024-09-30) x86_64\ncompiler info: gnuc: 12.2\nlibc info: glibc: 2.40\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n"},{"id":"507576","messageId":"xmqqmshvd0nn.fsf@gitster.g","threadId":"62513","inReplyTo":"87cyirtweq.fsf@localhost","subject":"Re: Unexpected effect of log.showSignature on tformat:%H.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-11-19T09:37:48Z","receivedAt":"2024-11-19T09:37:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Niels Möller <nisse@glasklarteknik.se> writes:\n\n> I had expected the output of git show -s --format='tformat:%H' to be\n> always the same, and was surprised to find that scripts using this\n> construction started to fail after I set log.showSignature true.\n\nIt is a bit unexpected, but knowing how the command options evolved,\nit is not all that surprising X-<.  If you are using --format, you\nare expected to use the %G placeholder and friends when you are\ninterested in signatures.  The --show-signature option is unaware of\nthe other formatting options like --pretty={short,oneline,fuller, so\nit is understandable (not \"expected\") what you are seeing.\n\n"},{"id":"507579","messageId":"878qtftu5e.fsf@localhost","threadId":"62513","inReplyTo":"xmqqmshvd0nn.fsf@gitster.g","subject":"Re: Unexpected effect of log.showSignature on tformat:%H.","fromName":"Niels Möller","fromEmail":"nisse@glasklarteknik.se","sentAt":"2024-11-19T10:06:21Z","receivedAt":"2024-11-19T10:06:28Z","isPatch":false,"sender":{"key":"nisse@glasklarteknik.se","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> It is a bit unexpected, but knowing how the command options evolved,\n> it is not all that surprising X-<.  If you are using --format, you\n> are expected to use the %G placeholder and friends when you are\n> interested in signatures.\n\nThe thing is, I'm generally interested in signatures when using git\ninteractively (that's why I enabled log.showSignature globally). But\nthen I have a scripted usecase that has a tag name, and needs to query\nthe corresponding commit hash, and in that context, I don't care about\nsignatures at all. The docs for git show say that %H expands to the\ncommit hash, which is exactly what I want. I didn't know about the %G\nformats, but after a quick look at the docs, I don't think they solves\nthat problem.\n\nI can work around this problem by using \"export\nGIT_CONFIG_GLOBAL=/dev/null\" in the script, which I guess might be\ngenerally good practice when using git in scripts? But I still think it\nwould be useful if there were an easy and reliable way to get from tag\nto commit hash, regardless of the user's config settings.\n\nRegards,\n/Niels Möller\n"},{"id":"507662","messageId":"Zz0NsaM-KFRXzBp6@tapette.crustytoothpaste.net","threadId":"62513","inReplyTo":"87cyirtweq.fsf@localhost","subject":"Re: Unexpected effect of log.showSignature on tformat:%H.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-11-19T22:14:09Z","receivedAt":"2024-11-19T22:14:18Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-11-19 at 09:17:33, Niels Möller wrote:\n> I had expected the output of git show -s --format='tformat:%H' to be\n> always the same, and was surprised to find that scripts using this\n> construction started to fail after I set log.showSignature true.\n> \n> See filled out bugreport form below, including a repro script.\n> \n> Regards,\n> /Niels Möller\n> \n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> \n>   git config --global log.showSignature true\n> \n>   I'm trying this out to get to see in git log which commits are\n>   signed.\n> \n> What did you expect to happen? (Expected behavior)\n> \n>   That git show -s --format='tformat:%H' SOME_COMMIT\n>   should still output the commit hash and nothing more.\n\ngit show is a porcelain, and it can be affected by options, such as\n`log.showSignature`.  If you want predictable behaviour, you need a\nplumbing command, whose behaviour isn't affected by configuration in\nthis way.  The equivalent to what you've requested is this:\n\n    git rev-list --no-commit-header -1 -s --format='tformat:%H' SOME_COMMIT\n\nI've confirmed that works correctly even if `log.showSignature` is set.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"507810","messageId":"874j41t0mi.fsf@localhost","threadId":"62513","inReplyTo":"Zz0NsaM-KFRXzBp6@tapette.crustytoothpaste.net","subject":"Re: Unexpected effect of log.showSignature on tformat:%H.","fromName":"Niels Möller","fromEmail":"nisse@glasklarteknik.se","sentAt":"2024-11-21T09:08:37Z","receivedAt":"2024-11-21T09:08:51Z","isPatch":false,"sender":{"key":"nisse@glasklarteknik.se","avatar":null},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> git show is a porcelain, and it can be affected by options, such as\n> `log.showSignature`.  If you want predictable behaviour, you need a\n> plumbing command, whose behaviour isn't affected by configuration in\n> this way.  The equivalent to what you've requested is this:\n>\n>     git rev-list --no-commit-header -1 -s --format='tformat:%H' SOME_COMMIT\n>\n> I've confirmed that works correctly even if `log.showSignature` is set.\n\nThanks! It seems the way to understand this is that git show can display\na bunch of different things, depending on configuration, and --tformat\naffects only one of potentially many output lines.\n\nSo git rev-list solves this problem. My script (which creates a file\narchive, in a reproducible fashion, from a list if git repos and (signed)\ntags) uses a few more git commands:\n\n  git clone\n  git ls-files\n  git -c gpg.ssh.allowedSignersFile=... tag --verify\n  git submodule\n\nOf these, it appears only ls-files is listed as a \"plumbing\" command. I\nwonder if I still need to stick to GIT_CONFIG_GLOBAL=/dev/null to avoid\nsurprises for the clone, tag and submodule commands?\n\nAny advice appreciated.\n\nRegards,\n/Niels\n"}]}