Skip to content

Commit 66102cf

Browse files
committed
Merge branch 'js/stash-apply-in-secondary-worktree'
"git stash apply" in a subdirectory of a secondary worktree failed to access the worktree correctly, which has been corrected. * js/stash-apply-in-secondary-worktree: stash apply: report status correctly even in a worktree's subdirectory
2 parents a4c5d9f + dfd557c commit 66102cf

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

builtin/stash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
497497
*/
498498
cp.git_cmd = 1;
499499
cp.dir = prefix;
500+
argv_array_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s",
501+
absolute_path(get_git_work_tree()));
502+
argv_array_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s",
503+
absolute_path(get_git_dir()));
500504
argv_array_push(&cp.args, "status");
501505
run_command(&cp);
502506
}

t/t3908-stash-in-worktree.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2019 Johannes E Schindelin
4+
#
5+
6+
test_description='Test git stash in a worktree'
7+
8+
. ./test-lib.sh
9+
10+
test_expect_success 'setup' '
11+
test_commit initial &&
12+
git worktree add wt &&
13+
test_commit -C wt in-worktree
14+
'
15+
16+
test_expect_success 'apply in subdirectory' '
17+
mkdir wt/subdir &&
18+
(
19+
cd wt/subdir &&
20+
echo modified >../initial.t &&
21+
git stash &&
22+
git stash apply >out
23+
) &&
24+
grep "\.\.\/initial\.t" wt/subdir/out
25+
'
26+
27+
test_done

0 commit comments

Comments
 (0)