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

[PATCH 0/2] worktree: change to new worktree dir before running hook(s)

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 12, 2018, 03:15 UTC
Message-ID
<20180212031526.40039-1-sunshine@sunshineco.com>
In-Reply-To
<20180210010132.33629-1-lars.schneider@autodesk.com>

This patch series replaces "worktree: set worktree environment in post-checkout hook"[1] from Lars, which is a proposed bug fix for ade546be47 (worktree: invoke post-checkout hook, 2017-12-07).

The problem that patch addresses is that "git worktree add" does not provide proper context to the invoked 'post-checkout' hook, so the hook doesn't know where the newly-created worktree is. Lars's approach was to set GIT_WORK_TREE to point at the new worktree directory, however, doing so has a few drawbacks:

1. GIT_WORK_TREE is normally assigned in conjunction with GIT_DIR; it is
   unusual and possibly problematic to set one but not the other.
2. Assigning GIT_WORK_TREE unconditionally may lead to unforeseen
   interactions and problems with end-user scripts and aliases or even
   within Git itself. It seems better to avoid unconditional assignment
   rather than risk problems such as those described and worked around
   by 86d26f240f (setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE
   when .., 2015-12-20)
3. Assigning GIT_WORK_TREE is too specialized a solution; it "fixes"
   only Git commands run by the hook, but does nothing for other
   commands ('mv', 'cp', etc.) that the hook might invoke.

The real problem with ade546be47 is that it neglects to change to the directory of the newly-created worktree before running the hook, thus the hook incorrectly runs in the directory in which "git worktree add" was invoked. Rather than messing with GIT_WORK_TREE, this replacement patch series fixes the problem by ensuring that the directory is changed before the hook is invoked.

[1]: https://public-inbox.org/git/20180210010132.33629-1-lars.schneider@autodesk.com/
Eric Sunshine (2):
  run-command: teach 'run_hook' about alternate worktrees
  worktree: add: change to new worktree directory before running hook
 builtin/worktree.c      | 11 ++++++++---
 run-command.c           | 23 +++++++++++++++++++++--
 run-command.h           |  4 ++++
 t/t2025-worktree-add.sh | 25 ++++++++++++++++++++++---
 4 files changed, 55 insertions(+), 8 deletions(-)
-- 
2.16.1.291.g4437f3f132
Previous: Lars SchneiderNext: Eric Sunshine
Message 3 of 24 in “worktree: set worktree environment in post-checkout hook”
  1. worktree: set worktree environment in post-checkout hooklars.schneider@autodesk.com, Feb 10, 2018
  2. Lars SchneiderFeb 10, 2018
  3. 0/2 worktree: change to new worktree dir before running hook(s)Eric Sunshine, Feb 12, 2018
  4. 2/2 worktree: add: change to new worktree directory before running hookEric Sunshine, Feb 12, 2018
  5. Junio C HamanoFeb 12, 2018
  6. Eric SunshineFeb 12, 2018
  7. Lars SchneiderFeb 12, 2018
  8. Eric SunshineFeb 13, 2018
  9. Eric SunshineFeb 13, 2018
  10. Johannes SixtFeb 13, 2018
  11. Eric SunshineFeb 13, 2018
  12. 1/2 run-command: teach 'run_hook' about alternate worktreesEric Sunshine, Feb 12, 2018
  13. Lars SchneiderFeb 12, 2018
  14. Eric SunshineFeb 12, 2018
  15. worktree: add: fix 'post-checkout' not knowing new worktree locationEric Sunshine, Feb 15, 2018
  16. Junio C HamanoFeb 15, 2018
  17. Eric SunshineFeb 15, 2018
  18. Junio C HamanoFeb 15, 2018
  19. Eric SunshineFeb 15, 2018
  20. worktree: add: fix 'post-checkout' not knowing new worktree locationEric Sunshine, Feb 15, 2018
  21. Lars SchneiderFeb 16, 2018
  22. Eric SunshineFeb 16, 2018
  23. Junio C HamanoFeb 16, 2018
  24. Eric SunshineFeb 12, 2018

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.