Skip to content

Commit 0cf1b72

Browse files
Pete Wyckoffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0055b56 commit 0cf1b72

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

git-p4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ def edit_template(self, template_file):
12201220
editor = os.environ.get("P4EDITOR")
12211221
else:
12221222
editor = read_pipe("git var GIT_EDITOR").strip()
1223-
system(editor + " " + template_file)
1223+
system([editor, template_file])
12241224

12251225
# If the file was not saved, prompt to see if this patch should
12261226
# be skipped. But skip this verification step if configured so.

t/lib-git-p4.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
4848
P4PORT=localhost:$P4DPORT
4949
P4CLIENT=client
5050
P4USER=author
51-
P4EDITOR=:
51+
P4EDITOR=true
5252
unset P4CHARSET
5353
export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
5454

@@ -57,6 +57,12 @@ cli="$TRASH_DIRECTORY/cli"
5757
git="$TRASH_DIRECTORY/git"
5858
pidfile="$TRASH_DIRECTORY/p4d.pid"
5959

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+
6066
start_p4d() {
6167
mkdir -p "$db" "$cli" "$git" &&
6268
rm -f "$pidfile" &&

t/t9805-git-p4-skip-submit-edit.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_expect_success 'init depot' '
1717
)
1818
'
1919

20-
# this works because EDITOR is set to :
20+
# this works because P4EDITOR is set to true
2121
test_expect_success 'no config, unedited, say yes' '
2222
git p4 clone --dest="$git" //depot &&
2323
test_when_finished cleanup_git &&
@@ -90,7 +90,9 @@ test_expect_success 'no config, edited' '
9090
cd "$git" &&
9191
echo line >>file1 &&
9292
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 &&
9496
p4 changes //depot/... >wc &&
9597
test_line_count = 5 wc
9698
)

0 commit comments

Comments
 (0)