Skip to contentSkip to conversation

git-p4: test t9820-git-p4-editor-handling.sh failing

PATCH In review Luke Diamand 2 participants 11 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi!

The test I put in recently for multi-word editor handling in git-p4, t9820-git-p4-editor-handling.sh, has started failing.

It looks like the reason is the change to it that goes:

- P4EDITOR="touch \"$git/touched\"" git p4 submit &&
+ P4EDITOR=": >\"$git/touched\"" git p4 submit &&

The problem is that git-p4 invokes $P4EDITOR passing it the name of the submit template. After it returns, it checks that the editor has actually updated the file's modification time.

The first version (somewhat subtly) does this; the second doesn't.

I put the extra check with "$git/touched" in just to check that P4EDITOR was being invoked at all, but I guess it's not strictly necessary. I wondered about doing this:

+ P4EDITOR=": >\"$git/touched\" && touch" git p4 submit &&

But it's possibly getting a bit obscure. I guess it could be OK with a comment.

Could it go back to the original version, or is there some other way to achieve a similar effect?

Thanks!
Luke

#1 lore raw
Quoted 11 lines · Luke Diamand

The test I put in recently for multi-word editor handling in git-p4, t9820-git-p4-editor-handling.sh, has started failing.

It looks like the reason is the change to it that goes:

(quoted diff) +1 -1
-	P4EDITOR="touch \"$git/touched\"" git p4 submit &&
+	P4EDITOR=": >\"$git/touched\"" git p4 submit &&

The problem is that git-p4 invokes $P4EDITOR passing it the name of the submit template. After it returns, it checks that the editor has actually updated the file's modification time.

Sorry, that was an unwarranted and unnecessary amend. Didn't realize that touch was trying to affect two files.

But "touch" is not quite right, either.

Unlike human sitting in front of keyboard, our fake editor types very fast and wallclock time may not change between the time when "git p4" prepares the file to be edited and the fake editor returns.

Is it really *only* the modification time that is checked? If our fake editor adds one blank line and return very fast without changing the modification time, doesn't the caller notice that (and if not, shouldn't it be fixed to do so [*1*])?

If you absolutely need to change the timestamp to work around the caller if it only checks the timestamp and does not notice the size or contents are different, then test-chmtime would be the right thing to use in the test suite to do this portably, something like.

    P4EDITOR=": >\"$git/touched\" && test-chmtime +5"

perhaps.

Thanks.

[Footnote]

*1* Yeah, I just checked. It does check only mtime and wants the
editor to spend at least one second to edit, which is silly X-<.

#2 lore raw

v3 cover git-p4: fix handling of multi-word P4EDITOR

Junio noticed that my new test was using touch, which is a bit racetastic because git-p4 wants P4EDITOR to spend at least one second editing the submit template or it will fail.

This updates the test to use test-chmtime, and also fixes the other git-p4 tests in the same way.

Luke Diamand (3):
git-p4: add failing test for P4EDITOR handling
git-p4: fix handling of multi-word P4EDITOR
git-p4: tests: use test-chmtime in place of touch

 git-p4.py                          |  2 +-
 t/t9803-git-p4-shell-metachars.sh  |  4 ++--
 t/t9805-git-p4-skip-submit-edit.sh |  4 ++--
 t/t9813-git-p4-preserve-users.sh   |  7 ++++---
 t/t9820-git-p4-editor-handling.sh  | 38 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 47 insertions(+), 8 deletions(-)
 create mode 100755 t/t9820-git-p4-editor-handling.sh
Signature · 1 line
2.4.1.502.gb11c5ab
#3 lore raw

PATCH v3 1/3 git-p4: add failing test for P4EDITOR handling

Add test case that git-p4 handles a setting of P4EDITOR that takes arguments, e.g. "gvim -f". This currently fails.

---
 t/t9820-git-p4-editor-handling.sh | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 t/t9820-git-p4-editor-handling.sh
