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

Re: [PATCH 1/1] stash apply: report status correctly even in a worktree's subdirectory

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 3, 2019, 22:22 UTC
Message-ID
<xmqqk19lbha6.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<a687c16b824ec9ab45d1e2c39a5470ed89153fc0.1569415522.git.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 13 quoted lines
> diff --git a/builtin/stash.c b/builtin/stash.c
> index b5a301f24d..a1e2e7ae7e 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -497,6 +497,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
>  		 */
>  		cp.git_cmd = 1;
>  		cp.dir = prefix;
> +		argv_array_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s",
> +				 absolute_path(get_git_work_tree()));
>  		argv_array_push(&cp.args, "status");
>  		run_command(&cp);
>  	}

Nicely spotted. Exporting GIT_WORK_TREE alone without GIT_DIR feels a bit disturbing, at least to me, though.

I wondered if this misbehaves when the end user has GIT_WORK_TREE environment exported, but in such a case, get_git_work_tree() would return that directory, and by re-exporting it to the child process, we would honor the end user's intention, so all is good, I think.

Thanks.
Show 33 quoted lines
> diff --git a/t/t3908-stash-in-worktree.sh b/t/t3908-stash-in-worktree.sh
> new file mode 100755
> index 0000000000..2b2b366ef9
> --- /dev/null
> +++ b/t/t3908-stash-in-worktree.sh
> @@ -0,0 +1,27 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2019 Johannes E Schindelin
> +#
> +
> +test_description='Test git stash in a worktree'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'setup' '
> +	test_commit initial &&
> +	git worktree add wt &&
> +	test_commit -C wt in-worktree
> +'
> +
> +test_expect_success 'apply in subdirectory' '
> +	mkdir wt/subdir &&
> +	(
> +		cd wt/subdir &&
> +		echo modified >../initial.t &&
> +		git stash &&
> +		git stash apply >out
> +	) &&
> +	grep "\.\.\/initial\.t" wt/subdir/out
> +'
> +
> +test_done
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 3 of 6 in “stash apply: be prepared to run in a worktree's subdirectory”
  1. 0/1 stash apply: be prepared to run in a worktree's subdirectoryJohannes Schindelin via GitGitGadget, Sep 25, 2019
  2. 1/1 stash apply: report status correctly even in a worktree's subdirectoryJohannes Schindelin via GitGitGadget, Sep 25, 2019
  3. Junio C HamanoOct 3, 2019
  4. Johannes SchindelinOct 4, 2019
  5. 0/1 stash apply: be prepared to run in a worktree's subdirectoryJohannes Schindelin via GitGitGadget, Oct 4, 2019
  6. 1/1 stash apply: report status correctly even in a worktree's subdirectoryJohannes Schindelin via GitGitGadget, Oct 4, 2019

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.