{"thread":{"id":"42358","subject":"GIT_INDEX_FILE relative path breaks in subdir","startedAt":"2016-05-17T17:18:36Z","lastAt":"2016-05-23T19:44:48Z","messageCount":9,"participants":["Joey Hess","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"286802","messageId":"20160517171836.GA12183@kitenet.net","threadId":"42358","inReplyTo":null,"subject":"GIT_INDEX_FILE relative path breaks in subdir","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-05-17T17:18:36Z","receivedAt":"2016-05-17T17:18:36Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"joey@darkstar:/tmp>git init test\nInitialized empty Git repository in /tmp/test/.git/\njoey@darkstar:/tmp>cd test\njoey@darkstar:/tmp/test>mkdir sub\njoey@darkstar:/tmp/test>cd sub\njoey@darkstar:/tmp/test/sub>GIT_INDEX_FILE=../.git/otherindex git write-tree\nfatal: Unable to create '/tmp/test/../.git/otherindex.lock': No such file or directory\n\nAppears to be a bug in git. Seems that it's assuming GIT_INDEX_FILE is\nrelative to the top of the worktree and not to the CWD.\n\nWorkaround: Use absolute path to the index file.\n\njoey@darkstar:/tmp/test/sub>GIT_INDEX_FILE=`pwd`/../.git/otherindex git write-tree\n4b825dc642cb6eb9a060e54bf8d69288fbee4904\njoey@darkstar:/tmp/test/sub>ls ../.git/otherindex \n../.git/otherindex\n\ngit version 2.8.1\n\n-- \nsee shy jo\n"},{"id":"286805","messageId":"xmqqy478wptr.fsf@gitster.mtv.corp.google.com","threadId":"42358","inReplyTo":"20160517171836.GA12183@kitenet.net","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-17T17:34:56Z","receivedAt":"2016-05-17T17:34:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joey Hess <id@joeyh.name> writes:\n\n> Appears to be a bug in git. Seems that it's assuming GIT_INDEX_FILE is\n> relative to the top of the worktree and not to the CWD.\n\nI think that has always been the case.  You can always specify it as\nrelative to the top.  Of course, you can use absolute.\n"},{"id":"286814","messageId":"20160517182645.GA27396@kitenet.net","threadId":"42358","inReplyTo":"xmqqy478wptr.fsf@gitster.mtv.corp.google.com","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-05-17T18:26:45Z","receivedAt":"2016-05-17T18:26:45Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Junio C Hamano wrote:\n> Joey Hess <id@joeyh.name> writes:\n> \n> > Appears to be a bug in git. Seems that it's assuming GIT_INDEX_FILE is\n> > relative to the top of the worktree and not to the CWD.\n> \n> I think that has always been the case.  You can always specify it as\n> relative to the top.  Of course, you can use absolute.\n\nI think it *has* always been that way, but is there anything in the\ndocumentation that indicates this is the case? This could well be best\nfixed in the documentation.\n\nHmm, at least GIT_OBJECT_DIRECTORY also behaves this way.\n(OTOH, GIT_DIR does not behave this way).\n\n-- \nsee shy jo\n"},{"id":"287209","messageId":"20160522190404.GA20998@kitenet.net","threadId":"42358","inReplyTo":"20160517182645.GA27396@kitenet.net","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-05-22T19:04:04Z","receivedAt":"2016-05-22T19:04:04Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"This is actually worse than I thought; when git is being run with a\ndetached work tree, GIT_INDEX_FILE is treated as a path relative to CWD,\ninstead of the normal behavior of relative the top of the work tree.\n\nNormal and expected (according to this thread anyway):\n\njoey@darkstar:~/src/other/git/Documentation> input=\"100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1    frotz\"\njoey@darkstar:~/src/other/git/Documentation> echo \"$input\" | GIT_INDEX_FILE=.git/newindex git update-index --index-info \njoey@darkstar:~/src/other/git/Documentation> ls ../.git/newindex \n../.git/newindex\n\nFully detached worktree and git dir:\n\njoey@darkstar:/> echo \"$input\" | GIT_INDEX_FILE=.git/index git --git-dir=/home/joey/src/other/git/.git --work-tree=/home/joey/src/other/git update-index --index-info \nfatal: Unable to create '/.git/index.lock': No such file or directory\njoey@darkstar:/> echo \"$input\" | GIT_WORK_TREE=/home/joey/src/other/git GIT_DIR=/home/joey/src/other/git/.git GIT_INDEX_FILE=.git/newindex git update-index --index-info \nfatal: Unable to create '/.git/newindex.lock': No such file or directory\n\nWork tree detached via git configuration:\n\njoey@darkstar:~/src/other/git> git config core.worktree /home/joey/src/other/git/tmptree\njoey@darkstar:~/src/other/git> mkdir tmptree\njoey@darkstar:~/src/other/git> cd tmptree/\njoey@darkstar:~/src/other/git/tmptree> mkdir Documentation\njoey@darkstar:~/src/other/git/tmptree> cd Documentation/\njoey@darkstar:~/src/other/git/tmptree/Documentation> echo \"$input\" | GIT_INDEX_FILE=.git/index git update-index --index-info\nfatal: Unable to create '/home/joey/src/other/git/tmptree/.git/index.lock': No such file or directory\n\nThis seems to make it basically impossible for any program that wants to\nuse GIT_INDEX_FILE to use anything other than an absolute path;\nthere are too many configurations to keep straight that could change how\ngit interprets what should be a simple relative path to a file.\n\n-- \nsee shy jo\n"},{"id":"287258","messageId":"xmqqwpmkafmb.fsf@gitster.mtv.corp.google.com","threadId":"42358","inReplyTo":"20160522190404.GA20998@kitenet.net","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-23T16:44:28Z","receivedAt":"2016-05-23T16:44:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joey Hess <id@joeyh.name> writes:\n\n> This seems to make it basically impossible for any program that wants to\n> use GIT_INDEX_FILE to use anything other than an absolute path;\n> there are too many configurations to keep straight that could change how\n> git interprets what should be a simple relative path to a file.\n\nThanks for digging.  Perhaps this needs to be documented (not \"in\nthis case it is take as relative to that, in this other case, ...\",\nbut \"you cannot rely on relative being relative to something you\nthink\").\n"},{"id":"287261","messageId":"20160523172951.GA1184@kitenet.net","threadId":"42358","inReplyTo":"xmqqwpmkafmb.fsf@gitster.mtv.corp.google.com","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-05-23T17:29:51Z","receivedAt":"2016-05-23T17:29:51Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Junio C Hamano wrote:\n> Joey Hess <id@joeyh.name> writes:\n> \n> > This seems to make it basically impossible for any program that wants to\n> > use GIT_INDEX_FILE to use anything other than an absolute path;\n> > there are too many configurations to keep straight that could change how\n> > git interprets what should be a simple relative path to a file.\n> \n> Thanks for digging.  Perhaps this needs to be documented (not \"in\n> this case it is take as relative to that, in this other case, ...\",\n> but \"you cannot rely on relative being relative to something you\n> think\").\n\nDocumenting it that way feels like ¯\\_(ツ)_/¯\nI feel it should be made consistently relative to top of work tree.\n\nSeems fairly unlikely that any scripts driving git rely on it\nbeing relative to the pwd when GIT_WORK_TREE etc is set.\n\n(I'd prefer relative to pwd because that is much more sane IMHO, but\nmaking that change is more likely to break something.)\n\n-- \nsee shy jo\n"},{"id":"287267","messageId":"xmqqiny4aaq9.fsf@gitster.mtv.corp.google.com","threadId":"42358","inReplyTo":"20160523172951.GA1184@kitenet.net","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-23T18:30:06Z","receivedAt":"2016-05-23T18:30:06Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joey Hess <id@joeyh.name> writes:\n\n> I feel it should be made consistently relative to top of work tree.\n>\n> Seems fairly unlikely that any scripts driving git rely on it\n> being relative to the pwd when GIT_WORK_TREE etc is set.\n\nOh, I do agree that the current status may be a sign that nobody\nthat is cautious to cater to all possible cases would be relying on\nthe current behaviour in their scripts.  It is likely that their\nscripts would first notice GIT_INDEX_FILE being relative, turn it\ninto absolute (or even error out---if the authors were aware of the\nissue), before doing anything else.\n\nBut people do write their scripts assuming that they will never use\nGIT_WORK_TREE environment (i.e. they rely on their workflow to stay\nwithin a subset of cases you described in your message); IOW, it is\nOK for them that their script is usable only in their workflow.\n\nAnd once you start worrying about not breaking them, your update\nwould become a lot trickier.\n\nI personally think that it would be OK as long as we do not change\nbehaviours for those who do not use core.worktree, $GIT_DIR and/or\n$GIT_WORK_TREE and change behaviour for others to match that\nbehaviour, simply because the plain vanilla no-configuration would\nbe used by the largest number of people.  But depending on the size\nof the \"minority\", you may get pushback from them.\n\n> (I'd prefer relative to pwd because that is much more sane IMHO, but\n> making that change is more likely to break something.)\n\nI am not sure if relative to PWD is useful.  If it were relative to\neither the GIT_DIR or the GIT_WORK_TREE, i.e. a fixed point, then\nyou can set and export GIT_INDEX_FILE and chdir around without\nhaving to adjust it.  If it were relative to PWD, you would need to\nadjust it every time you chdir, no?\n"},{"id":"287271","messageId":"20160523185258.GA10389@kitenet.net","threadId":"42358","inReplyTo":"xmqqiny4aaq9.fsf@gitster.mtv.corp.google.com","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Joey Hess","fromEmail":"id@joeyh.name","sentAt":"2016-05-23T18:52:58Z","receivedAt":"2016-05-23T18:52:58Z","isPatch":false,"sender":{"key":"id@joeyh.name","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Junio C Hamano wrote:\n> I personally think that it would be OK as long as we do not change\n> behaviours for those who do not use core.worktree, $GIT_DIR and/or\n> $GIT_WORK_TREE and change behaviour for others to match that\n> behaviour, simply because the plain vanilla no-configuration would\n> be used by the largest number of people.  But depending on the size\n> of the \"minority\", you may get pushback from them.\n\nThe minority affected would I think be limited to:\n\n1. People who have a configuration that *always* sets core.worktree etc,\n   and used GIT_INDEX_FILE with a cwd-relative path and it just happened\n   to work for them.\n\n2. People who have gone through the learning curve I've suffered about\n   how relative GIT_INDEX_FILE works, and put in a workaround that's\n   not the obvious \"use an absolute path\" workaround, but is more\n   complex. Like, checking the git configs and adjusting what the\n   variable is set relative to. And apparently nobody in this set felt\n   worth mentioning this to the list..\n\nI am unsure about the size of 1, and am sure 2 is small to nonexistant.\n\n> I am not sure if relative to PWD is useful.  If it were relative to\n> either the GIT_DIR or the GIT_WORK_TREE, i.e. a fixed point, then\n> you can set and export GIT_INDEX_FILE and chdir around without\n> having to adjust it.  If it were relative to PWD, you would need to\n> adjust it every time you chdir, no?\n\nGood point, I had not considered this use case. Although if I set a\nlong-term environment variable and expect to chdir around, well, that's\nwhat absolute paths are for. All my uses of GIT_INDEX_FILE\nare in short-term contexts where the program does not chdir.\n\n-- \nsee shy jo\n"},{"id":"287304","messageId":"xmqqtwho8spb.fsf@gitster.mtv.corp.google.com","threadId":"42358","inReplyTo":"20160523185258.GA10389@kitenet.net","subject":"Re: GIT_INDEX_FILE relative path breaks in subdir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-23T19:44:48Z","receivedAt":"2016-05-23T19:44:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joey Hess <id@joeyh.name> writes:\n\n>> I am not sure if relative to PWD is useful.  If it were relative to\n>> either the GIT_DIR or the GIT_WORK_TREE, i.e. a fixed point, then\n>> you can set and export GIT_INDEX_FILE and chdir around without\n>> having to adjust it.  If it were relative to PWD, you would need to\n>> adjust it every time you chdir, no?\n>\n> Good point, I had not considered this use case. Although if I set a\n> long-term environment variable and expect to chdir around, well, that's\n> what absolute paths are for. All my uses of GIT_INDEX_FILE\n> are in short-term contexts where the program does not chdir.\n\nSame to you.  I didn't consider a single-shot\n\n\t$ GIT_INDEX_FILE=./a-temporary-file-here git do something\n\nIt would be natural if we have that temporary file here where we\nare in that use case.\n"}]}