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

Re: [PATCH 2/2] worktree: add: change to new worktree directory before running hook

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 12, 2018, 20:31 UTC
Message-ID
<CAPig+cQ6Tq3J=bS8ymDqiXqUvoUiP59T=FGZgMw2FOAx0vyo=Q@mail.gmail.com>
In-Reply-To
<xmqq7erit2wo.fsf@gitster-ct.c.googlers.com>
On Mon, Feb 12, 2018 at 2:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
>> Fix this by changing to the new worktree's directory before running
>> the hook, and adjust the tests to verify that the hook is indeed run
>> within the correct directory.
>
> I like the approach taken by this replacement better.  Just to make
> sure I understand the basic idea, let me rephrase what these two
> patches are doing:
>
>  - "path" that is made absolute in this step is where the new
>    worktree is created, i.e. the top-level of the working tree in
>    the new worktree.  We chdir there and then run the hook script.

Sorry for misleading. The "absolute path" stuff in this patch is unnecessary; it's probably just left-over from Lars's proposal which did need to make it absolute when setting GIT_WORK_TREE, and I likely didn't think hard enough to realize that it doesn't need to be absolute just for chdir(). I'll drop the unnecessary absolute_pathdup() in the re-roll.

(The hook path in patch 1/2, on the other hand, does need to be made absolute since find_hook() returns a relative path before we've chdir()'d into the new worktree.)

>  - Even though we often see hooks executed inside .git/ directory,
>    for post-checkout, the top-level of the working tree is the right
>    place, as that is where the hook is run by "git checkout" [...]

Patch 1/2's commit message is a bit sloppy in its description of this. I'll tighten it up in the re-roll.

I'm also not fully convinced that these new overloads of run_hook_*() are warranted since it's hard to imagine any other case when they would be useful. It may make sense just to have builtin/worktree.c run the hook itself for this one-off case.

Show 6 quoted lines
> I wonder if we need to clear existing GIT_DIR/GIT_WORK_TREE from the
> environment, though.  When a user with a funny configuration (where
> these two environment variables are pointing at unusual places) uses
> "git worktree add" to create another worktree for the repository, it
> would not be sufficient to chdir to defeat them that are appropriate
> for the original, and not for the new, worktree, would it?
Good point. I'll look into sanitizing the environment.
Previous: Junio C HamanoNext: Lars Schneider
Message 6 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.