{"thread":{"id":"41832","subject":"Issue: `git apply` doesn't respect `--work-tree`","startedAt":"2016-03-26T08:21:45Z","lastAt":"2016-03-26T08:21:45Z","messageCount":1,"participants":["Ciprian Dorin Craciun"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"281902","messageId":"CA+Tk8fwhjwj9qjgWiiDsJnCupAQT1JJTfYYgDykQhfBnXE09SQ@mail.gmail.com","threadId":"41832","inReplyTo":null,"subject":"Issue: `git apply` doesn't respect `--work-tree`","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2016-03-26T08:21:45Z","receivedAt":"2016-03-26T08:21:45Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"[I've quickly looked at the mailing list archive and didn't see this\nissue reported.  However I might be wrong.]\n\n\nThe issue is simple:  `git apply` does not respect the `--work-tree`\nargument when called outside the repository.\n\nThe version of Git I used is OpenSUSE's official 2.1.4 but also 2.7.4\nfrom their repositories.\n\nThe command I used is:\n  git --work-tree /.../some-repo --git-dir /.../some-repo/.git apply\n/.../some-patch\n\nThe current working directory is completely unrelated with the\ntargeted work-tree (i.e. it is not a subdirectory of the work-tree).\n\n\nI confirmed the above by using `strace -f -e file -- git ...`, and\nalthough Git picks the correct path for the target work-tree and\nswitches there, it then switches back to the initial working directory\n(the one being invoked from).  See bellow the (redacted) output of\n`strace`:\n\n~~~~\ngetcwd(\"{current-working-dir}\", 129) = 79\nstat(\"{target-working-dir}/.git\", {st_mode=S_IFDIR|0700, st_size=300, ...}) = 0\nlstat(\"{target-working-dir}/.git/HEAD\", {st_mode=S_IFREG|0600,\nst_size=23, ...}) = 0\nopen(\"{target-working-dir}/.git/HEAD\", O_RDONLY)  = 3\nlstat(\"{target-working-dir}/.git/commondir\", 0x7ffe0231eb90) = -1\nENOENT (No such file or directory)\naccess(\"{target-working-dir}/.git/objects\", X_OK) = 0\naccess(\"{target-working-dir}/.git/refs\", X_OK)    = 0\nlstat(\"{target-working-dir}/.git/commondir\", 0x7ffe0231eb80) = -1\nENOENT (No such file or directory)\naccess(\"{home}/.config/git/config\", R_OK) = -1 ENOENT (No such file or\ndirectory)\naccess(\"{home}/.gitconfig\", R_OK) = 0\nopen(\"{home}/.gitconfig\", O_RDONLY) = 3\naccess(\"{target-working-dir}/.git/config\", R_OK)  = 0\nopen(\"{target-working-dir}/.git/config\", O_RDONLY) = 3\nstat(\"{target-working-dir}\", {st_mode=S_IFDIR|0700, st_size=880, ...}) = 0\ngetcwd(\"{current-working-dir}\", 129) = 79\nchdir(\"{target-working-dir}\")                     = 0\ngetcwd(\"{target-working-dir}\", 139)               = 11\nlstat(\"{target-working-dir}\", {st_mode=S_IFDIR|0700, st_size=880, ...}) = 0\nchdir(\"{current-working-dir}\") = 0\nstat(\"{target-working-dir}/.git\", {st_mode=S_IFDIR|0700, st_size=300, ...}) = 0\nlstat(\"{target-working-dir}/.git/commondir\", 0x7ffe0231eb40) = -1\nENOENT (No such file or directory)\naccess(\"{home}/.config/git/config\", R_OK) = -1 ENOENT (No such file or\ndirectory)\naccess(\"{home}/.gitconfig\", R_OK) = 0\nopen(\"{home}/.gitconfig\", O_RDONLY) = 3\naccess(\"{target-working-dir}/.git/config\", R_OK)  = 0\nopen(\"{target-working-dir}/.git/config\", O_RDONLY) = 3\nopen(\"{target-diff}\", O_RDONLY)           = 3\nopen(\"{home}/.config/git/attributes\", O_RDONLY) = -1 ENOENT (No such\nfile or directory)\nopen(\".gitattributes\", O_RDONLY)        = -1 ENOENT (No such file or directory)\nopen(\"{target-working-dir}/.git/info/attributes\", O_RDONLY) = -1\nENOENT (No such file or directory)\nlstat(\"{file-to-be-patched}\", 0x7ffe0231e1f0)       = -1 ENOENT (No\nsuch file or directory)\nerror: {file-to-be-patched}: No such file or directory\n+++ exited with 1 +++\n\n\nHope it helps,\nCiprian.\n"}]}