git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Issue: `git apply` doesn't respect `--work-tree`

From
Ciprian Dorin Craciun <ciprian.craciun@gmail.com>
Date
Mar 26, 2016, 08:21 UTC
Message-ID
<CA+Tk8fwhjwj9qjgWiiDsJnCupAQT1JJTfYYgDykQhfBnXE09SQ@mail.gmail.com>

[I've quickly looked at the mailing list archive and didn't see this issue reported. However I might be wrong.]

The issue is simple: `git apply` does not respect the `--work-tree` argument when called outside the repository.

The version of Git I used is OpenSUSE's official 2.1.4 but also 2.7.4 from their repositories.

The command I used is:
  git --work-tree /.../some-repo --git-dir /.../some-repo/.git apply
/.../some-patch

The current working directory is completely unrelated with the targeted work-tree (i.e. it is not a subdirectory of the work-tree).

I confirmed the above by using `strace -f -e file -- git ...`, and although Git picks the correct path for the target work-tree and switches there, it then switches back to the initial working directory (the one being invoked from). See bellow the (redacted) output of `strace`:

~~~~ getcwd("{current-working-dir}", 129) = 79 stat("{target-working-dir}/.git", {st_mode=S_IFDIR|0700, st_size=300, ...}) = 0 lstat("{target-working-dir}/.git/HEAD", {st_mode=S_IFREG|0600, st_size=23, ...}) = 0 open("{target-working-dir}/.git/HEAD", O_RDONLY) = 3 lstat("{target-working-dir}/.git/commondir", 0x7ffe0231eb90) = -1 ENOENT (No such file or directory) access("{target-working-dir}/.git/objects", X_OK) = 0 access("{target-working-dir}/.git/refs", X_OK) = 0 lstat("{target-working-dir}/.git/commondir", 0x7ffe0231eb80) = -1 ENOENT (No such file or directory) access("{home}/.config/git/config", R_OK) = -1 ENOENT (No such file or directory) access("{home}/.gitconfig", R_OK) = 0 open("{home}/.gitconfig", O_RDONLY) = 3 access("{target-working-dir}/.git/config", R_OK) = 0 open("{target-working-dir}/.git/config", O_RDONLY) = 3 stat("{target-working-dir}", {st_mode=S_IFDIR|0700, st_size=880, ...}) = 0 getcwd("{current-working-dir}", 129) = 79 chdir("{target-working-dir}") = 0 getcwd("{target-working-dir}", 139) = 11 lstat("{target-working-dir}", {st_mode=S_IFDIR|0700, st_size=880, ...}) = 0 chdir("{current-working-dir}") = 0 stat("{target-working-dir}/.git", {st_mode=S_IFDIR|0700, st_size=300, ...}) = 0 lstat("{target-working-dir}/.git/commondir", 0x7ffe0231eb40) = -1 ENOENT (No such file or directory) access("{home}/.config/git/config", R_OK) = -1 ENOENT (No such file or directory) access("{home}/.gitconfig", R_OK) = 0 open("{home}/.gitconfig", O_RDONLY) = 3 access("{target-working-dir}/.git/config", R_OK) = 0 open("{target-working-dir}/.git/config", O_RDONLY) = 3 open("{target-diff}", O_RDONLY) = 3 open("{home}/.config/git/attributes", O_RDONLY) = -1 ENOENT (No such file or directory) open(".gitattributes", O_RDONLY) = -1 ENOENT (No such file or directory) open("{target-working-dir}/.git/info/attributes", O_RDONLY) = -1 ENOENT (No such file or directory) lstat("{file-to-be-patched}", 0x7ffe0231e1f0) = -1 ENOENT (No such file or directory) error: {file-to-be-patched}: No such file or directory +++ exited with 1 +++

Hope it helps, Ciprian.

Message 1 of 1 in “Issue: `git apply` doesn't respect `--work-tree`”
  1. Ciprian Dorin CraciunMar 26, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.