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

[PATCH 3/4] git-p4: use absolute directory for PWD env var

From
PWPete Wyckoff <pw@padd.com>
Date
Dec 9, 2011, 23:48 UTC
Message-ID
<1323474497-14339-4-git-send-email-pw@padd.com>
In-Reply-To
<1323474497-14339-1-git-send-email-pw@padd.com>
From: Gary Gibbons <ggibbons@perforce.com>

P4 only looks at the environment variable $PWD to figure out where it is, so chdir() has code to set that every time. But when the clone --destination is not an absolute path, PWD will not be absolute and P4 won't be able to find any files expected to be in the current directory. Fix this by expanding PWD to an absolute path.

One place this crops up is when using a P4CONFIG environment variable to specify P4 parameters, such as P4USER or P4PORT. Setting P4CONFIG=.p4config works for p4 invocations from the current directory. But if the value of PWD is not absolute, it fails.

[ update description --pw ]
Signed-off-by: Gary Gibbons <ggibbons@perforce.com>
Signed-off-by: Pete Wyckoff <pw@padd.com>
---
 contrib/fast-import/git-p4 |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 99d3abe..0083f86 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -53,9 +53,10 @@ def p4_build_cmd(cmd):
 
 def chdir(dir):
     # P4 uses the PWD environment variable rather than getcwd(). Since we're
-    # not using the shell, we have to set it ourselves.
-    os.environ['PWD']=dir
+    # not using the shell, we have to set it ourselves.  This path could
+    # be relative, so go there first, then figure out where we ended up.
     os.chdir(dir)
+    os.environ['PWD'] = os.getcwd()
 
 def die(msg):
     if verbose:
-- 
1.7.8.rc4.42.g8317d
Previous: Pete WyckoffNext: Pete Wyckoff
Message 4 of 6 in “git-p4: paths for p4”
  1. 0/4 git-p4: paths for p4Pete Wyckoff, Dec 9, 2011
  2. 1/4 git-p4: ensure submit clientPath exists before chdirPete Wyckoff, Dec 9, 2011
  3. 2/4 git-p4: submit test for auto-creating clientPathPete Wyckoff, Dec 9, 2011
  4. 3/4 git-p4: use absolute directory for PWD env varPete Wyckoff, Dec 9, 2011
  5. 4/4 git-p4: test for absolute PWD problemPete Wyckoff, Dec 9, 2011
  6. Junio C HamanoDec 12, 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.