]> granicus.if.org Git - git/commitdiff
fsmonitor: read from getcwd(), not the PWD environment variable
authorAlex Vandiver <alexmv@dropbox.com>
Thu, 9 Nov 2017 19:58:09 +0000 (11:58 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Nov 2017 05:04:50 +0000 (14:04 +0900)
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 <alexmv@dropbox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7519/fsmonitor-watchman
templates/hooks--fsmonitor-watchman.sample

index a3e30bf54fc2f1bf4fbb3ce48fa13e33b2e6b346..5fe72cefaf89da7bc8d592fa264353ae992f1ed7 100755 (executable)
@@ -41,7 +41,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;
index 9a082f278116782c3e28af6517f2b7140224de97..ba6d88c5f8c46f51b4655364a936dc60a71fec12 100755 (executable)
@@ -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;