t/t9820-git-p4-editor-handling.sh new file +39 -0
new file mode 100755
index 0000000..af924bb
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+test_description='git p4 handling of EDITOR'
+
+. ./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 "file1"
+	)
+'
+
+test_expect_failure 'EDITOR has options' '
+# Check that the P4EDITOR argument can be given command-line
+# options, which git-p4 will then pass through to the shell.
+test_expect_success 'EDITOR has options' '
+	git p4 clone --dest="$git" //depot &&
+	test_when_finished cleanup_git &&
+	(
+		cd "$git" &&
+		echo change >file1 &&
+		git commit -m "change" file1 &&
+		P4EDITOR=": >\"$git/touched\" && test-chmtime +5" git p4 submit &&
+		test_path_is_file "$git/touched"
+	)
+'
+
+test_expect_success 'kill p4d' '
+	kill_p4d
+'
+
+test_done
Signature · 1 line
2.4.1.502.gb11c5ab
#7 lore raw

PATCH v3 2/3 git-p4: fix handling of multi-word P4EDITOR

In reply to Luke Diamand

This teaches git-p4 to pass the P4EDITOR variable to the shell for expansion, so that any command-line arguments are correctly handled. Without this, git-p4 can only launch the editor if P4EDITOR is solely the path to the binary, without any arguments.

This also adjusts t9805, which relied on the previous behaviour.

---
 git-p4.py                          | 2 +-
 t/t9805-git-p4-skip-submit-edit.sh | 2 +-
 t/t9820-git-p4-editor-handling.sh  | 1 -
 3 files changed, 2 insertions(+), 3 deletions(-)
git-p4.py +1 -1
index ff132b2..de06046 100755
@@ -1220,7 +1220,7 @@ class P4Submit(Command, P4UserMap):
             editor = os.environ.get("P4EDITOR")
         else:
             editor = read_pipe("git var GIT_EDITOR").strip()
-        system([editor, template_file])
+        system(["sh", "-c", ('%s "$@"' % editor), editor, template_file])
 
         # If the file was not saved, prompt to see if this patch should
         # be skipped.  But skip this verification step if configured so.
t/t9805-git-p4-skip-submit-edit.sh +1 -1
index 8931188..5fbf904 100755
@@ -90,7 +90,7 @@ test_expect_success 'no config, edited' '
 		cd "$git" &&
 		echo line >>file1 &&
 		git commit -a -m "change 5" &&
-		P4EDITOR="$TRASH_DIRECTORY/ed.sh" &&
+		P4EDITOR="\"$TRASH_DIRECTORY/ed.sh\"" &&
 		export P4EDITOR &&
 		git p4 submit &&
 		p4 changes //depot/... >wc &&
t/t9820-git-p4-editor-handling.sh +0 -1
index af924bb..7026ef9 100755
@@ -17,7 +17,6 @@ test_expect_success 'init depot' '
 	)
 '
 
-test_expect_failure 'EDITOR has options' '
 # Check that the P4EDITOR argument can be given command-line
 # options, which git-p4 will then pass through to the shell.
 test_expect_success 'EDITOR has options' '
Signature · 1 line
2.4.1.502.gb11c5ab
#8 lore raw

PATCH v3 3/3 git-p4: tests: use test-chmtime in place of touch

In reply to Luke Diamand

Using "touch" for P4EDITOR means that the tests can be a bit racy, since git-p4 checks the timestamp has been updated and fails if the timestamp is not updated.

Use test-chmtime instead, which is designed for this.

---
 t/t9803-git-p4-shell-metachars.sh  | 4 ++--
 t/t9805-git-p4-skip-submit-edit.sh | 2 +-
 t/t9813-git-p4-preserve-users.sh   | 7 ++++---
 3 files changed, 7 insertions(+), 6 deletions(-)
t/t9803-git-p4-shell-metachars.sh +2 -2
index fbacff3..d950c7d 100755
@@ -28,7 +28,7 @@ test_expect_success 'shell metachars in filenames' '
 		echo f2 >"file with spaces" &&
 		git add "file with spaces" &&
 		git commit -m "add files" &&
-		P4EDITOR=touch git p4 submit
+		P4EDITOR="test-chmtime +5" git p4 submit
 	) &&
 	(
 		cd "$cli" &&
@@ -47,7 +47,7 @@ test_expect_success 'deleting with shell metachars' '
 		git rm foo\$bar &&
 		git rm file\ with\ spaces &&
 		git commit -m "remove files" &&
-		P4EDITOR=touch git p4 submit
+		P4EDITOR="test-chmtime +5" git p4 submit
 	) &&
 	(
 		cd "$cli" &&
t/t9805-git-p4-skip-submit-edit.sh +1 -1
index 5fbf904..dc8fc0c 100755
@@ -17,7 +17,6 @@ test_expect_success 'init depot' '
 	)
 '
 
