{"thread":{"id":"58664","subject":"Soft bug: No chance to sign synthetic commits when using git subtree External","startedAt":"2022-10-21T07:52:32Z","lastAt":"2022-10-30T03:09:20Z","messageCount":3,"participants":["Adam Ryczkowski","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"465431","messageId":"CAEjZQXRsMaRYrskmpn5zBCrOt3xNOZ5shoVG82kjS7A3MZQtUQ@mail.gmail.com","threadId":"58664","inReplyTo":null,"subject":"Soft bug: No chance to sign synthetic commits when using git subtree External","fromName":"Adam Ryczkowski","fromEmail":"adam.ryczkowski@statystyka.net","sentAt":"2022-10-21T07:52:13Z","receivedAt":"2022-10-21T07:52:32Z","isPatch":false,"sender":{"key":"adam.ryczkowski@statystyka.net","avatar":null},"body":"Hello!\n\nI build a complex project \"Monorepo\" in an environment that mandates\ncode signing and monorepository philosophy. In my project I built\nseveral multi-purpose libraries. I track changes to those libraries in\na separate (local) repository, and use git subtree to merge them with\nthe Monorepo.\n\nGit does not have an option to sign the synthetic commits it generates\nwhen merging and pulling (and does ignore a policy `commit.gpgsign =\ntrue` in `.git/config` present in all repositories that are involved).\nIt is not that bad in `git subtree pull`, because I can do `git commit\n--amend -S --no-edit` on the last commit in the Monorepo, if I find\nthat the `git subtree pull` added a new commit.\n\nThe problem is with `git subtree push`, because it can add more than\none commit on a single invocation, forcing me to edit the history.\n\nDo you confirm this is an inconvenience bug (not a bug in the sense\nthat I get the repository corrupted)?\n\nI use git 2.38.1 on Ubuntu 20.04 64 bit\n\nSteps to reproduce:\n\n1. In the empty directory, in my example `/home/adam/gitbug`, create\nthe Monorepo:\n\n```\ngit init monorepo\n```\n\n2. Modify the `monorepo/.git/config` and add user's signing key and\n`commit.gpgsign=true`\n```\n[user]\nsigningkey = 1234561234567890\nemail = adam@statystyka.net\n[commit]\ngpgsign = true\n```\n\n3. Add a first commit and verify it gets signed.\n```\ncd monorepo\ngit commit -m \"Initial commit\" --allow-empty\ngit log --show-signature\ncd ..\n```\n\n4. Create a feature library \"lib1\":\n```\ngit init lib1\n```\n\n5. Modify the `lib1/.git/config` in a similar way as in Monorepo (step\n2) and add `receive.denyCurrentBranch=\nupdateInstead`\n```\n[user]\nsigningkey = 1234561234567890\nemail = adam@statystyka.net\n[commit]\ngpgsign = true\n[receive]\ndenyCurrentBranch = updateInstead\n```\n\n6. Add a first commit to lib1. Verify it is signed.\n```\ncd lib1\ntouch library_code.py\ngit add library_code.py\ngit commit -m \"Initial commit in lib1\"\ngit log --show-signature\ncd ..\n```\n\n7. Add lib1 as a subtree repository for Monorepo. Bug #1: The\nsignature of the subtree split commit IS NOT signed in the Monorepo.\n```\ncd monorepo\ngit remote add lib1 \"/home/adam/gitbug/lib1\"\ngit subtree add --prefix lib/lib1 lib1 master\ngit log --show-signature\n\nMerge: 6f06087 cef349f\nAuthor: Adam Ryczkowski <adam@statystyka.net>\nDate:   Thu Oct 20 09:35:27 2022 +0200\n\n    Add 'lib/lib1/' from commit 'cef349f0c89b7a506a5558750310d4cb3dc1f307'\n\n    git-subtree-dir: lib/lib1\n    git-subtree-mainline: 6f06087ac3d45d18d0651717388906902d6fa74b\n    git-subtree-split: cef349f0c89b7a506a5558750310d4cb3dc1f307\n\n```\n\n\n8. Sign the signature with git amend, and verify all the commits are signed:\n```\ngit commit -S --amend --no-edit\ngit log --show-signature\ncd ..\n```\n\n9. Make a commit in lib1 and verify all the commits are signed:\n```\ncd lib1\necho \"First line of code\" >> library_code.py\ngit commit -S -am \"Adds first line of code\"\ngit log --show-signature\ncd ..\n```\n\n10. Pull the changes in the lib1 to the Monorepo and verify all the\ncommits are signed:\n```\ncd monorepo\ngit subtree pull --prefix=lib/lib1 lib1 master\ngit log --show-signature\n```\n\n11. Modify the lib1 from inside the Monorepo and push the changes to\nthe subtree repository:\n```\necho \"Another line of code\" >> lib/lib1/library_code.py\ngit commit -S -am \"Adds another line of code\"\ngit log --show-signature\ngit subtree push --prefix=lib/lib1 lib1 master\ncd ..\n```\n\n12. Bug #2: In the lib1 the added commit \"Adds another line of code\"\nadded by the `git subtree push` IS NOT signed:\n```\ncd lib1\ngit log --show-signature\n```\n\n13. We need to walk around this bug otherwise the `git subtree pull`\nwill merge UNSIGNED commits.\n```\ngit commit -S --amend --no-edit\ngit log --show-signature\ncd ..\n```\n\n14. Go back to the lib1 and subtre pull the last subtree push we did,\notherwise our subsequent subtree push would end with `error: failed to\npush some refs to '/home/adam/tmp/gitbug/lib1`. If we hadn't manually\nsigned the last commit in lib1, this would pull that unsigned commit\nand cover it with ANOTHER unsigned commit caused by git subtree pull.\n```\ncd monorepo\ngit subtree pull --prefix=lib/lib1 lib1 master\ngit log --show-signature\n```\n\n15. Make a _second_ push to the lib1.\n```\necho \"Third line of code\" >> lib/lib1/library_code.py\ngit commit -S -am \"Adds third line of code\"\ngit log --show-signature # All is signed as expected\ngit subtree push --prefix=lib/lib1 lib1 master\ncd ..\n```\n\n16. Go to the lib1 and see a total mayhem: Three unsigned commits:\n```\ncd lib1\ngit log --show-signature\n```\nFirst two commits and a commit `2de16` are unsigned... The only way of\nfixing it is to do rewrite the history:\n\n\n```\ncommit b3c5429d2b3f7f4a3643bd577d1c4fd458238a22\nAuthor: Adam Ryczkowski <adam@statystyka.net>\nDate:   Thu Oct 20 12:43:18 2022 +0200\n\n    Adds third line of code\n\ncommit 53f1d874c542731b7fbb928877034332b57cc6e9\nMerge: 2de16ea d80a03e\nAuthor: Adam Ryczkowski <adam@statystyka.net>\nDate:   Thu Oct 20 12:42:51 2022 +0200\n\n    Merge commit 'd80a03ef0c1a82e29d94d89c8d7bd1d3f40e8691'\n\ncommit d80a03ef0c1a82e29d94d89c8d7bd1d3f40e8691\nPrimary key fingerprint: C076 B904 25BB FE0B 2718  697B 519B A799 293A 0D76\nAuthor: Adam Ryczkowski <adam@statystyka.net>\nDate:   Thu Oct 20 12:42:14 2022 +0200\n\n    Adds another line of code\n\ncommit 2de16ead1752dc661904099c34f6b09f495faa94\nAuthor: Adam Ryczkowski <adam@statystyka.net>\nDate:   Thu Oct 20 12:42:14 2022 +0200\n\n    Adds another line of code\n\ncommit 3d80e8b60eb65378e78fc1bf88e5eed2da703dab\nPrimary key fingerprint: C076 B904 25BB FE0B 2718  697B 519B A799 293A 0D76\nAuthor: Adam Ryczkowski <adam@statystyka.net>\nDate:   Thu Oct 20 12:42:00 2022 +0200\n\n    Adds first line of code\n\ncommit cef349f0c89b7a506a5558750310d4cb3dc1f307\nPrimary key fingerprint: C076 B904 25BB FE0B 2718  697B 519B A799 293A 0D76\nAuthor: Adam Ryczkowski <adam@statystyka.net>\nDate:   Thu Oct 20 09:34:57 2022 +0200\n\n    Initial commit in lib1\n```\n\nAdam Ryczkowski\n"},{"id":"466006","messageId":"CAEjZQXRB47GirGP53njjGMS1gm6ydUUuxOEaj_XQGkkE8wfo5g@mail.gmail.com","threadId":"58664","inReplyTo":"CAEjZQXRsMaRYrskmpn5zBCrOt3xNOZ5shoVG82kjS7A3MZQtUQ@mail.gmail.com","subject":"Fwd: Soft bug: No chance to sign synthetic commits when using git subtree External","fromName":"Adam Ryczkowski","fromEmail":"adam.ryczkowski@statystyka.net","sentAt":"2022-10-29T07:24:01Z","receivedAt":"2022-10-29T07:24:17Z","isPatch":false,"sender":{"key":"adam.ryczkowski@statystyka.net","avatar":null},"body":"A week passed and my last message did not get any follow ups\n(https://lore.kernel.org/git/CAEjZQXRsMaRYrskmpn5zBCrOt3xNOZ5shoVG82kjS7A3MZQtUQ@mail.gmail.com/T/#u).\nSince it is my first post to the vger.kernel.org and I am using gmail\n(which feels awkward in the context of this list), it lets me to\nbelieve that the message was filtered out from human eyes somehow.\n\nI would appreciate it if someone responds to this email, just to let\nme know that the initial message was delivered successfully. Thank\nyou.\n\nAdam\n"},{"id":"466040","messageId":"CAPig+cS5psokHgzV0Ri69Wi_Ba-iE9XW8uFeVybwnQuvLWomQw@mail.gmail.com","threadId":"58664","inReplyTo":"CAEjZQXRB47GirGP53njjGMS1gm6ydUUuxOEaj_XQGkkE8wfo5g@mail.gmail.com","subject":"Re: Soft bug: No chance to sign synthetic commits when using git subtree External","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2022-10-30T03:09:05Z","receivedAt":"2022-10-30T03:09:20Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Oct 29, 2022 at 3:32 AM Adam Ryczkowski\n<adam.ryczkowski@statystyka.net> wrote:\n> A week passed and my last message did not get any follow ups\n> (https://lore.kernel.org/git/CAEjZQXRsMaRYrskmpn5zBCrOt3xNOZ5shoVG82kjS7A3MZQtUQ@mail.gmail.com/T/#u).\n> Since it is my first post to the vger.kernel.org and I am using gmail\n> (which feels awkward in the context of this list), it lets me to\n> believe that the message was filtered out from human eyes somehow.\n>\n> I would appreciate it if someone responds to this email, just to let\n> me know that the initial message was delivered successfully. Thank\n> you.\n\nPresence of your initial message in the archive is indicative that it\nmade it to the list itself. That nobody responded is likely due to\nthere being very few git-subtree users on the list rather than any\nintentional lack of regard for your report. I have, myself, never used\nor looked at git-subtree, hence am of no help on the subject.\n"}]}