Skip to content

Commit 6f1dc21

Browse files
Alex Vandivergitster
authored andcommitted
fsmonitor: read from getcwd(), not the PWD environment variable
Though the process has chdir'd to the root of the working tree, the PWD environment variable is only guaranteed to be updated accordingly if a shell is involved -- which is not guaranteed to be the case. That is, if `/usr/bin/perl` is a binary, $ENV{PWD} is unchanged from whatever spawned `git` -- if `/usr/bin/perl` is a trivial shell wrapper to the real `perl`, `$ENV{PWD}` will have been updated to the root of the working copy. Update to read from the Cwd module using the `getcwd` syscall, not the PWD environment variable. The Cygwin case is left unchanged, as it necessarily _does_ go through a shell. Signed-off-by: Alex Vandiver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ba1b9ca commit 6f1dc21

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

t/t7519/fsmonitor-watchman

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ if ($system =~ m/^MSYS_NT/ || $system =~ m/^MINGW/) {
4141
$git_work_tree =~ s/[\r\n]+//g;
4242
$git_work_tree =~ s,\\,/,g;
4343
} else {
44-
$git_work_tree = $ENV{'PWD'};
44+
require Cwd;
45+
$git_work_tree = Cwd::cwd();
4546
}
4647

4748
my $retry = 1;

templates/hooks--fsmonitor-watchman.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ if ($system =~ m/^MSYS_NT/ || $system =~ m/^MINGW/) {
4040
$git_work_tree =~ s/[\r\n]+//g;
4141
$git_work_tree =~ s,\\,/,g;
4242
} else {
43-
$git_work_tree = $ENV{'PWD'};
43+
require Cwd;
44+
$git_work_tree = Cwd::cwd();
4445
}
4546

4647
my $retry = 1;

0 commit comments

Comments
 (0)