{"thread":{"id":"11832","subject":"handle_alias() inside .git dir","startedAt":"2008-02-02T09:02:20Z","lastAt":"2008-02-03T04:57:38Z","messageCount":2,"participants":["Kevin Ballard","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"67091","messageId":"837649D4-465F-4C85-BBE8-B004637EDEF7@sb.org","threadId":"11832","inReplyTo":null,"subject":"handle_alias() inside .git dir","fromName":"Kevin Ballard","fromEmail":"kevin@sb.org","sentAt":"2008-02-02T09:02:20Z","receivedAt":"2008-02-02T09:02:20Z","isPatch":false,"sender":{"key":"kevin@sb.org","avatar":"https://avatars.githubusercontent.com/u/714?v=4"},"body":"It seems that using any aliases while inside a .git dir will end up  \nsetting the work tree to the current dir, even though it's clearly not  \na work tree. This means that having an alias like `git config alias.st  \n= status` and running `git st` inside a .git dir will proceed to spit  \nout a listing that claims that every file in the project is missing  \nrather than displaying an error about not being in a work tree like  \n`git status` will show.\n\nThis happens because setup_git_directory_gently() ends up setting  \nGIT_DIR_ENVIRONMENT to \".\" if it detects that we are in the .git  \ndirectory, and then a subsequent call to setup_git_directory() calls  \nsetup_git_directory_gently() again, which sees the GIT_DIR_ENVIRONMENT  \nand ends up calling set_work_tree(). The comment to set_work_tree()  \nsays it's only called if GIT_DIR is set and calls what it does \"old  \nbehavior\". I assume it exists for some sort of backwards  \ncompatibility, but in quick testing simply commenting out line 266 of  \nsetup.c (the call to set_work_tree) makes `git st` work as expected.  \nI'm not sure if this will have any adverse effect on anything else.  \nDoes anybody know if this will cause problems?\n\nAnother option that seems like it should work is checking if we're a  \nbare repo, and if not then setting the work tree to our parent dir,  \nassuming any relevant config values or env variables aren't set that  \nwould point elsewhere. I would try and implement this but after  \nlooking at it for a few minutes, I fear 4AM is not the best of times  \nto try and figure out how this code works.\n\n-Kevin Ballard\n\n-- \nKevin Ballard\nhttp://kevin.sb.org\nkevin@sb.org\nhttp://www.tildesoft.com\n\n\n"},{"id":"67184","messageId":"20080203045738.GA10660@coredump.intra.peff.net","threadId":"11832","inReplyTo":"837649D4-465F-4C85-BBE8-B004637EDEF7@sb.org","subject":"Re: handle_alias() inside .git dir","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-03T04:57:38Z","receivedAt":"2008-02-03T04:57:38Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 02, 2008 at 04:02:20AM -0500, Kevin Ballard wrote:\n\n> This happens because setup_git_directory_gently() ends up setting  \n> GIT_DIR_ENVIRONMENT to \".\" if it detects that we are in the .git  \n> directory, and then a subsequent call to setup_git_directory() calls  \n> setup_git_directory_gently() again, which sees the GIT_DIR_ENVIRONMENT  \n> and ends up calling set_work_tree(). The comment to set_work_tree() says \n> it's only called if GIT_DIR is set and calls what it does \"old behavior\". \n> I assume it exists for some sort of backwards compatibility, but in quick \n> testing simply commenting out line 266 of setup.c (the call to \n> set_work_tree) makes `git st` work as expected. I'm not sure if this will \n> have any adverse effect on anything else. Does anybody know if this will \n> cause problems?\n\nNo, I don't think that's right. That call is there for people who have\nexplicitly set GIT_DIR to use their cwd as the working tree, wherever it\nmay be.\n\nThe problem is that setup_git_directory_gently actually _sets_ GIT_DIR.\nSo the next time through when we call setup_git_directory_gently again,\nit thinks you have set it in the environment, which has the special\nmeaning.\n\nUnfortunately, it doesn't look like there's a simple fix. Because the\nsemantics of the two are related, I think we need to set GIT_WORK_TREE\nwhenever we set GIT_DIR, and we need some way of setting GIT_WORK_TREE\nto a value that means \"I don't have a work tree.\"\n\n-Peff\n"}]}