-# this works because P4EDITOR is set to true
 test_expect_success 'no config, unedited, say yes' '
 	git p4 clone --dest="$git" //depot &&
 	test_when_finished cleanup_git &&
@@ -25,6 +24,7 @@ test_expect_success 'no config, unedited, say yes' '
 		cd "$git" &&
 		echo line >>file1 &&
 		git commit -a -m "change 2" &&
+		P4EDITOR="test-chmtime +5" &&
 		echo y | git p4 submit &&
 		p4 changes //depot/... >wc &&
 		test_line_count = 2 wc
t/t9813-git-p4-preserve-users.sh +4 -3
index 166b840..fe65788 100755
@@ -53,7 +53,8 @@ test_expect_success 'preserve users' '
 		git commit --author "Alice <[email protected]>" -m "a change by alice" file1 &&
 		git commit --author "Bob <[email protected]>" -m "a change by bob" file2 &&
 		git config git-p4.skipSubmitEditCheck true &&
-		P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
+		P4EDITOR="test-chmtime +5" P4USER=alice P4PASSWD=secret &&
+		git p4 commit --preserve-user &&
 		p4_check_commit_author file1 alice &&
 		p4_check_commit_author file2 bob
 	)
@@ -69,7 +70,7 @@ test_expect_success 'refuse to preserve users without perms' '
 		git config git-p4.skipSubmitEditCheck true &&
 		echo "username-noperms: a change by alice" >>file1 &&
 		git commit --author "Alice <[email protected]>" -m "perms: a change by alice" file1 &&
-		P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
+		P4EDITOR="test-chmtime +5" P4USER=bob P4PASSWD=secret &&
 		export P4EDITOR P4USER P4PASSWD &&
 		test_must_fail git p4 commit --preserve-user &&
 		! git diff --exit-code HEAD..p4/master
@@ -87,7 +88,7 @@ test_expect_success 'preserve user where author is unknown to p4' '
 		git commit --author "Bob <[email protected]>" -m "preserve: a change by bob" file1 &&
 		echo "username-unknown: a change by charlie" >>file1 &&
 		git commit --author "Charlie <[email protected]>" -m "preserve: a change by charlie" file1 &&
-		P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
+		P4EDITOR="test-chmtime +5" P4USER=alice P4PASSWD=secret &&
 		export P4EDITOR P4USER P4PASSWD &&
 		test_must_fail git p4 commit --preserve-user &&
 		! git diff --exit-code HEAD..p4/master &&
Signature · 1 line
2.4.1.502.gb11c5ab
#9 lore raw

Re: [PATCHv3 3/3] git-p4: tests: use test-chmtime in place of touch

Quoted 3 lines · Luke Diamand

Using "touch" for P4EDITOR means that the tests can be a bit racy, since git-p4 checks the timestamp has been updated and fails if the timestamp is not updated.

Junio - this one is incorrect where it changes t9805 around the test called "no config, unedited, say yes" (it didn't need changing at all).

I can resend all three, or just the last one. Please let me know which is easier.

Thanks
Luke

Quoted 37 lines

Use test-chmtime instead, which is designed for this.

---
  t/t9803-git-p4-shell-metachars.sh  | 4 ++--
  t/t9805-git-p4-skip-submit-edit.sh | 2 +-
  t/t9813-git-p4-preserve-users.sh   | 7 ++++---
  3 files changed, 7 insertions(+), 6 deletions(-)
t/t9803-git-p4-shell-metachars.sh +2 -2
index fbacff3..d950c7d 100755
@@ -28,7 +28,7 @@ test_expect_success 'shell metachars in filenames' '
  		echo f2 >"file with spaces" &&
  		git add "file with spaces" &&
  		git commit -m "add files" &&
-		P4EDITOR=touch git p4 submit
+		P4EDITOR="test-chmtime +5" git p4 submit
  	) &&
  	(
  		cd "$cli" &&
@@ -47,7 +47,7 @@ test_expect_success 'deleting with shell metachars' '
  		git rm foo\$bar &&
  		git rm file\ with\ spaces &&
  		git commit -m "remove files" &&
-		P4EDITOR=touch git p4 submit
+		P4EDITOR="test-chmtime +5" git p4 submit
  	) &&
  	(
  		cd "$cli" &&
t/t9805-git-p4-skip-submit-edit.sh +0 -0
index 5fbf904..dc8fc0c 100755

t/t9805-git-p4-skip-submit-edit.sh test_expect_success 'init depot' ' · line 20

Quoted 4 lines
t/t9805-git-p4-skip-submit-edit.sh +0 -1
@@ -17,7 +17,6 @@ test_expect_success 'init depot' '
  	)
  '
 
