diff --git a/git-p4.py b/git-p4.py index 41a77e6648ddad9a7599452bf361fd13ff4dcf88..ca6bb95c573608f8477ed7f3388c5df1e63f8041 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1248,7 +1248,7 @@ def edit_template(self, template_file): 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. diff --git a/t/t9803-git-p4-shell-metachars.sh b/t/t9803-git-p4-shell-metachars.sh index fbacff34fed6607ec3d0470a28a9fde31bfa7c0c..d950c7d665498c484f83d127cd2363def5169a89 100755 --- a/t/t9803-git-p4-shell-metachars.sh +++ b/t/t9803-git-p4-shell-metachars.sh @@ -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" && diff --git a/t/t9805-git-p4-skip-submit-edit.sh b/t/t9805-git-p4-skip-submit-edit.sh index 89311886db168e6613fa98d9c7a340d460435585..5fbf904dc8f4df7de522d0eecbca133d7299259d 100755 --- a/t/t9805-git-p4-skip-submit-edit.sh +++ b/t/t9805-git-p4-skip-submit-edit.sh @@ -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 && diff --git a/t/t9813-git-p4-preserve-users.sh b/t/t9813-git-p4-preserve-users.sh index 166b840bfae01d65e02d9ac7f7187142829d4f5f..0fe23128070745750b54843bfb05a7822f41c285 100755 --- a/t/t9813-git-p4-preserve-users.sh +++ b/t/t9813-git-p4-preserve-users.sh @@ -53,7 +53,9 @@ test_expect_success 'preserve users' ' git commit --author "Alice " -m "a change by alice" file1 && git commit --author "Bob " -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' ' git config git-p4.skipSubmitEditCheck true && echo "username-noperms: a change by alice" >>file1 && git commit --author "Alice " -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' ' git commit --author "Bob " -m "preserve: a change by bob" file1 && echo "username-unknown: a change by charlie" >>file1 && git commit --author "Charlie " -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 && diff --git a/t/t9820-git-p4-editor-handling.sh b/t/t9820-git-p4-editor-handling.sh new file mode 100755 index 0000000000000000000000000000000000000000..6dc6df032ec0c15b39dccd24ade52580fc115add --- /dev/null +++ b/t/t9820-git-p4-editor-handling.sh @@ -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