git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] fsmonitor: Read from getcwd(), not the PWD environment variable

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 10, 2017, 05:04 UTC
Message-ID
<xmqqzi7ug1w2.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1a8090dfa6f273bae68cfcdd62446944bedbc8a7.1510257457.git.alexmv@dropbox.com>
Alex Vandiver <alexmv@dropbox.com> writes:
This comment is only so that I do not keep editing them while queuing..
> Subject: Re: [PATCH 1/2] fsmonitor: Read from getcwd(), not the PWD environment variable
Downcase "Read" (or any word after "<area>: " on the commit title).
Show 11 quoted lines
> 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.

Interesting observation. Why didn't anybody else notice it, I wonder?

Thanks, will queue.
Show 34 quoted lines
> Signed-off-by: Alex Vandiver <alexmv@dropbox.com>
> ---
>  t/t7519/fsmonitor-watchman                 | 3 ++-
>  templates/hooks--fsmonitor-watchman.sample | 3 ++-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/t/t7519/fsmonitor-watchman b/t/t7519/fsmonitor-watchman
> index a3e30bf54..5fe72cefa 100755
> --- a/t/t7519/fsmonitor-watchman
> +++ b/t/t7519/fsmonitor-watchman
> @@ -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;
> diff --git a/templates/hooks--fsmonitor-watchman.sample b/templates/hooks--fsmonitor-watchman.sample
> index 9a082f278..ba6d88c5f 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;
Previous: Alex VandiverNext: Ben Peart
Message 7 of 9 in “fsmonitor: Stop reading from PWD, write fsmonitor+split index right”
  1. 0/2 fsmonitor: Stop reading from PWD, write fsmonitor+split index rightAlex Vandiver, Nov 9, 2017
  2. 2/2 fsmonitor: Store fsmonitor bitmap before splitting indexAlex Vandiver, Nov 9, 2017
  3. Junio C HamanoNov 10, 2017
  4. Ben PeartNov 13, 2017
  5. Alex VandiverDec 16, 2017
  6. 1/2 fsmonitor: Read from getcwd(), not the PWD environment variableAlex Vandiver, Nov 9, 2017
  7. Junio C HamanoNov 10, 2017
  8. fsmonitor: simplify determining the git worktree under WindowsBen Peart, Nov 10, 2017
  9. Junio C HamanoNov 13, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.