{"thread":{"id":"29390","subject":"post-update to stash after push to non-bare current branch","startedAt":"2012-01-18T17:53:47Z","lastAt":"2012-01-21T00:35:21Z","messageCount":10,"participants":["Neal Kreitzinger","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"182728","messageId":"jf70vc$kol$1@dough.gmane.org","threadId":"29390","inReplyTo":null,"subject":"post-update to stash after push to non-bare current branch","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2012-01-18T17:53:47Z","receivedAt":"2012-01-18T17:53:47Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"We use the worktree of git-repos as the webroot for virtual hosts assigned \nto ports so we can directly test changes to dev and test git-repos.  We have \nsome developers who want to develop offline on laptops and push to these \nnon-bare repos so they can test their changes.  My plan is to set \nreceive.denyCurrentBranch = warn, and then use the post-update hook on the \nremote non-bare to do a stash of the worktree and index.  My assumption is \nthat post-update hook only executes after a successful push.  Correct?  I \nonly want to stash the non-bare remote work-tree and index after a \nsuccessful push to it (effectively doing a git-reset --hard, but also \nkeeping any changes to the worktree/index of the non-bare remote as a safety \nin case someone does directly make uncommitted changes on the non-bare \nremote.)\n\nv/r,\nneal \n"},{"id":"182731","messageId":"4F171088.4080006@gmail.com","threadId":"29390","inReplyTo":"jf70vc$kol$1@dough.gmane.org","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Neal Kreitzinger","fromEmail":"nkreitzinger@gmail.com","sentAt":"2012-01-18T18:33:44Z","receivedAt":"2012-01-18T18:33:44Z","isPatch":false,"sender":{"key":"nkreitzinger@gmail.com","avatar":null},"body":"On 1/18/2012 11:53 AM, Neal Kreitzinger wrote:\n> We use the worktree of git-repos as the webroot for virtual hosts assigned\n> to ports so we can directly test changes to dev and test git-repos.  We have\n> some developers who want to develop offline on laptops and push to these\n> non-bare repos so they can test their changes.  My plan is to set\n> receive.denyCurrentBranch = warn, and then use the post-update hook on the\n> remote non-bare to do a stash of the worktree and index.  My assumption is\n> that post-update hook only executes after a successful push.  Correct?  I\n> only want to stash the non-bare remote work-tree and index after a\n> successful push to it (effectively doing a git-reset --hard, but also\n> keeping any changes to the worktree/index of the non-bare remote as a safety\n> in case someone does directly make uncommitted changes on the non-bare\n> remote.)\n>\nIf I manually run git-stash on the non-bare remote after pushing to it \nfrom a clone (receive.denyCurrentBranch=warn) it works as expected and \nleaves the worktree and index matching the new HEAD.  However, when \npost-update runs the git-stash is leaves the worktree dirty.  (git 1.7.1)\n\nv/r,\nneal\n"},{"id":"182733","messageId":"4F1714AD.4090706@gmail.com","threadId":"29390","inReplyTo":"4F171088.4080006@gmail.com","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Neal Kreitzinger","fromEmail":"nkreitzinger@gmail.com","sentAt":"2012-01-18T18:51:25Z","receivedAt":"2012-01-18T18:51:25Z","isPatch":false,"sender":{"key":"nkreitzinger@gmail.com","avatar":null},"body":"On 1/18/2012 12:33 PM, Neal Kreitzinger wrote:\n> On 1/18/2012 11:53 AM, Neal Kreitzinger wrote:\n>> We use the worktree of git-repos as the webroot for virtual hosts\n>> assigned\n>> to ports so we can directly test changes to dev and test git-repos. We\n>> have\n>> some developers who want to develop offline on laptops and push to these\n>> non-bare repos so they can test their changes. My plan is to set\n>> receive.denyCurrentBranch = warn, and then use the post-update hook on\n>> the\n>> remote non-bare to do a stash of the worktree and index. My assumption is\n>> that post-update hook only executes after a successful push. Correct? I\n>> only want to stash the non-bare remote work-tree and index after a\n>> successful push to it (effectively doing a git-reset --hard, but also\n>> keeping any changes to the worktree/index of the non-bare remote as a\n>> safety\n>> in case someone does directly make uncommitted changes on the non-bare\n>> remote.)\n>>\n> If I manually run git-stash on the non-bare remote after pushing to it\n> from a clone (receive.denyCurrentBranch=warn) it works as expected and\n> leaves the worktree and index matching the new HEAD. However, when\n> post-update runs the git-stash is leaves the worktree dirty. (git 1.7.1)\n>\nhooks/post-update was:\n\ngit stash save\necho \"worktree+index of non-bare remote current branch stashed for safety\"\n\nit created the stash and echoed the message. However, as stated earlier, \nthe worktree is still dirty.  I then manually run git-reset --hard and \nthat makes it clean (worktree, index, HEAD match).  However, if I add \nthat to the hook it still leaves dirty worktree (index matches HEAD, but \nworktree doesn't match index)\n\nhooks/post-update is:\n\ngit stash save\necho \"worktree+index of non-bare remote current branch stashed for safety\"\ngit reset --hard\necho \"git-reset --hard on current remote branch to ensure clean state\"\n\nmessage is echoed, but git-reset --hard does not appear to have really \nworked. (git 1.7.1)\n\nv/r,\nneal\n"},{"id":"182746","messageId":"7vwr8oljq7.fsf@alter.siamese.dyndns.org","threadId":"29390","inReplyTo":"4F1714AD.4090706@gmail.com","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-01-18T22:38:24Z","receivedAt":"2012-01-18T22:38:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Neal Kreitzinger <nkreitzinger@gmail.com> writes:\n\n> hooks/post-update is:\n>\n> git stash save\n> echo \"worktree+index of non-bare remote current branch stashed for safety\"\n> git reset --hard\n> echo \"git-reset --hard on current remote branch to ensure clean state\"\n>\n> message is echoed, but git-reset --hard does not appear to have really\n> worked. (git 1.7.1)\n\nHave you checked where in the filesystem hierarchy that script is run\n(hint: pwd)?\n\nAlso it is unclear why you keep saying \"stash\". What kind of changes are\nyou expecting to be saved to the stash? Will they be changes that are not\nsource controlled that you would rather not to see? In other words, after\nrunning \"stash\" every time somebody pushes and having accumulated many\nstash entries, when do you plan to pop these stashed changes?\n\nI would have expect that such a repository to reject a push if the working\ntree is dirty, and run checkout in post-update, though.\n"},{"id":"182759","messageId":"4F1764B9.90907@gmail.com","threadId":"29390","inReplyTo":"7vwr8oljq7.fsf@alter.siamese.dyndns.org","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Neal Kreitzinger","fromEmail":"nkreitzinger@gmail.com","sentAt":"2012-01-19T00:32:57Z","receivedAt":"2012-01-19T00:32:57Z","isPatch":false,"sender":{"key":"nkreitzinger@gmail.com","avatar":null},"body":"On 1/18/2012 4:38 PM, Junio C Hamano wrote:\n> Neal Kreitzinger<nkreitzinger@gmail.com>  writes:\n>\n>> hooks/post-update is:\n>>\n>> git stash save\n>> echo \"worktree+index of non-bare remote current branch stashed for safety\"\n>> git reset --hard\n>> echo \"git-reset --hard on current remote branch to ensure clean state\"\n>>\n>> message is echoed, but git-reset --hard does not appear to have really\n>> worked. (git 1.7.1)\n>\n> Have you checked where in the filesystem hierarchy that script is run\n> (hint: pwd)?\n>\necho pwd in post-update echoes /path/WORKTREE/.git in git-push stdout.\n\n> Also it is unclear why you keep saying \"stash\". What kind of changes are\n> you expecting to be saved to the stash? Will they be changes that are not\n> source controlled that you would rather not to see? In other words, after\n> running \"stash\" every time somebody pushes and having accumulated many\n> stash entries, when do you plan to pop these stashed changes?\n>\ngood point. rejection of dirty worktree is a cleaner safety.\n\n> I would have expect that such a repository to reject a push if the working\n> tree is dirty, and run checkout in post-update, though.\n>\n'git-checkout -f' works manually, but in post-update hook it leaves \nbehind dirty worktree, ie. index and HEAD match, but worktree still \nmatches HEAD@{1}.  This is the same undesired result git-stash and \ngit-reset --hard leave behind when executed in post-update hook.\n\nv/r,\nneal\n"},{"id":"182760","messageId":"7vboq0ld5e.fsf@alter.siamese.dyndns.org","threadId":"29390","inReplyTo":"4F1764B9.90907@gmail.com","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-01-19T01:00:29Z","receivedAt":"2012-01-19T01:00:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Neal Kreitzinger <nkreitzinger@gmail.com> writes:\n\n>> Have you checked where in the filesystem hierarchy that script is run\n>> (hint: pwd)?\n>>\n> echo pwd in post-update echoes /path/WORKTREE/.git in git-push stdout.\n> ...\n> 'git-checkout -f' works manually, but in post-update hook...\n\nStronger hint. Did you run \"git checkout -f\" in /path/WORKTREE/.git to\nback that \"works manually\" claim?\n"},{"id":"182815","messageId":"4F188FA2.1000209@gmail.com","threadId":"29390","inReplyTo":"7vboq0ld5e.fsf@alter.siamese.dyndns.org","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Neal Kreitzinger","fromEmail":"nkreitzinger@gmail.com","sentAt":"2012-01-19T21:48:18Z","receivedAt":"2012-01-19T21:48:18Z","isPatch":false,"sender":{"key":"nkreitzinger@gmail.com","avatar":null},"body":"On 1/18/2012 7:00 PM, Junio C Hamano wrote:\n> Neal Kreitzinger<nkreitzinger@gmail.com>  writes:\n>\n>>> Have you checked where in the filesystem hierarchy that script is run\n>>> (hint: pwd)?\n>>>\n>> echo pwd in post-update echoes /path/WORKTREE/.git in git-push stdout.\n>> ...\n>> 'git-checkout -f' works manually, but in post-update hook...\n>\n> Stronger hint. Did you run \"git checkout -f\" in /path/WORKTREE/.git to\n> back that \"works manually\" claim?\n\n(Manual behavior):\nIf pwd is WORKTREE/ then git-checkout has correct effect, ie. worktree, \nindex, and HEAD match.\nIf pwd is WORKTREE/.git/ then git-checkout complains 'must be run in a \nworktree' and has no effect.\n\n(post-update hook behavior):\nIf pwd is WORKTREE/.git/ then git-push verbage does not complain, and \ngit-checkout exits zero status but has incorrect effect, ie. index and \nHEAD match, but worktree matches HEAD@{1}.\nIf pwd is WORKTREE/ then git-push complains 'not a git repository', and \ngit-checkout exits non-zero status and has no effect, ie. worktree and \nindex match HEAD@{1}.\n\nEvidence:\n\n(post-update hook script):\nMYPWD=`pwd`\necho $MYPWD\npushd /home/neal/FSNMSTHTML\nMYPWD=`pwd`\necho $MYPWD\ngit checkout -f HEAD\nif [ $? -ne 0 ]; then\n   echo \"error on checkout!\"\nelse\n   echo \"checkout HEAD to non-bare remote current branch after push\"\nfi\necho $MYPWD\npopd\nMYPWD=`pwd`\necho $MYPWD\n\n(git-push verbage):\n$ git push origin HEAD\nCounting objects: 9, done.\nDelta compression using up to 8 threads.\nCompressing objects: 100% (5/5), done.\nWriting objects: 100% (5/5), 462 bytes, done.\nTotal 5 (delta 4), reused 0 (delta 0)\nUnpacking objects: 100% (5/5), done.\nremote: warning: updating the current branch\nremote: /home/neal/FSNMSTHTML/.git\nremote: ~/FSNMSTHTML ~/FSNMSTHTML/.git\nremote: /home/neal/FSNMSTHTML\nremote: fatal: Not a git repository: '.'\nremote: error on checkout!\nremote: /home/neal/FSNMSTHTML\nremote: ~/FSNMSTHTML/.git\nremote: /home/neal/FSNMSTHTML/.git\nTo file:///home/neal/FSNMSTHTML\n    cee9269..34dc5a9  HEAD -> master\n\nv/r,\nneal\n"},{"id":"182885","messageId":"4F1A0311.30502@gmail.com","threadId":"29390","inReplyTo":"4F188FA2.1000209@gmail.com","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Neal Kreitzinger","fromEmail":"nkreitzinger@gmail.com","sentAt":"2012-01-21T00:13:05Z","receivedAt":"2012-01-21T00:13:05Z","isPatch":false,"sender":{"key":"nkreitzinger@gmail.com","avatar":null},"body":"On 1/19/2012 3:48 PM, Neal Kreitzinger wrote:\n> On 1/18/2012 7:00 PM, Junio C Hamano wrote:\n>> Neal Kreitzinger<nkreitzinger@gmail.com> writes:\n>>\n>>>> Have you checked where in the filesystem hierarchy that script\n>>>> is run (hint: pwd)?\n>>>>\n>>> echo pwd in post-update echoes /path/WORKTREE/.git in git-push\n>>> stdout. ... 'git-checkout -f' works manually, but in post-update\n>>> hook...\n>>\n>> Stronger hint. Did you run \"git checkout -f\" in\n>> /path/WORKTREE/.git to back that \"works manually\" claim?\n>\n> (Manual behavior): If pwd is WORKTREE/ then git-checkout has correct\n> effect, ie. worktree, index, and HEAD match. If pwd is\n> WORKTREE/.git/ then git-checkout complains 'must be run in a\n> worktree' and has no effect.\n>\n> (post-update hook behavior): If pwd is WORKTREE/.git/ then git-push\n> verbage does not complain, and git-checkout exits zero status but\n> has incorrect effect, ie. index and HEAD match, but worktree matches\n> HEAD@{1}. If pwd is WORKTREE/ then git-push complains 'not a git\n> repository', and git-checkout exits non-zero status and has no\n> effect, ie. worktree and index match HEAD@{1}.\n>\n> Evidence:\n>\n> (post-update hook script): MYPWD=`pwd` echo $MYPWD pushd\n> /home/neal/FSNMSTHTML MYPWD=`pwd` echo $MYPWD git checkout -f HEAD\n> if [ $? -ne 0 ]; then echo \"error on checkout!\" else echo \"checkout\n> HEAD to non-bare remote current branch after push\" fi echo $MYPWD\n> popd MYPWD=`pwd` echo $MYPWD\n>\n> (git-push verbage): $ git push origin HEAD Counting objects: 9, done.\n> Delta compression using up to 8 threads. Compressing objects: 100%\n> (5/5), done. Writing objects: 100% (5/5), 462 bytes, done. Total 5\n> (delta 4), reused 0 (delta 0) Unpacking objects: 100% (5/5), done.\n> remote: warning: updating the current branch remote:\n> /home/neal/FSNMSTHTML/.git remote: ~/FSNMSTHTML ~/FSNMSTHTML/.git\n> remote: /home/neal/FSNMSTHTML remote: fatal: Not a git repository:\n> '.' remote: error on checkout! remote: /home/neal/FSNMSTHTML remote:\n> ~/FSNMSTHTML/.git remote: /home/neal/FSNMSTHTML/.git To\n> file:///home/neal/FSNMSTHTML cee9269..34dc5a9 HEAD -> master\n>\nTo get this to work I had to learn more about shell scripting and export\nthe GIT_WORK_TREE git environment variable.\n\n(post-update hook):\nexport GIT_WORK_TREE=/home/neal/FSNMSTHTML\ngit checkout -f HEAD\n\nfor more info see this stackoverflow thread\nhttp://stackoverflow.com/questions/6635018/reuse-git-work-tree-in-post-receive-hook-to-rm-a-few-files\n\nv/r,\nneal\n"},{"id":"182886","messageId":"7vr4ytdi54.fsf@alter.siamese.dyndns.org","threadId":"29390","inReplyTo":"4F1A0311.30502@gmail.com","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-01-21T00:16:39Z","receivedAt":"2012-01-21T00:16:39Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Neal Kreitzinger <nkreitzinger@gmail.com> writes:\n\n> To get this to work I had to learn more about shell scripting and export\n> the GIT_WORK_TREE git environment variable.\n>\n> (post-update hook):\n> export GIT_WORK_TREE=/home/neal/FSNMSTHTML\n> git checkout -f HEAD\n\n\nHmm, I thought \"cd .. && git checkout -f HEAD\" (or \"git reset --hard\")\nwould have worked.\n"},{"id":"182891","messageId":"4F1A0849.8050205@gmail.com","threadId":"29390","inReplyTo":"7vr4ytdi54.fsf@alter.siamese.dyndns.org","subject":"Re: post-update to stash after push to non-bare current branch","fromName":"Neal Kreitzinger","fromEmail":"nkreitzinger@gmail.com","sentAt":"2012-01-21T00:35:21Z","receivedAt":"2012-01-21T00:35:21Z","isPatch":false,"sender":{"key":"nkreitzinger@gmail.com","avatar":null},"body":"On 1/20/2012 6:16 PM, Junio C Hamano wrote:\n> Neal Kreitzinger<nkreitzinger@gmail.com>  writes:\n>\n>> To get this to work I had to learn more about shell scripting and export\n>> the GIT_WORK_TREE git environment variable.\n>>\n>> (post-update hook):\n>> export GIT_WORK_TREE=/home/neal/FSNMSTHTML\n>> git checkout -f HEAD\n>\n>\n> Hmm, I thought \"cd ..&&  git checkout -f HEAD\" (or \"git reset --hard\")\n> would have worked.\n\nOk, I just tried that for the first time and it complained \"not a git \nrepository: '.'\" because it looks like that caused GIT_DIR to no longer \npoint to WORKTREE/.git but instead to WORKTREE/ because GIT_DIR is set \nto '.' in the post-update script's environment as indicated in this \nthread: \nhttp://stackoverflow.com/questions/6635018/reuse-git-work-tree-in-post-receive-hook-to-rm-a-few-files\n\nv/r,\nneal\n"}]}