git-p4: paths for p4
cover git-p4: paths for p4
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
Signature · 1 line
1.7.8.rc4.42.g8317d
PATCH 1/4 git-p4: ensure submit clientPath exists before chdir
From: Gary Gibbons <[email protected]>
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 ]
--- contrib/fast-import/git-p4 | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
contrib/fast-import/git-p4 +4 -0
@@ -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("...")
Signature · 1 line
1.7.8.rc4.42.g8317d
PATCH 2/4 git-p4: submit test for auto-creating clientPath
In reply to Pete Wyckoff--- t/t9807-submit.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) create mode 100755 t/t9807-submit.sh
t/t9807-submit.sh new file +38 -0
@@ -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
Signature · 1 line
1.7.8.rc4.42.g8317d
PATCH 3/4 git-p4: use absolute directory for PWD env var
In reply to Pete WyckoffFrom: Gary Gibbons <[email protected]>
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 ]
--- contrib/fast-import/git-p4 | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
contrib/fast-import/git-p4 +3 -2
@@ -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:
Signature · 1 line
1.7.8.rc4.42.g8317d
PATCH 4/4 git-p4: test for absolute PWD problem
In reply to Pete Wyckoff--- t/t9808-chdir.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-) create mode 100755 t/t9808-chdir.sh
t/t9808-chdir.sh new file +49 -0
@@ -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
Signature · 1 line
1.7.8.rc4.42.g8317d
Thanks; will queue directly to 'master'.