Skip to content

Commit 25a294e

Browse files
committed
Merge branch 'nd/export-worktree' into maint
Running an aliased command from a subdirectory when the .git thing in the working tree is a gitfile pointing elsewhere did not work. * nd/export-worktree: setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR
2 parents f9610bc + d95138e commit 25a294e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

environment.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ void set_git_work_tree(const char *new_work_tree)
231231
}
232232
git_work_tree_initialized = 1;
233233
work_tree = xstrdup(real_path(new_work_tree));
234+
if (setenv(GIT_WORK_TREE_ENVIRONMENT, work_tree, 1))
235+
die("could not set GIT_WORK_TREE to '%s'", work_tree);
234236
}
235237

236238
const char *get_git_work_tree(void)

t/t0002-gitfile.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,21 @@ test_expect_success 'check rev-list' '
9999
test "$SHA" = "$(git rev-list HEAD)"
100100
'
101101

102+
test_expect_success 'setup_git_dir twice in subdir' '
103+
git init sgd &&
104+
(
105+
cd sgd &&
106+
git config alias.lsfi ls-files &&
107+
mv .git .realgit &&
108+
echo "gitdir: .realgit" >.git &&
109+
mkdir subdir &&
110+
cd subdir &&
111+
>foo &&
112+
git add foo &&
113+
git lsfi >actual &&
114+
echo foo >expected &&
115+
test_cmp expected actual
116+
)
117+
'
118+
102119
test_done

0 commit comments

Comments
 (0)