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

Re: [PATCH] Do not trust PWD blindly

From
Johannes Sixt <j6t@kdbg.org>
Date
Jul 10, 2011, 20:47 UTC
Message-ID
<4E1A0FCC.7080308@kdbg.org>
In-Reply-To
<alpine.DEB.1.00.1107091935210.1985@bonsai2>
Am 09.07.2011 19:38, schrieb Johannes Schindelin:
> 
> At least on Windows, chdir() does not update PWD.
Very strange wording. chdir() should not update PWD even on POSIX.
Show 22 quoted lines
> Unfortunately, stat()
> does not fill any ino or dev fields anymore, so get_pwd_cwd() is not
> able to tell.
> 
> But there is a telltale: both ino and dev are 0 when they are not filled
> correctly, so let's be extra cautious.
> 
> This happens to fix a bug in "get-receive-pack working_directory/" when
> the GIT_DIR would not be set correctly due to absolute_path(".")
> returning the wrong value.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> 
> 	On Fri, 8 Jul 2011, Pat Thoyts wrote:
> 
> 	> ! t5516-fetch-push      (60 receive.denyCurrentBranch = updateInstead)
> 
> 	This patch fixes that.
> 
> 	Hannes, I have no idea whether you meant 10c4c881 to fix anything 
> 	on Windows.

I think this fix worked for me because when git is called from CMD, PWD is not in the enviornment and the if (pwd && ...) branch is never taken.

Show 18 quoted lines
> 
>  abspath.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/abspath.c b/abspath.c
> index 01858eb..37287f8 100644
> --- a/abspath.c
> +++ b/abspath.c
> @@ -102,7 +102,8 @@ static const char *get_pwd_cwd(void)
>  	pwd = getenv("PWD");
>  	if (pwd && strcmp(pwd, cwd)) {
>  		stat(cwd, &cwd_stat);
> -		if (!stat(pwd, &pwd_stat) &&
> +		if ((cwd_stat.st_dev || cwd_stat.st_ino) &&
> +		    !stat(pwd, &pwd_stat) &&
>  		    pwd_stat.st_dev == cwd_stat.st_dev &&
>  		    pwd_stat.st_ino == cwd_stat.st_ino) {
>  			strlcpy(cwd, pwd, PATH_MAX);
Acked-by: Johannes Sixt <j6t@kdbg.org>
-- Hannes
Previous: Sebastian SchuberthNext: Johannes Schindelin
Message 3 of 8 in “Do not trust PWD blindly”
  1. Do not trust PWD blindlyJohannes Schindelin, Jul 9, 2011
  2. Sebastian SchuberthJul 9, 2011
  3. Johannes SixtJul 10, 2011
  4. Johannes SchindelinJul 10, 2011
  5. Randal L. SchwartzJul 11, 2011
  6. Johannes SchindelinJul 11, 2011
  7. Junio C HamanoJul 11, 2011
  8. Johannes SchindelinJul 11, 2011

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.