git p4 test: do not pollute /tmp

Generating the submit template for p4 uses tempfile.mkstemp(), which by default puts files in /tmp. For a test that fails, possibly on purpose, this is not cleaned up. Run with TMPDIR pointing into the trash directory so the temp files go away with the test results. To do this required some other minor changes. First, the editor is launched using system(editor + " " + template_file), using shell expansion to build the command string. This doesn't work if editor has a space in it. And is generally unwise as it's easy to fool the shell into doing extra work. Exec the args directly, without shell expansion. Second, without shell expansion, the trick of "P4EDITOR=:" used in the tests doesn't work. Use a real command, true, as the non-interactive editor for testing. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Jan 21, 2014 at 18:16 UTC 0cf1b72a38e6190a7e614bbc53fbb81704a3d4af
3 files changed +12 -4
git-p4.py
+1 -1
@@ -1220,7 +1220,7 @@ class P4Submit(Command, P4UserMap):
1220 editor = os.environ.get("P4EDITOR")
1221 else:
1222 editor = read_pipe("git var GIT_EDITOR").strip()
1223 - system(editor + " " + template_file)
1223 + system([editor, template_file])
1224
1225 # If the file was not saved, prompt to see if this patch should
1226 # be skipped. But skip this verification step if configured so.
t/lib-git-p4.sh
+7 -1
@@ -48,7 +48,7 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
48 P4PORT=localhost:$P4DPORT
49 P4CLIENT=client
50 P4USER=author
51 -P4EDITOR=:
51 +P4EDITOR=true
52 unset P4CHARSET
53 export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
54
@@ -57,6 +57,12 @@ cli="$TRASH_DIRECTORY/cli"
57 git="$TRASH_DIRECTORY/git"
58 pidfile="$TRASH_DIRECTORY/p4d.pid"
59
60 +# git p4 submit generates a temp file, which will
61 +# not get cleaned up if the submission fails. Don't
62 +# clutter up /tmp on the test machine.
63 +TMPDIR="$TRASH_DIRECTORY"
64 +export TMPDIR
65 +
66 start_p4d() {
67 mkdir -p "$db" "$cli" "$git" &&
68 rm -f "$pidfile" &&
t/t9805-git-p4-skip-submit-edit.sh
+4 -2
@@ -17,7 +17,7 @@ test_expect_success 'init depot' '
17 )
18 '
19
20 -# this works because EDITOR is set to :
20 +# this works because P4EDITOR is set to true
21 test_expect_success 'no config, unedited, say yes' '
22 git p4 clone --dest="$git" //depot &&
23 test_when_finished cleanup_git &&
@@ -90,7 +90,9 @@ test_expect_success 'no config, edited' '
90 cd "$git" &&
91 echo line >>file1 &&
92 git commit -a -m "change 5" &&
93 - P4EDITOR="" EDITOR="\"$TRASH_DIRECTORY/ed.sh\"" git p4 submit &&
93 + P4EDITOR="$TRASH_DIRECTORY/ed.sh" &&
94 + export P4EDITOR &&
95 + git p4 submit &&
96 p4 changes //depot/... >wc &&
97 test_line_count = 5 wc
98 )