Skip to content

Commit 9fb0a79

Browse files
committed
Merge branch 'ld/p4-editor-multi-words'
Unlike "$EDITOR" and "$GIT_EDITOR" that can hold the path to the command and initial options (e.g. "/path/to/emacs -nw"), 'git p4' did not let the shell interpolate the contents of the environment variable that name the editor "$P4EDITOR" (and "$EDITOR", too). Make it in line with the rest of Git, as well as with Perforce. * ld/p4-editor-multi-words: git-p4: tests: use test-chmtime in place of touch git-p4: fix handling of multi-word P4EDITOR git-p4: add failing test for P4EDITOR handling
2 parents 5455ee0 + f3b5b07 commit 9fb0a79

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

git-p4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ def edit_template(self, template_file):
12481248
editor = os.environ.get("P4EDITOR")
12491249
else:
12501250
editor = read_pipe("git var GIT_EDITOR").strip()
1251-
system([editor, template_file])
1251+
system(["sh", "-c", ('%s "$@"' % editor), editor, template_file])
12521252

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

t/t9803-git-p4-shell-metachars.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test_expect_success 'shell metachars in filenames' '
2828
echo f2 >"file with spaces" &&
2929
git add "file with spaces" &&
3030
git commit -m "add files" &&
31-
P4EDITOR=touch git p4 submit
31+
P4EDITOR="test-chmtime +5" git p4 submit
3232
) &&
3333
(
3434
cd "$cli" &&
@@ -47,7 +47,7 @@ test_expect_success 'deleting with shell metachars' '
4747
git rm foo\$bar &&
4848
git rm file\ with\ spaces &&
4949
git commit -m "remove files" &&
50-
P4EDITOR=touch git p4 submit
50+
P4EDITOR="test-chmtime +5" git p4 submit
5151
) &&
5252
(
5353
cd "$cli" &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test_expect_success 'no config, edited' '
9090
cd "$git" &&
9191
echo line >>file1 &&
9292
git commit -a -m "change 5" &&
93-
P4EDITOR="$TRASH_DIRECTORY/ed.sh" &&
93+
P4EDITOR="\"$TRASH_DIRECTORY/ed.sh\"" &&
9494
export P4EDITOR &&
9595
git p4 submit &&
9696
p4 changes //depot/... >wc &&

t/t9813-git-p4-preserve-users.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ test_expect_success 'preserve users' '
5353
git commit --author "Alice <[email protected]>" -m "a change by alice" file1 &&
5454
git commit --author "Bob <[email protected]>" -m "a change by bob" file2 &&
5555
git config git-p4.skipSubmitEditCheck true &&
56-
P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
56+
P4EDITOR="test-chmtime +5" P4USER=alice P4PASSWD=secret &&
57+
export P4EDITOR P4USER P4PASSWD &&
58+
git p4 commit --preserve-user &&
5759
p4_check_commit_author file1 alice &&
5860
p4_check_commit_author file2 bob
5961
)
@@ -69,7 +71,7 @@ test_expect_success 'refuse to preserve users without perms' '
6971
git config git-p4.skipSubmitEditCheck true &&
7072
echo "username-noperms: a change by alice" >>file1 &&
7173
git commit --author "Alice <[email protected]>" -m "perms: a change by alice" file1 &&
72-
P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
74+
P4EDITOR="test-chmtime +5" P4USER=bob P4PASSWD=secret &&
7375
export P4EDITOR P4USER P4PASSWD &&
7476
test_must_fail git p4 commit --preserve-user &&
7577
! git diff --exit-code HEAD..p4/master
@@ -87,7 +89,7 @@ test_expect_success 'preserve user where author is unknown to p4' '
8789
git commit --author "Bob <[email protected]>" -m "preserve: a change by bob" file1 &&
8890
echo "username-unknown: a change by charlie" >>file1 &&
8991
git commit --author "Charlie <[email protected]>" -m "preserve: a change by charlie" file1 &&
90-
P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
92+
P4EDITOR="test-chmtime +5" P4USER=alice P4PASSWD=secret &&
9193
export P4EDITOR P4USER P4PASSWD &&
9294
test_must_fail git p4 commit --preserve-user &&
9395
! git diff --exit-code HEAD..p4/master &&

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
test_description='git p4 handling of EDITOR'
4+
5+
. ./lib-git-p4.sh
6+
7+
test_expect_success 'start p4d' '
8+
start_p4d
9+
'
10+
11+
test_expect_success 'init depot' '
12+
(
13+
cd "$cli" &&
14+
echo file1 >file1 &&
15+
p4 add file1 &&
16+
p4 submit -d "file1"
17+
)
18+
'
19+
20+
# Check that the P4EDITOR argument can be given command-line
21+
# options, which git-p4 will then pass through to the shell.
22+
test_expect_success 'EDITOR with options' '
23+
git p4 clone --dest="$git" //depot &&
24+
test_when_finished cleanup_git &&
25+
(
26+
cd "$git" &&
27+
echo change >file1 &&
28+
git commit -m "change" file1 &&
29+
P4EDITOR=": >\"$git/touched\" && test-chmtime +5" git p4 submit &&
30+
test_path_is_file "$git/touched"
31+
)
32+
'
33+
34+
test_expect_success 'kill p4d' '
35+
kill_p4d
36+
'
37+
38+
test_done

0 commit comments

Comments
 (0)