Browse Source

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
maint
Junio C Hamano 10 years ago
parent
commit
9fb0a798a7
  1. 2
      git-p4.py
  2. 4
      t/t9803-git-p4-shell-metachars.sh
  3. 2
      t/t9805-git-p4-skip-submit-edit.sh
  4. 8
      t/t9813-git-p4-preserve-users.sh
  5. 38
      t/t9820-git-p4-editor-handling.sh

2
git-p4.py

@ -1248,7 +1248,7 @@ class P4Submit(Command, P4UserMap): @@ -1248,7 +1248,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.

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

@ -28,7 +28,7 @@ test_expect_success 'shell metachars in filenames' ' @@ -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' ' @@ -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" &&

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

@ -90,7 +90,7 @@ test_expect_success 'no config, edited' ' @@ -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 &&

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

@ -53,7 +53,9 @@ test_expect_success 'preserve users' ' @@ -53,7 +53,9 @@ test_expect_success 'preserve users' '
git commit --author "Alice <alice@example.com>" -m "a change by alice" file1 &&
git commit --author "Bob <bob@example.com>" -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 &&
export P4EDITOR P4USER P4PASSWD &&
git p4 commit --preserve-user &&
p4_check_commit_author file1 alice &&
p4_check_commit_author file2 bob
)
@ -69,7 +71,7 @@ test_expect_success 'refuse to preserve users without perms' ' @@ -69,7 +71,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 <alice@example.com>" -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 +89,7 @@ test_expect_success 'preserve user where author is unknown to p4' ' @@ -87,7 +89,7 @@ test_expect_success 'preserve user where author is unknown to p4' '
git commit --author "Bob <bob@example.com>" -m "preserve: a change by bob" file1 &&
echo "username-unknown: a change by charlie" >>file1 &&
git commit --author "Charlie <charlie@example.com>" -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 &&

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

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
#!/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"
)
'

# 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 with 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
Loading…
Cancel
Save