{"thread":{"id":"59996","subject":"receive.denyCurrentBranch=updateInstead won't update the repo","startedAt":"2023-07-17T20:26:41Z","lastAt":"2023-07-18T23:30:00Z","messageCount":9,"participants":["Adam Sinus Skawiński","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"479583","messageId":"CAGE71k3Ccm3hBrfNgXFqO9Zk0V9FkoskgD1ViJ6eSakxdBuqQQ@mail.gmail.com","threadId":"59996","inReplyTo":null,"subject":"receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Adam Sinus Skawiński","fromEmail":"adam.skawinski@sinpi.net","sentAt":"2023-07-17T20:26:26Z","receivedAt":"2023-07-17T20:26:41Z","isPatch":false,"sender":{"key":"adam.skawinski@sinpi.net","avatar":null},"body":"I'm using Git to push-to-checkout a website.\n\nThe receive.denyCurrentBranch=updateInstead option (set on the server\nrepo), according to the docs, should allow the push and do a checkout\non the worktree if it's clean, or just refuse the push if the worktree\nisn't clean. Instead, for me it allows the push, but doesn't update\nthe worktree - I have to `git checkout -f` on the remote shell after\neach push, even though the worktree is clean.\n\nNote: The `push-to-checkout` hook doesn't seem to run, either, even\nthough it's in the .git/hooks/push-to-checkout file, with +x rights as\nneeded. I made it output some lines and exit with code 1, so it should\nabort after producing the output - and yet the pushes come through.\nOther hooks, like `update`, work fine and can abort if they exit 1.\n\nSetup:\n\nMy client is 2.31.0.windows.1 (TortoiseGit)\nServer’s git is 2.39.1.\nMy remote is set as ssh://user@hostname.com/path.\n\nPlease advise what I can do to investigate further.\n\n-- \nAdam \"Sinus\" Skawiński\n"},{"id":"479584","messageId":"xmqqzg3ugt18.fsf@gitster.g","threadId":"59996","inReplyTo":"CAGE71k3Ccm3hBrfNgXFqO9Zk0V9FkoskgD1ViJ6eSakxdBuqQQ@mail.gmail.com","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-17T20:52:19Z","receivedAt":"2023-07-17T20:53:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Adam \\\"Sinus\\\" Skawiński\"  <adam.skawinski@sinpi.net> writes:\n\n> Note: The `push-to-checkout` hook doesn't seem to run, either, even\n> though it's in the .git/hooks/push-to-checkout file, with +x rights as\n> needed. I made it output some lines and exit with code 1, so it should\n> abort after producing the output - and yet the pushes come through.\n> Other hooks, like `update`, work fine and can abort if they exit 1.\n\nI have nothing to offer offhand, but have you compared on the server\nside your \"update\" and \"push-to-checkout\" hooks?  Even a simple typo\nof the filename \"push-to-checkout\" would make it untable to run ;-).\nSimilarly to the name of the configuration variable, which is rather\nlong and prone to be mistyped.  After staring at a problem for a\nlong time getting frustrated, I myself would miss such a trivial\nmistake, and would want to go back and double check just to be sure.\n\nIn fact, while trying to reproduce the problem with a simple pair of\nrepositories, I did manage to mistype denyCurrentBranch and saw that\nthe machinery not to kick in at all ;-).\n"},{"id":"479586","messageId":"xmqqfs5mgs8v.fsf@gitster.g","threadId":"59996","inReplyTo":"CAGE71k3Ccm3hBrfNgXFqO9Zk0V9FkoskgD1ViJ6eSakxdBuqQQ@mail.gmail.com","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-17T21:09:20Z","receivedAt":"2023-07-17T21:09:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Adam \\\"Sinus\\\" Skawiński\"  <adam.skawinski@sinpi.net> writes:\n\n> needed. I made it output some lines and exit with code 1, so it should\n> abort after producing the output - and yet the pushes come through.\n\nDid the output come back to your client side?  \"git push -v\" should\nshow.\n\nIf there is no need to update (i.e. after a successful push, you try\nto push the same thing), the hook would not even run, so you may need\nto rewind the \"server\" side while experimenting.\n"},{"id":"479588","messageId":"CAGE71k3c+CGT=42cfkh+2Z-BcvefojNwpzWfc_XHPkBK8psJfA@mail.gmail.com","threadId":"59996","inReplyTo":"CAGE71k2bdy2aYy7speu=OOStopgjzVNOPQ_-V-63aCURLibFWw@mail.gmail.com","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Adam Sinus Skawiński","fromEmail":"adam.skawinski@sinpi.net","sentAt":"2023-07-17T22:26:38Z","receivedAt":"2023-07-17T22:26:56Z","isPatch":false,"sender":{"key":"adam.skawinski@sinpi.net","avatar":null},"body":"(I seem to have responded privately to the helpful Junio C Hamano,\ninstead of to the list, sorry about that.)\n\nWell, there's progress. Indeed I must have borked something with the\nhook, as I can now confirm that the hook works and fails as intended.\n\nStill, local-to-server pushes fail to checkout on the server, without\nany indication as to why. The server clearly recognizes the\nupdateInstead option, as it runs the push-to-checkout hook, but then\nit silently fails to update the remote worktree.\n\nAny idea what could be causing this?\n\nPushing to ssh://*hostname*/home/uuuusername/domains/mywebsite.com\nEnumerating objects: 5, done.\nCounting objects: 100% (5/5), done.\nDelta compression using up to 8 threads\nCompressing objects: 100% (3/3), done.\nWriting objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.\nTotal 3 (delta 2), reused 0 (delta 0), pack-reused 0\nremote: HOOK UPDATE: 1=refs/heads/mywebsite\n2=650585f1c2abdbbd68de71acfb31b5d66ee1d0f3\n3=adc4a555cfc23e037ad026a405a13e7a468188c4 GITDIR=\nHOOK PUSH-TO-CHECKOUT 1=adc4a555cfc23e037ad026a405a13e7a468188c4 2= 3= GITDIR=\nTo ssh://*hostname*/home/uuuusername/domains/mywebsite.com\n650585f..adc4a55  mywebsite -> mywebsite\nupdating local tracking ref 'refs/remotes/myserver-mywebsite/mywebsite'\n\n-- \nAdam \"Sinus\" Skawiński\n"},{"id":"479613","messageId":"CAGE71k3tMOtyFVrmGW33RuQ3GufJg8X6ORKCwHQgg6RmXbRCQA@mail.gmail.com","threadId":"59996","inReplyTo":"CAGE71k3c+CGT=42cfkh+2Z-BcvefojNwpzWfc_XHPkBK8psJfA@mail.gmail.com","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Adam Sinus Skawiński","fromEmail":"adam.skawinski@sinpi.net","sentAt":"2023-07-18T22:20:04Z","receivedAt":"2023-07-18T22:20:23Z","isPatch":false,"sender":{"key":"adam.skawinski@sinpi.net","avatar":null},"body":"Correct me if I'm wrong, but I'm looking at receive-pack.c and can't\ngrasp one thing.\n\nIn receive-pack.c:1452-1453,\n> if (!invoked_hook)\n>   retval = push_to_deploy(sha1, &env, worktree->path);\n... push_to_deploy is reached only if... hook didn't get invoked?\n\nI have now re-tested and, indeed, once I got _rid_ of the hook\nentirely, deployment proceeded!\nSo, shouldn't that be a check for retval instead, perhaps..?\n\nOn Tue, 18 Jul 2023 at 00:26, Adam \"Sinus\" Skawiński\n<adam.skawinski@sinpi.net> wrote:\n>\n> (I seem to have responded privately to the helpful Junio C Hamano,\n> instead of to the list, sorry about that.)\n>\n> Well, there's progress. Indeed I must have borked something with the\n> hook, as I can now confirm that the hook works and fails as intended.\n>\n> Still, local-to-server pushes fail to checkout on the server, without\n> any indication as to why. The server clearly recognizes the\n> updateInstead option, as it runs the push-to-checkout hook, but then\n> it silently fails to update the remote worktree.\n>\n> Any idea what could be causing this?\n>\n> Pushing to ssh://*hostname*/home/uuuusername/domains/mywebsite.com\n> Enumerating objects: 5, done.\n> Counting objects: 100% (5/5), done.\n> Delta compression using up to 8 threads\n> Compressing objects: 100% (3/3), done.\n> Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.\n> Total 3 (delta 2), reused 0 (delta 0), pack-reused 0\n> remote: HOOK UPDATE: 1=refs/heads/mywebsite\n> 2=650585f1c2abdbbd68de71acfb31b5d66ee1d0f3\n> 3=adc4a555cfc23e037ad026a405a13e7a468188c4 GITDIR=\n> HOOK PUSH-TO-CHECKOUT 1=adc4a555cfc23e037ad026a405a13e7a468188c4 2= 3= GITDIR=\n> To ssh://*hostname*/home/uuuusername/domains/mywebsite.com\n> 650585f..adc4a55  mywebsite -> mywebsite\n> updating local tracking ref 'refs/remotes/myserver-mywebsite/mywebsite'\n>\n> --\n> Adam \"Sinus\" Skawiński\n\n\n\n-- \nAdam \"Sinus\" Skawiński\n"},{"id":"479614","messageId":"xmqqa5vsg8gp.fsf@gitster.g","threadId":"59996","inReplyTo":"CAGE71k3tMOtyFVrmGW33RuQ3GufJg8X6ORKCwHQgg6RmXbRCQA@mail.gmail.com","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-18T22:28:54Z","receivedAt":"2023-07-18T22:29:05Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Adam \\\"Sinus\\\" Skawiński\"  <adam.skawinski@sinpi.net> writes:\n\n> Correct me if I'm wrong, but I'm looking at receive-pack.c and can't\n> grasp one thing.\n>\n> In receive-pack.c:1452-1453,\n>> if (!invoked_hook)\n>>   retval = push_to_deploy(sha1, &env, worktree->path);\n> ... push_to_deploy is reached only if... hook didn't get invoked?\n\nCorrect.  The hook is responsible for both DECIDING if it wants to\ntouch/update the working tree, AND ACTUALLY UPDATING the working\ntree itself.\n\nAnd the entire point of the \"hook\" is that its update does not have\nto be just \"checkout the given commit's tree\", for which using the\ndefault push-to-deply is sufficient.  It is for those who want to do\nmore.\n"},{"id":"479617","messageId":"CAGE71k28Gao4xuR565qsLmPH02tVAdoCZPeuCjo7r9YZXWs82Q@mail.gmail.com","threadId":"59996","inReplyTo":"xmqqa5vsg8gp.fsf@gitster.g","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Adam Sinus Skawiński","fromEmail":"adam.skawinski@sinpi.net","sentAt":"2023-07-18T22:49:45Z","receivedAt":"2023-07-18T22:50:39Z","isPatch":false,"sender":{"key":"adam.skawinski@sinpi.net","avatar":null},"body":"Oh. Then it's different from the other hooks, which merely enhance or\nabort the default behaviour by returning non-zero! I hadn't thought of\nthat. The documentation is phrased in a way that made me assume \"This\nhook is to be used to override the default behaviour\" means overriding\nthe tree cleanliness checks, not replacing the whole deployment\nroutine, which - if a hook is in place - needs to be fully\nreimplemented in the hook.\n\nAll in all, I'm glad it works now. Thank you for the explanation, I\nshall bother you no more. :)\n\nOn Wed, 19 Jul 2023 at 00:29, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Adam \\\"Sinus\\\" Skawiński\"  <adam.skawinski@sinpi.net> writes:\n>\n> > Correct me if I'm wrong, but I'm looking at receive-pack.c and can't\n> > grasp one thing.\n> >\n> > In receive-pack.c:1452-1453,\n> >> if (!invoked_hook)\n> >>   retval = push_to_deploy(sha1, &env, worktree->path);\n> > ... push_to_deploy is reached only if... hook didn't get invoked?\n>\n> Correct.  The hook is responsible for both DECIDING if it wants to\n> touch/update the working tree, AND ACTUALLY UPDATING the working\n> tree itself.\n>\n> And the entire point of the \"hook\" is that its update does not have\n> to be just \"checkout the given commit's tree\", for which using the\n> default push-to-deply is sufficient.  It is for those who want to do\n> more.\n\n\n\n-- \nAdam \"Sinus\" Skawiński\n"},{"id":"479620","messageId":"xmqqh6q0esbd.fsf@gitster.g","threadId":"59996","inReplyTo":"CAGE71k28Gao4xuR565qsLmPH02tVAdoCZPeuCjo7r9YZXWs82Q@mail.gmail.com","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-18T23:03:02Z","receivedAt":"2023-07-18T23:03:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Adam \\\"Sinus\\\" Skawiński\"  <adam.skawinski@sinpi.net> writes:\n\n> Oh. Then it's different from the other hooks, which merely enhance or\n> abort the default behaviour by returning non-zero! I hadn't thought of\n> that.\n\nI do not know if it is all that different from others, but in any\ncase it is a clear sign that the documentation needs a bit more love\nto make sure that it will not lead new readers and users into the\nsame confusion.\n\nThanks.\n"},{"id":"479628","messageId":"CAGE71k0ZSLOF+XZTwKy4+7vOZ_u-SMwgsA=viraqrAnU_ed2fQ@mail.gmail.com","threadId":"59996","inReplyTo":"xmqqh6q0esbd.fsf@gitster.g","subject":"Re: receive.denyCurrentBranch=updateInstead won't update the repo","fromName":"Adam Sinus Skawiński","fromEmail":"adam.skawinski@sinpi.net","sentAt":"2023-07-18T23:29:40Z","receivedAt":"2023-07-18T23:30:00Z","isPatch":false,"sender":{"key":"adam.skawinski@sinpi.net","avatar":null},"body":"Glad to have pointed out a possible improvement. :)\n\nBy \"different from others\" I primarily meant that all the other hooks\n(save for fsmonitor-watchman, I guess) are safe to simply be \"echo\nHello world; exit 0\" as they don't REPLACE any functionality. This one\ndoes.\n\nPerhaps there's a need for \"pre-deploy\" / \"post-deploy\" hooks,\nensuring that it's a good time to deploy, maybe bringing a live\nwebsite into and out of maintenance mode after the hopefully brief\ndeployment..?\n\nOn Wed, 19 Jul 2023 at 01:03, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Adam \\\"Sinus\\\" Skawiński\"  <adam.skawinski@sinpi.net> writes:\n>\n> > Oh. Then it's different from the other hooks, which merely enhance or\n> > abort the default behaviour by returning non-zero! I hadn't thought of\n> > that.\n>\n> I do not know if it is all that different from others, but in any\n> case it is a clear sign that the documentation needs a bit more love\n> to make sure that it will not lead new readers and users into the\n> same confusion.\n>\n> Thanks.\n\n\n\n-- \nAdam \"Sinus\" Skawiński\n"}]}