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

[PATCH] Do not trust PWD blindly

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 9, 2011, 17:38 UTC
Message-ID
<alpine.DEB.1.00.1107091935210.1985@bonsai2>
In-Reply-To
<CABNJ2GKgzXGDq9FhKcVP380bs=rEKqYdrOaCb+A99_TBm7A4_A@mail.gmail.com>

At least on Windows, chdir() does not update PWD. 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.
 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);
-- 
1.7.6.rc0.4047.g15f89
Next: Sebastian Schuberth
Message 1 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.