path: root/templates
diff options
authorAlex Vandiver <>2017-11-09 19:58:09 (GMT)
committerJunio C Hamano <>2017-11-10 05:04:50 (GMT)
commit6f1dc21d983a495877c8054d41d9b634e234ccc4 (patch)
tree66f54dd50739f5367026e6ced8bd4ba091dd04c9 /templates
parentba1b9caca69909b3c048bda1bbfab4fefb070bff (diff)
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 <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'templates')
1 files changed, 2 insertions, 1 deletions
diff --git a/templates/hooks--fsmonitor-watchman.sample b/templates/hooks--fsmonitor-watchman.sample
index 9a082f2..ba6d88c 100755
--- a/templates/hooks--fsmonitor-watchman.sample
+++ b/templates/hooks--fsmonitor-watchman.sample
@@ -40,7 +40,8 @@ if ($system =~ m/^MSYS_NT/ || $system =~ m/^MINGW/) {
$git_work_tree =~ s/[\r\n]+//g;
$git_work_tree =~ s,\\,/,g;
} else {
- $git_work_tree = $ENV{'PWD'};
+ require Cwd;
+ $git_work_tree = Cwd::cwd();
my $retry = 1;