[PATCH 0/4] git-p4: paths for p4

STALE3745d

6 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH 0/4] git-p4: paths for p4

From: Pete Wyckoff <hidden>
Date: 2016-06-15 22:52:36

There are two problems associated with how we set up paths for
use by p4, fixed in this series.  Each fix is accompanied by
another patch that is the unit test.

There is a break in the sequence in the t98* patches here, but
that is on purpose to avoid collision with new tests from other
in-flight patches.

1-2:
    in submit, create clientPath if it does not exist

3-4:
    in clone, make sure p4 sees an absolute path

Gary Gibbons (2):
  git-p4: ensure submit clientPath exists before chdir
  git-p4: use absolute directory for PWD env var

Pete Wyckoff (2):
  git-p4: submit test for auto-creating clientPath
  git-p4: test for absolute PWD problem

 contrib/fast-import/git-p4 |    9 ++++++-
 t/t9807-submit.sh          |   38 ++++++++++++++++++++++++++++++++++
 t/t9808-chdir.sh           |   49 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 2 deletions(-)
 create mode 100755 t/t9807-submit.sh
 create mode 100755 t/t9808-chdir.sh

-- 
1.7.8.rc4.42.g8317d

[PATCH 1/4] git-p4: ensure submit clientPath exists before chdir

From: Pete Wyckoff <hidden>
Date: 2016-06-15 22:52:36

From: Gary Gibbons <redacted>

Submitting patches back to p4 requires a p4 "client".  This
is a mapping from server depot paths into a local directory.
The directory need not exist or be populated with files; only
the mapping on the server is required.  When there is no
directory, make git-p4 automatically create it.

[ reword description --pw ]

Signed-off-by: Gary Gibbons <redacted>
Signed-off-by: Pete Wyckoff <redacted>
---
 contrib/fast-import/git-p4 |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index b975d67..99d3abe 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1099,6 +1099,10 @@ class P4Submit(Command, P4UserMap):
         print "Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath)
         self.oldWorkingDirectory = os.getcwd()
 
+        # ensure the clientPath exists
+        if not os.path.exists(self.clientPath):
+            os.makedirs(self.clientPath)
+
         chdir(self.clientPath)
         print "Synchronizing p4 checkout..."
         p4_sync("...")
-- 
1.7.8.rc4.42.g8317d

[PATCH 2/4] git-p4: submit test for auto-creating clientPath

From: Pete Wyckoff <hidden>
Date: 2016-06-15 22:52:36

Signed-off-by: Pete Wyckoff <redacted>
---
 t/t9807-submit.sh |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
 create mode 100755 t/t9807-submit.sh
diff --git a/t/t9807-submit.sh b/t/t9807-submit.sh
new file mode 100755
index 0000000..85ab0d0
--- /dev/null
+++ b/t/t9807-submit.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+test_description='git-p4 submit'
+
+. ./lib-git-p4.sh
+
+test_expect_success 'start p4d' '
+	start_p4d
+'
+
+test_expect_success 'init depot' '
+	(
+		cd "$cli" &&
+		echo file1 >file1 &&
+		p4 add file1 &&
+		p4 submit -d "change 1"
+	)
+'
+
+test_expect_success 'submit with no client dir' '
+	test_when_finished cleanup_git &&
+        "$GITP4" clone --dest="$git" //depot &&
+        (
+                cd "$git" &&
+                echo file2 >file2 &&
+                git add file2 &&
+                git commit -m "git commit 2" &&
+                rm -rf "$cli" &&
+                git config git-p4.skipSubmitEdit true &&
+                "$GITP4" submit
+	)
+'
+
+test_expect_success 'kill p4d' '
+	kill_p4d
+'
+
+test_done
-- 
1.7.8.rc4.42.g8317d

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

From: Pete Wyckoff <hidden>
Date: 2016-06-15 22:52:36

From: Gary Gibbons <redacted>

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 <redacted>
Signed-off-by: Pete Wyckoff <redacted>
---
 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

[PATCH 4/4] git-p4: test for absolute PWD problem

From: Pete Wyckoff <hidden>
Date: 2016-06-15 22:52:36

Signed-off-by: Pete Wyckoff <redacted>
---
 t/t9808-chdir.sh |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
 create mode 100755 t/t9808-chdir.sh
diff --git a/t/t9808-chdir.sh b/t/t9808-chdir.sh
new file mode 100755
index 0000000..e6fd681
--- /dev/null
+++ b/t/t9808-chdir.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+test_description='git-p4 relative chdir'
+
+. ./lib-git-p4.sh
+
+test_expect_success 'start p4d' '
+	start_p4d
+'
+
+test_expect_success 'init depot' '
+	(
+		cd "$cli" &&
+		echo file1 >file1 &&
+		p4 add file1 &&
+		p4 submit -d "change 1"
+	)
+'
+
+# P4 reads from P4CONFIG file to find its server params, if the
+# environment variable is set
+test_expect_success 'P4CONFIG and absolute dir clone' '
+	printf "P4PORT=$P4PORT\nP4CLIENT=$P4CLIENT\n" >p4config &&
+	test_when_finished "rm \"$TRASH_DIRECTORY/p4config\"" &&
+	test_when_finished cleanup_git &&
+	(
+                P4CONFIG=p4config && export P4CONFIG &&
+		unset P4PORT P4CLIENT &&
+		"$GITP4" clone --verbose --dest="$git" //depot
+	)
+'
+
+# same thing, but with relative directory name, note missing $ on --dest
+test_expect_success 'P4CONFIG and relative dir clone' '
+	printf "P4PORT=$P4PORT\nP4CLIENT=$P4CLIENT\n" >p4config &&
+	test_when_finished "rm \"$TRASH_DIRECTORY/p4config\"" &&
+	test_when_finished cleanup_git &&
+	(
+                P4CONFIG=p4config && export P4CONFIG &&
+		unset P4PORT P4CLIENT &&
+		"$GITP4" clone --verbose --dest="git" //depot
+	)
+'
+
+test_expect_success 'kill p4d' '
+	kill_p4d
+'
+
+test_done
-- 
1.7.8.rc4.42.g8317d

Re: [PATCH 0/4] git-p4: paths for p4

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:37

Thanks; will queue directly to 'master'.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help