{"thread":{"id":"39415","subject":"git status doesn't ignore GIT_DIR directory?","startedAt":"2015-05-23T01:03:38Z","lastAt":"2015-05-23T17:39:39Z","messageCount":10,"participants":["Thorsten von Eicken","Junio C Hamano","Duy Nguyen","Mike Hommey"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"261975","messageId":"555FD1EA.2060706@rightscale.com","threadId":"39415","inReplyTo":null,"subject":"git status doesn't ignore GIT_DIR directory?","fromName":"Thorsten von Eicken","fromEmail":"tve@rightscale.com","sentAt":"2015-05-23T01:03:38Z","receivedAt":"2015-05-23T01:03:38Z","isPatch":false,"sender":{"key":"tve@rightscale.com","avatar":null},"body":"I renamed my .git directory to _git and I'm surprised that git status \nthinks that it's an untracked file:\n\n$ GIT_DIR=_git git status\nOn branch master\nYour branch is up-to-date with 'origin/master'.\n\nUntracked files:\n   (use \"git add <file>...\" to include in what will be committed)\n\n         _git/\n\nnothing added to commit but untracked files present (use \"git add\" to track)\n\nThis doesn't seem to make sense, shouldn't git ignore whatever $GIT_DIR \npoints to? Or is there some other magic option I need to use for it to \ndo what I expect?\n"},{"id":"261978","messageId":"CAPc5daW2yTHHegPDrEWS5KiSYWZECV+AxMnewzz9ayASB1QNUw@mail.gmail.com","threadId":"39415","inReplyTo":"555FD1EA.2060706@rightscale.com","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-23T02:03:48Z","receivedAt":"2015-05-23T02:03:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As far as I know, GIT_DIR was prepared as a mechanism to point at\nanother .git directory that does not live inside the working tree, not\nas a mechanism to rename it to arbitrary name. E.g.\n\n $ git init\n $ mv .git .svn\n $ GIT_DIR=$(pwd)/.svn ; export GIT_DIR\n\nis not expected to work.\n\n\nOn Fri, May 22, 2015 at 6:03 PM, Thorsten von Eicken <tve@rightscale.com> wrote:\n> I renamed my .git directory to _git and I'm surprised that git status thinks\n> that it's an untracked file:\n>\n> $ GIT_DIR=_git git status\n> On branch master\n> Your branch is up-to-date with 'origin/master'.\n>\n> Untracked files:\n>   (use \"git add <file>...\" to include in what will be committed)\n>\n>         _git/\n>\n> nothing added to commit but untracked files present (use \"git add\" to track)\n>\n> This doesn't seem to make sense, shouldn't git ignore whatever $GIT_DIR\n> points to? Or is there some other magic option I need to use for it to do\n> what I expect?\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"261980","messageId":"20150523022256.GA17789@lanh","threadId":"39415","inReplyTo":"CAPc5daW2yTHHegPDrEWS5KiSYWZECV+AxMnewzz9ayASB1QNUw@mail.gmail.com","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-05-23T02:22:56Z","receivedAt":"2015-05-23T02:22:56Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, May 22, 2015 at 07:03:48PM -0700, Junio C Hamano wrote:\n> As far as I know, GIT_DIR was prepared as a mechanism to point at\n> another .git directory that does not live inside the working tree, not\n> as a mechanism to rename it to arbitrary name. E.g.\n> \n>  $ git init\n>  $ mv .git .svn\n>  $ GIT_DIR=$(pwd)/.svn ; export GIT_DIR\n> \n> is not expected to work.\n\nThis is not the first time we get this report. Perhaps we should\ndocument it.\n\n-- 8< --\nSubject: git.txt: mention the special name \".git\" in GIT_DIR\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 90c5f37..91d6dd2 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -691,6 +691,9 @@ Git so take care if using Cogito etc.\n \tspecifies a path to use instead of the default `.git`\n \tfor the base of the repository.\n \tThe '--git-dir' command-line option also sets this value.\n++\n+Note that if GIT_DIR is set explicitly to a directory inside working\n+tree, the directory name must be \".git\".\n \n 'GIT_WORK_TREE'::\n \tSet the path to the root of the working tree.\n-- 8< --\n"},{"id":"261982","messageId":"556004DE.7080504@rightscale.com","threadId":"39415","inReplyTo":"20150523022256.GA17789@lanh","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Thorsten von Eicken","fromEmail":"tve@rightscale.com","sentAt":"2015-05-23T04:41:02Z","receivedAt":"2015-05-23T04:41:02Z","isPatch":false,"sender":{"key":"tve@rightscale.com","avatar":null},"body":"On 5/22/2015 7:22 PM, Duy Nguyen wrote:\n> On Fri, May 22, 2015 at 07:03:48PM -0700, Junio C Hamano wrote:\n>> As far as I know, GIT_DIR was prepared as a mechanism to point at\n>> another .git directory that does not live inside the working tree, not\n>> as a mechanism to rename it to arbitrary name. E.g.\n>>\n>>  $ git init\n>>  $ mv .git .svn\n>>  $ GIT_DIR=$(pwd)/.svn ; export GIT_DIR\n>>\n>> is not expected to work.\n>\n> ++\n> +Note that if GIT_DIR is set explicitly to a directory inside working\n> +tree, the directory name must be \".git\".\nThis is not at all what I was hoping to hear, but thanks for the response.\nThorsten\n"},{"id":"261983","messageId":"20150523053900.GA2364@glandium.org","threadId":"39415","inReplyTo":"20150523022256.GA17789@lanh","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2015-05-23T05:39:00Z","receivedAt":"2015-05-23T05:39:00Z","isPatch":false,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"On Sat, May 23, 2015 at 09:22:56AM +0700, Duy Nguyen wrote:\n> On Fri, May 22, 2015 at 07:03:48PM -0700, Junio C Hamano wrote:\n> > As far as I know, GIT_DIR was prepared as a mechanism to point at\n> > another .git directory that does not live inside the working tree, not\n> > as a mechanism to rename it to arbitrary name. E.g.\n> > \n> >  $ git init\n> >  $ mv .git .svn\n> >  $ GIT_DIR=$(pwd)/.svn ; export GIT_DIR\n> > \n> > is not expected to work.\n> \n> This is not the first time we get this report. Perhaps we should\n> document it.\n> \n> -- 8< --\n> Subject: git.txt: mention the special name \".git\" in GIT_DIR\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n> diff --git a/Documentation/git.txt b/Documentation/git.txt\n> index 90c5f37..91d6dd2 100644\n> --- a/Documentation/git.txt\n> +++ b/Documentation/git.txt\n> @@ -691,6 +691,9 @@ Git so take care if using Cogito etc.\n>  \tspecifies a path to use instead of the default `.git`\n>  \tfor the base of the repository.\n>  \tThe '--git-dir' command-line option also sets this value.\n> ++\n> +Note that if GIT_DIR is set explicitly to a directory inside working\n> +tree, the directory name must be \".git\".\n\nIsn't the requirement that it _ends_ with \".git\" (that is,\nGIT_DIR=/path/to/foo.git would work)\n\nMike\n"},{"id":"261988","messageId":"CACsJy8C2LHVrZ-MPupz2_BbE-5m7_fA7qK5HdUa9GR30y8YNPw@mail.gmail.com","threadId":"39415","inReplyTo":"20150523053900.GA2364@glandium.org","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-05-23T11:42:57Z","receivedAt":"2015-05-23T11:42:57Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, May 23, 2015 at 12:39 PM, Mike Hommey <mh@glandium.org> wrote:\n> On Sat, May 23, 2015 at 09:22:56AM +0700, Duy Nguyen wrote:\n>> --- a/Documentation/git.txt\n>> +++ b/Documentation/git.txt\n>> @@ -691,6 +691,9 @@ Git so take care if using Cogito etc.\n>>       specifies a path to use instead of the default `.git`\n>>       for the base of the repository.\n>>       The '--git-dir' command-line option also sets this value.\n>> ++\n>> +Note that if GIT_DIR is set explicitly to a directory inside working\n>> +tree, the directory name must be \".git\".\n>\n> Isn't the requirement that it _ends_ with \".git\" (that is,\n> GIT_DIR=/path/to/foo.git would work)\n\nIf $GIT_DIR points to somewhere inside worktree, \".git\" exactly (it's\nstrcmp(), not ends_with()) is the only exception. If it points outside\nworktree, the directory name could be anything.\n-- \nDuy\n"},{"id":"261989","messageId":"CACsJy8B7tUiRqw0ogLFaHfDo2RwVN8BP09uBQBGVOA9eHtWLvw@mail.gmail.com","threadId":"39415","inReplyTo":"556004DE.7080504@rightscale.com","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-05-23T11:53:41Z","receivedAt":"2015-05-23T11:53:41Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, May 23, 2015 at 11:41 AM, Thorsten von Eicken\n<tve@rightscale.com> wrote:\n> On 5/22/2015 7:22 PM, Duy Nguyen wrote:\n>> On Fri, May 22, 2015 at 07:03:48PM -0700, Junio C Hamano wrote:\n>>> As far as I know, GIT_DIR was prepared as a mechanism to point at\n>>> another .git directory that does not live inside the working tree, not\n>>> as a mechanism to rename it to arbitrary name. E.g.\n>>>\n>>>  $ git init\n>>>  $ mv .git .svn\n>>>  $ GIT_DIR=$(pwd)/.svn ; export GIT_DIR\n>>>\n>>> is not expected to work.\n>>\n>> ++\n>> +Note that if GIT_DIR is set explicitly to a directory inside working\n>> +tree, the directory name must be \".git\".\n> This is not at all what I was hoping to hear, but thanks for the response.\n\nTo elaborate a bit more, I think \".git\" was cooked in the code near\nthe beginning and for too long. By the time people wanted flexibility,\n\".git\" string was already all over the place and changing it may\nrequire some (and maybe big) code reorganization, and all that is for\na rare use case.. I think I saw at least two attempts to fix this but\nthey went nowhere. On the bright side, you can work around this easily\nby adding \".svn\" to your ignore list.\n-- \nDuy\n"},{"id":"261994","messageId":"xmqq1ti7dyky.fsf@gitster.dls.corp.google.com","threadId":"39415","inReplyTo":"20150523053900.GA2364@glandium.org","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-23T16:54:05Z","receivedAt":"2015-05-23T16:54:05Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Hommey <mh@glandium.org> writes:\n\n> On Sat, May 23, 2015 at 09:22:56AM +0700, Duy Nguyen wrote:\n>> On Fri, May 22, 2015 at 07:03:48PM -0700, Junio C Hamano wrote:\n>> > As far as I know, GIT_DIR was prepared as a mechanism to point at\n>> > another .git directory that does not live inside the working tree, not\n>> > as a mechanism to rename it to arbitrary name. E.g.\n>> > \n>> >  $ git init\n>> >  $ mv .git .svn\n>> >  $ GIT_DIR=$(pwd)/.svn ; export GIT_DIR\n>> > \n>> > is not expected to work.\n>> ...\n>> ++\n>> +Note that if GIT_DIR is set explicitly to a directory inside working\n>> +tree, the directory name must be \".git\".\n>\n> Isn't the requirement that it _ends_ with \".git\" (that is,\n> GIT_DIR=/path/to/foo.git would work)\n\nI think both of you are wrong ;-)\n\nThe thing is, what you are seeing does not have much to do with\nGIT_DIR.  It is \"what Git does when it finds a directory inside the\nworking tree of a project\".  And \".git\" is the only special thing in\nthat context.\n\nWhen we find a directory whose name is \".git\", whether it is the\nsame as GIT_DIR or not (and \"not\" case includes when you do not have\nGIT_DIR defined), \"git add\" thinks \"Ah, that is a repository proper,\nand I wouldn't add it to my project\".  It can do two things.  (1) if\nit is not at the top of the working tree, i.e. some/directory/.git,\nthen some/directory is a submodule of the project that has the\nworking tree we are talking about (unless some/.git exists which\nmakes some/directory/.git a submodule of the project that has some/\nas its working tree, of course), so \"git add\" would treat\nsome/directory as a thing to add.  (2) if it is at the top of the\nworking tree, it does not do anything to it, as it does not make\nsense to add the whole working tree as a separate submodule of\nourselves.\n\nThe same for \"git status\".  (1) is treated as a submodule and we do\nnot consider individual files in some/directory/.git as untracked.\n(2) we do not cconsider individual files in .git as untracked.\n\nGIT_DIR further comes into play when it is _not_ defined.  In that\ncase we try upwards to find a directory that has \".git\" subdirectory\nand contains our $(cwd), and then declare it as our repository.\n\nAnd when GIT_DIR points at somewhere that does not affect all of the\nabove (i.e. trying to see if a random directory inside our working\ntree is a \".git\" repository), it can be named anything.  If you are\nworking in /path/to/my/work/tree with GIT_DIR set, it can point at\n/path/to/my/repository_git (note that it does not end with \".git\",\nand note also that it is outside our working tree) just fine.\n\nIf you move that directory to /path/to/my/worktree/repository_git,\nand point at it with GIT_DIR, we will notice that is our repository\nmetadata, but \"git add\" and friends will see \"repository_git\" is\ndifferent from \".git\" and the special casing rules for directories\ninside working tree do not kick in.\n"},{"id":"261995","messageId":"xmqqwpzzcjq0.fsf@gitster.dls.corp.google.com","threadId":"39415","inReplyTo":"xmqq1ti7dyky.fsf@gitster.dls.corp.google.com","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-23T17:00:23Z","receivedAt":"2015-05-23T17:00:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> I think both of you are wrong ;-)\n>\n> The thing is, what you are seeing does not have much to do with\n> GIT_DIR.  It is \"what Git does when it finds a directory inside the\n> working tree of a project\".  And \".git\" is the only special thing in\n> that context.\n\nIn short, I think Duy's \"how about this\" means well, but adds\ndocumentation at a wrong place.\n\nHaving said all that, the message I am responding to showed the\nright way to look at, understand, and explain the current behaviour.\nIt is a separate issue if the current behaviour is optimal from the\nusability point of view.  It is not entirely implausible to extend\nthe special casing rules from \"a directory named '.git' only\" to \"in\naddition, the directory pointed at by GIT_DIR, if exists, is treated\nthe same way\".\n"},{"id":"261999","messageId":"xmqqk2vzchwk.fsf@gitster.dls.corp.google.com","threadId":"39415","inReplyTo":"xmqqwpzzcjq0.fsf@gitster.dls.corp.google.com","subject":"Re: git status doesn't ignore GIT_DIR directory?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-23T17:39:39Z","receivedAt":"2015-05-23T17:39:39Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> I think both of you are wrong ;-)\n>>\n>> The thing is, what you are seeing does not have much to do with\n>> GIT_DIR.  It is \"what Git does when it finds a directory inside the\n>> working tree of a project\".  And \".git\" is the only special thing in\n>> that context.\n>\n> In short, I think Duy's \"how about this\" means well, but adds\n> documentation at a wrong place.\n>\n> Having said all that, the message I am responding to showed the\n> right way to look at, understand, and explain the current behaviour.\n> It is a separate issue if the current behaviour is optimal from the\n> usability point of view.  It is not entirely implausible to extend\n> the special casing rules from \"a directory named '.git' only\" to \"in\n> addition, the directory pointed at by GIT_DIR, if exists, is treated\n> the same way\".\n\nIf somebody is interested in pursuing this further in the direction\nof changing the behaviour (so that Thorsten's original would work as\nexpected), one thing to be careful about is the case (1) (case (2)\nis more or less straight-forward and obvious).\n\nIf you do\n\n    $ GIT_DIR=/path/to/worktree/sub/repo.git\n    $ GIT_WORK_TREE=/path/to/worktree\n    $ export GIT_DIR GIT_WORK_TREE\n    $ cd $GIT_WORK_TREE\n    $ git add sub\n\nwith the current rule, because sub/repo.git does not trigger the\nspecial casing, we may end up adding everything inside our own\nrepository, which is clearly crazy.  But if you change the rule to\nspecial case the directory pointed at by $GIT_DIR, then we would\nstart treating that directory as \"ah, there is a Git repository\".\nBut the updated code must not say \"hence, sub/ is the top level of\nthe working tree of that repository, so we add it as a submodule\".\n\nIt instead should just ignore that repo.git directory, just like a\nplain vanilla \"git add .\"  ignores \".git\" at the top-level, and add\nother things in sub/ directory, i.e. treating sub/ as just a normal\nsubdirectory in our working tree.\n\nI am not planning to do this in a near future myself, but I thought\nI should caution in case anybody is interested.\n\nThanks.\n"}]}