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

Re: [PATCH v2] worktree: add: fix 'post-checkout' not knowing new worktree location

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 15, 2018, 21:27 UTC
Message-ID
<20180215212751.GA42108@flurp.local>
In-Reply-To
<xmqqh8qi7z7o.fsf@gitster-ct.c.googlers.com>
On Thu, Feb 15, 2018 at 12:52:11PM -0800, Junio C Hamano wrote:
Show 15 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
> >  test_expect_success '"add" invokes post-checkout hook (branch)' '
> >  	post_checkout_hook &&
> > -	printf "%s %s 1\n" $_z40 $(git rev-parse HEAD) >hook.expect &&
> > +	{
> > +		echo $_z40 $(git rev-parse HEAD) 1 &&
> > +		echo $(pwd)/.git/worktrees/gumby &&
> > +		echo $(pwd)/gumby
> > +	} >hook.expect &&
> >  	git worktree add gumby &&
> > -	test_cmp hook.expect hook.actual
> > +	test_cmp hook.expect gumby/hook.actual
> >  '
> 
> This seems to segfault on me, without leaving hook.actual anywhere.

I'm unable to reproduce the segfault, but I'm guessing it's because I'm a dummy. Can you squash in the following and retry?

--- >8 ---
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 604a0292b0..f69f862947 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -348,7 +348,7 @@ static int add_worktree(const char *path, const char *refname,
 	if (!ret && opts->checkout) {
 		const char *hook = find_hook("post-checkout");
 		if (hook) {
-			const char *env[] = { "GIT_DIR", "GIT_WORK_TREE" };
+			const char *env[] = { "GIT_DIR", "GIT_WORK_TREE", NULL };
 			cp.git_cmd = 0;
 			cp.no_stdin = 1;
 			cp.stdout_to_stderr = 1;
--- >8 ---

If that fixes it, can you squash it locally or should I re-send?
Previous: Junio C HamanoNext: Junio C Hamano
Message 17 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.