-# this works because P4EDITOR is set to true

The above line shouldn't be removed, but it's worth noting that it gets set to true in lib-git-p4.sh.

t/t9805-git-p4-skip-submit-edit.sh test_expect_success 'no config, unedited, say yes' ' · line 27

Quoted 8 lines
t/t9805-git-p4-skip-submit-edit.sh +1 -0
  test_expect_success 'no config, unedited, say yes' '
  	git p4 clone --dest="$git" //depot &&
  	test_when_finished cleanup_git &&
@@ -25,6 +24,7 @@ test_expect_success 'no config, unedited, say yes' '
  		cd "$git" &&
  		echo line >>file1 &&
  		git commit -a -m "change 2" &&
+		P4EDITOR="test-chmtime +5" &&

The above line should not be added.

Quoted 36 lines
t/t9805-git-p4-skip-submit-edit.sh +0 -0
  		echo y | git p4 submit &&
  		p4 changes //depot/... >wc &&
  		test_line_count = 2 wc
t/t9813-git-p4-preserve-users.sh +4 -3
index 166b840..fe65788 100755
@@ -53,7 +53,8 @@ test_expect_success 'preserve users' '
  		git commit --author "Alice <[email protected]>" -m "a change by alice" file1 &&
  		git commit --author "Bob <[email protected]>" -m "a change by bob" file2 &&
  		git config git-p4.skipSubmitEditCheck true &&
-		P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
+		P4EDITOR="test-chmtime +5" P4USER=alice P4PASSWD=secret &&
+		git p4 commit --preserve-user &&
  		p4_check_commit_author file1 alice &&
  		p4_check_commit_author file2 bob
  	)
@@ -69,7 +70,7 @@ test_expect_success 'refuse to preserve users without perms' '
  		git config git-p4.skipSubmitEditCheck true &&
  		echo "username-noperms: a change by alice" >>file1 &&
  		git commit --author "Alice <[email protected]>" -m "perms: a change by alice" file1 &&
-		P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
+		P4EDITOR="test-chmtime +5" P4USER=bob P4PASSWD=secret &&
  		export P4EDITOR P4USER P4PASSWD &&
  		test_must_fail git p4 commit --preserve-user &&
  		! git diff --exit-code HEAD..p4/master
@@ -87,7 +88,7 @@ test_expect_success 'preserve user where author is unknown to p4' '
  		git commit --author "Bob <[email protected]>" -m "preserve: a change by bob" file1 &&
  		echo "username-unknown: a change by charlie" >>file1 &&
  		git commit --author "Charlie <[email protected]>" -m "preserve: a change by charlie" file1 &&
-		P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
+		P4EDITOR="test-chmtime +5" P4USER=alice P4PASSWD=secret &&
  		export P4EDITOR P4USER P4PASSWD &&
  		test_must_fail git p4 commit --preserve-user &&
  		! git diff --exit-code HEAD..p4/master &&
#4 lore raw

Re: [PATCHv3 1/3] git-p4: add failing test for P4EDITOR handling

In reply to Luke Diamand

t/t9820-git-p4-editor-handling.sh line 24

Quoted 6 lines · Luke Diamand
t/t9820-git-p4-editor-handling.sh new file +6 -0
+
+test_expect_failure 'EDITOR has options' '
+# Check that the P4EDITOR argument can be given command-line
+# options, which git-p4 will then pass through to the shell.
+test_expect_success 'EDITOR has options' '
+	git p4 clone --dest="$git" //depot &&

Oops? I assume that the one before the comment should go and this one is

test_expect_failure 'Editor with an option' '

or something.

