{"thread":{"id":"41624","subject":"Making git apply always work relative to current directory","startedAt":"2016-03-05T18:11:25Z","lastAt":"2016-03-05T19:42:00Z","messageCount":3,"participants":["brian m. carlson","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"280251","messageId":"20160305181125.GA48536@vauxhall.crustytoothpaste.net","threadId":"41624","inReplyTo":null,"subject":"Making git apply always work relative to current directory","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-03-05T18:11:25Z","receivedAt":"2016-03-05T18:11:25Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"I have a piece of software which must run out of a given directory.  In\ndevelopment, this is a git repository, and in production it is not.  I\nalso have an ignored subdirectory where I would like to use git apply to\napply patches (in both environments).\n\nIf I run git apply --no-index --verbose <patch>, it succeeds in both\ncases, but when I'm in the git repository, it *silently does nothing*.\nI have to provide a --directory argument in order for it to function\nunderneath the repository, but of course that doesn't work when the\ndirectory isn't within a repository.  --unsafe-paths did not seem to\nmake a difference.  I'm using Git 2.7.2.\n\nIs there a way to tell git apply that it should apply relative to the\ncurrent working directory, no matter what?  I'm happy to send a patch to\neither the documentation or git apply if necessary.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"280256","messageId":"xmqq4mckvhzq.fsf@gitster.mtv.corp.google.com","threadId":"41624","inReplyTo":"20160305181125.GA48536@vauxhall.crustytoothpaste.net","subject":"Re: Making git apply always work relative to current directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-05T19:31:53Z","receivedAt":"2016-03-05T19:31:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> If I run git apply --no-index --verbose <patch>, it succeeds in both\n> cases, but when I'm in the git repository, it *silently does nothing*.\n\nThat originally sounded peculiar to me and I suspected it to be a\nbug, but it looks like a designed-in feature and with us since\n\ncommit edf2e37002eeb30a2ccad5db3b3e1fe41cdc7eb0\nAuthor: Junio C Hamano <junkio@cox.net>\nDate:   Fri Nov 25 23:14:15 2005 -0800\n\n    git-apply: work from subdirectory.\n    \n    When applying a patch to index file, we need to know where GIT_DIR is;\n    use setup_git_directory() to find it out.  This also allows us to work\n    from a subdirectory if we wanted to.\n    \n    When git-apply is run from a subdirectory, it applies the given patch\n    only to the files under the current directory and below.\n    \n    Signed-off-by: Junio C Hamano <junkio@cox.net>\n\nSo exclusion by use_patch() for paths outside the current directory\nseems to be a feature; the log message does not say \"why\", but if I\nhave to guess, the reasoning was probably \"The old world order was\nthat the command has to always be run from the top level.  A user\nwho wants to run it from a subdirectory must be doing so for a\nreason, e.g. 'I am currently working in this directory, do not touch\noutside this area'\".  In any case, I suspect that the existing tooling\npeople built over the past 10 years around \"git apply\" already depends\non this behaviour, so we cannot lightly change it.\n\nIs it so hard to temporarily go up to the root, run \"git apply\", and\ncome back?  You can use \"--no-index --directory=trash\" for both\ncases that way.\n"},{"id":"280261","messageId":"20160305194200.GB48536@vauxhall.crustytoothpaste.net","threadId":"41624","inReplyTo":"xmqq4mckvhzq.fsf@gitster.mtv.corp.google.com","subject":"Re: Making git apply always work relative to current directory","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-03-05T19:42:00Z","receivedAt":"2016-03-05T19:42:00Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sat, Mar 05, 2016 at 11:31:53AM -0800, Junio C Hamano wrote:\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> \n> > If I run git apply --no-index --verbose <patch>, it succeeds in both\n> > cases, but when I'm in the git repository, it *silently does nothing*.\n> \n> That originally sounded peculiar to me and I suspected it to be a\n> bug, but it looks like a designed-in feature and with us since\n> \n> commit edf2e37002eeb30a2ccad5db3b3e1fe41cdc7eb0\n> Author: Junio C Hamano <junkio@cox.net>\n> Date:   Fri Nov 25 23:14:15 2005 -0800\n> \n>     git-apply: work from subdirectory.\n>     \n>     When applying a patch to index file, we need to know where GIT_DIR is;\n>     use setup_git_directory() to find it out.  This also allows us to work\n>     from a subdirectory if we wanted to.\n>     \n>     When git-apply is run from a subdirectory, it applies the given patch\n>     only to the files under the current directory and below.\n>     \n>     Signed-off-by: Junio C Hamano <junkio@cox.net>\n> \n> So exclusion by use_patch() for paths outside the current directory\n> seems to be a feature; the log message does not say \"why\", but if I\n> have to guess, the reasoning was probably \"The old world order was\n> that the command has to always be run from the top level.  A user\n> who wants to run it from a subdirectory must be doing so for a\n> reason, e.g. 'I am currently working in this directory, do not touch\n> outside this area'\".  In any case, I suspect that the existing tooling\n> people built over the past 10 years around \"git apply\" already depends\n> on this behaviour, so we cannot lightly change it.\n\nI was planning to add a --here option (maybe spelled\n--current-directory) that would change that behavior, since I figured\nthat people would be relying on the current behavior.  The man page\nclearly indicates that some people are using it as a better GNU patch,\nso an option that does that might be useful.\n\nRegardless, I'd say that --verbose should cause git apply to say\nsomething.  I'm not a newbie with Git, and I spent about an hour trying\nto figure this out.  I've also been bitten by it before elsewhere.\n\n> Is it so hard to temporarily go up to the root, run \"git apply\", and\n> come back?  You can use \"--no-index --directory=trash\" for both\n> cases that way.\n\nThe existing code used patch until we realized that older versions of\nGNU patch can't apply certain git diffs.  It's not super easy to change\nit, but I suppose we could.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"}]}