{"thread":{"id":"46840","subject":"git apply fails silently when on the wrong directory","startedAt":"2017-09-27T00:54:06Z","lastAt":"2017-09-27T01:25:31Z","messageCount":3,"participants":["Ernesto Alfonso","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"328990","messageId":"87k20lt10c.fsf@gmail.com","threadId":"46840","inReplyTo":null,"subject":"git apply fails silently when on the wrong directory","fromName":"Ernesto Alfonso","fromEmail":"erjoalgo@gmail.com","sentAt":"2017-09-27T00:53:55Z","receivedAt":"2017-09-27T00:54:06Z","isPatch":false,"sender":{"key":"erjoalgo@gmail.com","avatar":null},"body":"I recently ran into a similar issue as described here:\n\nhttps://stackoverflow.com/questions/24821431/git-apply-patch-fails-silently-no-errors-but-nothing-happens\n\nI was using the alias:\n\nalias ganw='git diff -U0 -w --no-color \"$@\" | git apply --cached --ignore-whitespace --unidiff-zero -'\n\nto stage non-whitespace changes, but I was not in the root directory and\nthe changes were not being applied. I broke down the command to discover\nthe 'git apply' part of the pipe was silently failing to apply anything,\nexiting 0 without even a warning.\n\nThe exit status and lack of warning is terribly misleading, I imagine\nthis would be the cause of subtle bugs in automated scripts. \n\nIs this expected behaviour?\n\nThanks,\n\nErnesto\n"},{"id":"328991","messageId":"87d16dt0xq.fsf@gmail.com","threadId":"46840","inReplyTo":"87k20lt10c.fsf@gmail.com","subject":"Re: git apply fails silently when on the wrong directory","fromName":"Ernesto Alfonso","fromEmail":"erjoalgo@gmail.com","sentAt":"2017-09-27T00:55:29Z","receivedAt":"2017-09-27T00:55:39Z","isPatch":false,"sender":{"key":"erjoalgo@gmail.com","avatar":null},"body":"Also, has there been a feature request for a '-w' option to 'git add',\nanalogous to the same option in 'git diff'?\n\nErnesto Alfonso <erjoalgo@gmail.com> writes:\n\n> I recently ran into a similar issue as described here:\n>\n> https://stackoverflow.com/questions/24821431/git-apply-patch-fails-silently-no-errors-but-nothing-happens\n>\n> I was using the alias:\n>\n> alias ganw='git diff -U0 -w --no-color \"$@\" | git apply --cached --ignore-whitespace --unidiff-zero -'\n>\n> to stage non-whitespace changes, but I was not in the root directory and\n> the changes were not being applied. I broke down the command to discover\n> the 'git apply' part of the pipe was silently failing to apply anything,\n> exiting 0 without even a warning.\n>\n> The exit status and lack of warning is terribly misleading, I imagine\n> this would be the cause of subtle bugs in automated scripts. \n>\n> Is this expected behaviour?\n>\n> Thanks,\n>\n> Ernesto\n"},{"id":"328993","messageId":"20170927012506.5tplhzain5z4eyxy@sigill.intra.peff.net","threadId":"46840","inReplyTo":"87k20lt10c.fsf@gmail.com","subject":"Re: git apply fails silently when on the wrong directory","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-09-27T01:25:06Z","receivedAt":"2017-09-27T01:25:31Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 26, 2017 at 05:53:55PM -0700, Ernesto Alfonso wrote:\n\n> I recently ran into a similar issue as described here:\n> \n> https://stackoverflow.com/questions/24821431/git-apply-patch-fails-silently-no-errors-but-nothing-happens\n> \n> I was using the alias:\n> \n> alias ganw='git diff -U0 -w --no-color \"$@\" | git apply --cached --ignore-whitespace --unidiff-zero -'\n> \n> to stage non-whitespace changes, but I was not in the root directory and\n> the changes were not being applied. I broke down the command to discover\n> the 'git apply' part of the pipe was silently failing to apply anything,\n> exiting 0 without even a warning.\n> \n> The exit status and lack of warning is terribly misleading, I imagine\n> this would be the cause of subtle bugs in automated scripts. \n> \n> Is this expected behaviour?\n\nYes, this is as documented in git-apply(1):\n\n   Reads the supplied diff output (i.e. \"a patch\") and applies it to\n   files. When running from a subdirectory in a repository, patched\n   paths outside the directory are ignored.\n\nI agree it's a potential source of confusion. There's some previous\ndiscussion in this thread:\n\n  https://public-inbox.org/git/CA+DCAeQQQH59Lb43Y4Bi1xktPNoODV11KkUBbKNG1OZ7mDb-UQ@mail.gmail.com/\n\n-Peff\n"}]}