Quoted 15 lines
t/t9820-git-p4-editor-handling.sh new file +15 -0
+	test_when_finished cleanup_git &&
+	(
+		cd "$git" &&
+		echo change >file1 &&
+		git commit -m "change" file1 &&
+		P4EDITOR=": >\"$git/touched\" && test-chmtime +5" git p4 submit &&
+		test_path_is_file "$git/touched"
+	)
+'
+
+test_expect_success 'kill p4d' '
+	kill_p4d
+'
+
+test_done
#5 lore raw

Re: [PATCHv3 1/3] git-p4: add failing test for P4EDITOR handling

Quoted 12 lines · Junio C Hamano

t/t9820-git-p4-editor-handling.sh line 24

Quoted 6 lines · Luke Diamand
t/t9820-git-p4-editor-handling.sh new file +6 -0
+
+test_expect_failure 'EDITOR has options' '
+# Check that the P4EDITOR argument can be given command-line
+# options, which git-p4 will then pass through to the shell.
+test_expect_success 'EDITOR has options' '
+	git p4 clone --dest="$git" //depot &&

Oops? I assume that the one before the comment should go and this one is

Quoted 3 lines

test_expect_failure 'Editor with an option' '

or something.

I'll queue the three patches, each of them followed with its own SQUASH commit. Could you sanity check them? If everything looks OK then I'll just squash them and that way we can save back-and-forth.

Thanks.

#6 lore raw

Re: [PATCHv3 1/3] git-p4: add failing test for P4EDITOR handling

Quoted 14 lines · Junio C Hamano
Quoted 12 lines · Junio C Hamano

t/t9820-git-p4-editor-handling.sh line 24

Quoted 6 lines · Luke Diamand
t/t9820-git-p4-editor-handling.sh new file +6 -0
+
+test_expect_failure 'EDITOR has options' '
+# Check that the P4EDITOR argument can be given command-line
+# options, which git-p4 will then pass through to the shell.
+test_expect_success 'EDITOR has options' '
+	git p4 clone --dest="$git" //depot &&

Oops? I assume that the one before the comment should go and this one is

Quoted 7 lines
Quoted 3 lines

test_expect_failure 'Editor with an option' '

or something.

I'll queue the three patches, each of them followed with its own SQUASH commit. Could you sanity check them? If everything looks OK then I'll just squash them and that way we can save back-and-forth.

That would be great, thanks!

#10 lore raw

Re: [PATCHv3 3/3] git-p4: tests: use test-chmtime in place of touch

In reply to Luke Diamand

t/t9813-git-p4-preserve-users.sh test_expect_success 'preserve users' ' · line 57

Quoted 11 lines · Luke Diamand
t/t9813-git-p4-preserve-users.sh +2 -1
index 166b840..fe65788 100755
@@ -53,7 +53,8 @@ test_expect_success 'preserve users' '
 		git commit --author "Alice <[email protected]>" -m "a change by alice" file1 &&
 		git commit --author "Bob <[email protected]>" -m "a change by bob" file2 &&
 		git config git-p4.skipSubmitEditCheck true &&
-		P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
+		P4EDITOR="test-chmtime +5" P4USER=alice P4PASSWD=secret &&
+		git p4 commit --preserve-user &&

I think this hunk is wrong; we need to either change && to \ to make it a single logical line that exports three environment variables only to "git p4 commit --preserve-user", or insert "export P4EDITOR P4USER P4PASSWD &&" between these two lines.

The latter seems to be what the remainder of the test is doing, so I'd fix this up to mimick them.

Sorry for not catching it in the earlier review.

Thanks.

Quoted 9 lines
t/t9813-git-p4-preserve-users.sh +1 -1
@@ -69,7 +70,7 @@ test_expect_success 'refuse to preserve users without perms' '
 		git config git-p4.skipSubmitEditCheck true &&
 		echo "username-noperms: a change by alice" >>file1 &&
 		git commit --author "Alice <[email protected]>" -m "perms: a change by alice" file1 &&
-		P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
+		P4EDITOR="test-chmtime +5" P4USER=bob P4PASSWD=secret &&
 		export P4EDITOR P4USER P4PASSWD &&
 		test_must_fail git p4 commit --preserve-user &&
 		! git diff --exit-code HEAD..p4/master