{"thread":{"id":"22224","subject":"git checkout -f: What am I missing?","startedAt":"2010-01-14T21:16:12Z","lastAt":"2010-01-28T10:27:13Z","messageCount":3,"participants":["Soham Mehta","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"131680","messageId":"4B4F899C.7070800@box.net","threadId":"22224","inReplyTo":null,"subject":"git checkout -f: What am I missing?","fromName":"Soham Mehta","fromEmail":"soham@box.net","sentAt":"2010-01-14T21:16:12Z","receivedAt":"2010-01-14T21:16:12Z","isPatch":false,"sender":{"key":"soham@box.net","avatar":null},"body":"Hi,\n\nI have a situation with git that I'm trying to understand:\n\nDescription:\n1) GIT_DIR is set to /path/to/repo/.git\n2) Repository is /not /a bare repo, and all files are nicely checked-out \nin /path/to/repo/\n3) Somebody pushes to that repo using ssh (any branch, checked-out or not)\n4) Default post-receive hook runs (it is the only one +x) which sends \nout an email \n(http://repo.or.cz/w/git.git/blob/HEAD:/contrib/hooks/post-receive-email)\n5) After it is done sending the email, I put \"git checkout -f\", at the \nend in the same file, in case someone pushes to a checked-out branch\n\nProblem:\nIt runs \"checkout -f\" as if inside .git directory, instead of on the \nparent. i.e. it gets all files from the parent and writes them inside \n.git. Parent is left untouched.\n\nSome more info:\n0) We don't have GIT_DIR set in the environment. The hook does a \nrev-parse to find it.\n1) echo of $GIT_DIR right before the checkout -f line gives a \".\" .\n2) It works as expected if I do this:  cd /path/to/repo && git \n--git-dir=/path/to/repo/.git/ checkout -f\n\nWhat I do know:\n1) Pushing to a checked-out branch is not a git best-practice, and some \ngit behavior is undefined in that case. We already have plans to go away \nfrom that.\n2) Git tends to like full path names instead of relative ones\n\nCan someone help me understand this behavior?\n\nThanks.\n-Soham\n"},{"id":"131727","messageId":"4B508997.8030105@drmicha.warpmail.net","threadId":"22224","inReplyTo":"4B4F899C.7070800@box.net","subject":"Re: git checkout -f: What am I missing?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-01-15T15:28:23Z","receivedAt":"2010-01-15T15:28:23Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Soham Mehta venit, vidit, dixit 14.01.2010 22:16:\n> Hi,\n> \n> I have a situation with git that I'm trying to understand:\n> \n> Description:\n> 1) GIT_DIR is set to /path/to/repo/.git\n> 2) Repository is /not /a bare repo, and all files are nicely checked-out \n> in /path/to/repo/\n> 3) Somebody pushes to that repo using ssh (any branch, checked-out or not)\n> 4) Default post-receive hook runs (it is the only one +x) which sends \n> out an email \n> (http://repo.or.cz/w/git.git/blob/HEAD:/contrib/hooks/post-receive-email)\n> 5) After it is done sending the email, I put \"git checkout -f\", at the \n> end in the same file, in case someone pushes to a checked-out branch\n> \n> Problem:\n> It runs \"checkout -f\" as if inside .git directory, instead of on the \n> parent. i.e. it gets all files from the parent and writes them inside \n> .git. Parent is left untouched.\n> \n> Some more info:\n> 0) We don't have GIT_DIR set in the environment. The hook does a \n> rev-parse to find it.\n> 1) echo of $GIT_DIR right before the checkout -f line gives a \".\" .\n> 2) It works as expected if I do this:  cd /path/to/repo && git \n> --git-dir=/path/to/repo/.git/ checkout -f\n> \n> What I do know:\n> 1) Pushing to a checked-out branch is not a git best-practice, and some \n> git behavior is undefined in that case. We already have plans to go away \n> from that.\n> 2) Git tends to like full path names instead of relative ones\n> \n> Can someone help me understand this behavior?\n\nDoes the thread\nhttp://permalink.gmane.org/gmane.comp.version-control.git/136267\nhelp by any chance?\nYou've found the solution, \"cd .. && unset GIT_DIR\" does it.\n\nMichael\n"},{"id":"132883","messageId":"4B616681.4080700@drmicha.warpmail.net","threadId":"22224","inReplyTo":"4B60B2CF.10401@box.net","subject":"Re: git checkout -f: What am I missing?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-01-28T10:27:13Z","receivedAt":"2010-01-28T10:27:13Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Soham Mehta venit, vidit, dixit 27.01.2010 22:40:\n> Thanks Michael.\n> \n> Is that a bug? If not, how do I understand it?\n> \n> -Soham\n> \n> \n> thus spake Michael J Gruber , On 1/15/2010 7:28 AM:\n>> Soham Mehta venit, vidit, dixit 14.01.2010 22:16:\n>>   \n>>> Hi,\n>>>\n>>> I have a situation with git that I'm trying to understand:\n>>>\n>>> Description:\n>>> 1) GIT_DIR is set to /path/to/repo/.git\n>>> 2) Repository is /not /a bare repo, and all files are nicely checked-out \n>>> in /path/to/repo/\n>>> 3) Somebody pushes to that repo using ssh (any branch, checked-out or not)\n>>> 4) Default post-receive hook runs (it is the only one +x) which sends \n>>> out an email \n>>> (http://repo.or.cz/w/git.git/blob/HEAD:/contrib/hooks/post-receive-email)\n>>> 5) After it is done sending the email, I put \"git checkout -f\", at the \n>>> end in the same file, in case someone pushes to a checked-out branch\n>>>\n>>> Problem:\n>>> It runs \"checkout -f\" as if inside .git directory, instead of on the \n>>> parent. i.e. it gets all files from the parent and writes them inside \n>>> .git. Parent is left untouched.\n>>>\n>>> Some more info:\n>>> 0) We don't have GIT_DIR set in the environment. The hook does a \n>>> rev-parse to find it.\n>>> 1) echo of $GIT_DIR right before the checkout -f line gives a \".\" .\n>>> 2) It works as expected if I do this:  cd /path/to/repo && git \n>>> --git-dir=/path/to/repo/.git/ checkout -f\n>>>\n>>> What I do know:\n>>> 1) Pushing to a checked-out branch is not a git best-practice, and some \n>>> git behavior is undefined in that case. We already have plans to go away \n>>> from that.\n>>> 2) Git tends to like full path names instead of relative ones\n>>>\n>>> Can someone help me understand this behavior?\n>>>     \n>>\n>> Does the thread\n>> http://permalink.gmane.org/gmane.comp.version-control.git/136267\n>> help by any chance?\n>> You've found the solution, \"cd .. && unset GIT_DIR\" does it.\n>>\n>> Michael\n>>   \n\nBecause it messes up the reading order.\n\nWhy?\n\nPlease don't top-post.\n\nBack to your question: The thread I pointed you to explains that git\nsets \"GIT_DIR=.\", and given that the behaviour is exactly as expected.\nIt's not a bug. Changing it may break existing hooks.\n\nOne may argue for a change in behaviour in the next major release, but\nnot 1.7. any more.\n\nMichael\n"}]}