git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>,
	Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH v2 3/6] t3404: remove uneeded calls to set_fake_editor
Date: Tue, 15 Oct 2019 10:25:29 +0000	[thread overview]
Message-ID: <09857dee784910b2123764be8cced9364dac4844.1571135132.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.388.v2.git.1571135132.gitgitgadget@gmail.com>

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Some tests were calling set_fake_editor to ensure they had a sane no-op
editor set. Now that all the editor setting is done in subshells these
tests can rely on EDITOR=: and so do not need to call set_fake_editor.

Also add a test at the end to detect any future additions messing with
the exported value of $EDITOR.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 t/lib-rebase.sh               | 28 ++++++++++++++++++++++++++++
 t/t3404-rebase-interactive.sh | 25 +++++--------------------
 2 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 7ea30e5006..e4554db85e 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -118,3 +118,31 @@ make_empty () {
 	git commit --allow-empty -m "$1" &&
 	git tag "$1"
 }
+
+# Call this (inside test_expect_success) at the end of a test file to
+# check that no tests have changed editor related environment
+# variables or config settings
+test_editor_unchanged () {
+	# We're only interested in exported variables hence 'sh -c'
+	sh -c 'cat >actual <<-EOF
+	EDITOR=$EDITOR
+	FAKE_COMMIT_AMEND=$FAKE_COMMIT_AMEND
+	FAKE_COMMIT_MESSAGE=$FAKE_COMMIT_MESSAGE
+	FAKE_LINES=$FAKE_LINES
+	GIT_EDITOR=$GIT_EDITOR
+	GIT_SEQUENCE_EDITOR=$GIT_SEQUENCE_EDITOR
+	core.editor=$(git config core.editor)
+	sequence.editor=$(git config sequence.editor)
+	EOF'
+	cat >expect <<-\EOF
+	EDITOR=:
+	FAKE_COMMIT_AMEND=
+	FAKE_COMMIT_MESSAGE=
+	FAKE_LINES=
+	GIT_EDITOR=
+	GIT_SEQUENCE_EDITOR=
+	core.editor=
+	sequence.editor=
+	EOF
+	test_cmp expect actual
+}
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index cb9b210000..c5d0326825 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -189,7 +189,6 @@ test_expect_success 'implicit interactive rebase does not invoke sequence editor
 
 test_expect_success 'no changes are a nop' '
 	git checkout branch2 &&
-	set_fake_editor &&
 	git rebase -i F &&
 	test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
 	test $(git rev-parse I) = $(git rev-parse HEAD)
@@ -199,7 +198,6 @@ test_expect_success 'test the [branch] option' '
 	git checkout -b dead-end &&
 	git rm file6 &&
 	git commit -m "stop here" &&
-	set_fake_editor &&
 	git rebase -i F branch2 &&
 	test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
 	test $(git rev-parse I) = $(git rev-parse branch2) &&
@@ -208,7 +206,6 @@ test_expect_success 'test the [branch] option' '
 
 test_expect_success 'test --onto <branch>' '
 	git checkout -b test-onto branch2 &&
-	set_fake_editor &&
 	git rebase -i --onto branch1 F &&
 	test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
 	test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
@@ -218,7 +215,6 @@ test_expect_success 'test --onto <branch>' '
 test_expect_success 'rebase on top of a non-conflicting commit' '
 	git checkout branch1 &&
 	git tag original-branch1 &&
-	set_fake_editor &&
 	git rebase -i branch2 &&
 	test file6 = $(git diff --name-only original-branch1) &&
 	test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
@@ -264,7 +260,6 @@ test_expect_success 'stop on conflicting pick' '
 	>>>>>>> 5d18e54... G
 	EOF
 	git tag new-branch1 &&
-	set_fake_editor &&
 	test_must_fail git rebase -i master &&
 	test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
 	test_cmp expect .git/rebase-merge/patch &&
@@ -293,7 +288,6 @@ test_expect_success 'abort' '
 test_expect_success 'abort with error when new base cannot be checked out' '
 	git rm --cached file1 &&
 	git commit -m "remove file in base" &&
-	set_fake_editor &&
 	test_must_fail git rebase -i master > output 2>&1 &&
 	test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
 		output &&
@@ -308,7 +302,6 @@ test_expect_success 'retain authorship' '
 	test_tick &&
 	GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
 	git tag twerp &&
-	set_fake_editor &&
 	git rebase -i --onto master HEAD^ &&
 	git show HEAD | grep "^Author: Twerp Snog"
 '
@@ -326,7 +319,6 @@ test_expect_success 'retain authorship w/ conflicts' '
 	test_commit b conflict b conflict-b &&
 	GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
 
-	set_fake_editor &&
 	test_must_fail git rebase -i conflict-a &&
 	echo resolved >conflict &&
 	git add conflict &&
@@ -357,7 +349,6 @@ test_expect_success 'retain authorship when squashing' '
 
 test_expect_success REBASE_P '-p handles "no changes" gracefully' '
 	HEAD=$(git rev-parse HEAD) &&
-	set_fake_editor &&
 	git rebase -i -p HEAD^ &&
 	git update-index --refresh &&
 	git diff-files --quiet &&
@@ -404,7 +395,6 @@ test_expect_success REBASE_P 'preserve merges with -p' '
 	git commit -m M file1 &&
 	git checkout -b to-be-rebased &&
 	test_tick &&
-	set_fake_editor &&
 	git rebase -i -p --onto branch1 master &&
 	git update-index --refresh &&
 	git diff-files --quiet &&
@@ -450,7 +440,6 @@ test_expect_success '--continue tries to commit' '
 test_expect_success 'verbose flag is heeded, even after --continue' '
 	git reset --hard master@{1} &&
 	test_tick &&
-	set_fake_editor &&
 	test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
 	echo resolved > file1 &&
 	git add file1 &&
@@ -750,7 +739,6 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' '
 	GIT_EDITOR=: git commit --amend \
 		--author="Somebody else <somebody@else.com>" &&
 	test $(git rev-parse branch3) != $(git rev-parse branch4) &&
-	set_fake_editor &&
 	git rebase -i branch3 &&
 	test $(git rev-parse branch3) = $(git rev-parse branch4)
 
@@ -775,7 +763,6 @@ test_expect_success 'submodule rebase setup' '
 		git commit -a -m "submodule second"
 	) &&
 	test_tick &&
-	set_fake_editor &&
 	git commit -a -m "Three changes submodule"
 '
 
@@ -800,7 +787,6 @@ test_expect_success 'submodule conflict setup' '
 '
 
 test_expect_success 'rebase -i continue with only submodule staged' '
-	set_fake_editor &&
 	test_must_fail git rebase -i submodule-base &&
 	git add sub &&
 	git rebase --continue &&
@@ -810,7 +796,6 @@ test_expect_success 'rebase -i continue with only submodule staged' '
 test_expect_success 'rebase -i continue with unstaged submodule' '
 	git checkout submodule-topic &&
 	git reset --hard &&
-	set_fake_editor &&
 	test_must_fail git rebase -i submodule-base &&
 	git reset &&
 	git rebase --continue &&
@@ -823,7 +808,6 @@ test_expect_success 'avoid unnecessary reset' '
 	test-tool chmtime =123456789 file3 &&
 	git update-index --refresh &&
 	HEAD=$(git rev-parse HEAD) &&
-	set_fake_editor &&
 	git rebase -i HEAD~4 &&
 	test $HEAD = $(git rev-parse HEAD) &&
 	MTIME=$(test-tool chmtime --get file3) &&
@@ -858,7 +842,6 @@ test_expect_success 'rebase -i can copy notes' '
 	test_commit n2 &&
 	test_commit n3 &&
 	git notes add -m"a note" n3 &&
-	set_fake_editor &&
 	git rebase -i --onto n1 n2 &&
 	test "a note" = "$(git notes show HEAD)"
 '
@@ -896,7 +879,6 @@ test_tick # Ensure that the rebased commits get a different timestamp.
 test_expect_success 'always cherry-pick with --no-ff' '
 	git checkout no-ff-branch &&
 	git tag original-no-ff-branch &&
-	set_fake_editor &&
 	git rebase -i --no-ff A &&
 	for p in 0 1 2
 	do
@@ -1044,7 +1026,6 @@ test_expect_success 'rebase --exec works without -i ' '
 
 test_expect_success 'rebase -i --exec without <CMD>' '
 	git reset --hard execute &&
-	set_fake_editor &&
 	test_must_fail git rebase -i --exec 2>actual &&
 	test_i18ngrep "requires a value" actual &&
 	git checkout master
@@ -1180,7 +1161,6 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
 test_expect_success 'rebase -i produces readable reflog' '
 	git reset --hard &&
 	git branch -f branch-reflog-test H &&
-	set_fake_editor &&
 	git rebase -i --onto I F branch-reflog-test &&
 	cat >expect <<-\EOF &&
 	rebase -i (finish): returning to refs/heads/branch-reflog-test
@@ -1603,4 +1583,9 @@ test_expect_success 'valid author header when author contains single quote' '
 	test_cmp expected actual
 '
 
+# This must be the last test in this file
+test_expect_success '$EDITOR and friends are unchanged' '
+	test_editor_unchanged
+'
+
 test_done
-- 
gitgitgadget


  parent reply	other threads:[~2019-10-15 10:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 18:36 [PATCH 0/3] sequencer: start running post-commit hook again Phillip Wood via GitGitGadget
2019-10-10 18:36 ` [PATCH 1/3] sequencer.h fix placement of #endif Phillip Wood via GitGitGadget
2019-10-10 18:36 ` [PATCH 2/3] sequencer: use run_commit_hook() Phillip Wood via GitGitGadget
2019-10-10 21:15   ` Johannes Schindelin
2019-10-11  4:24     ` Junio C Hamano
2019-10-14 13:26       ` Phillip Wood
2019-10-14 22:14         ` Johannes Schindelin
2019-10-10 18:36 ` [PATCH 3/3] sequencer: run post-commit hook Phillip Wood via GitGitGadget
2019-10-10 21:31   ` Johannes Schindelin
2019-10-11  4:27     ` Junio C Hamano
2019-10-11 15:39     ` Phillip Wood
2019-10-15 10:25 ` [PATCH v2 0/6] sequencer: start running post-commit hook again Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 1/6] t3404: remove unnecessary subshell Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 2/6] t3404: set $EDITOR in subshell Phillip Wood via GitGitGadget
2019-10-15 10:25   ` Phillip Wood via GitGitGadget [this message]
2019-10-15 10:25   ` [PATCH v2 4/6] sequencer.h fix placement of #endif Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 5/6] move run_commit_hook() to libgit and use it there Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 6/6] sequencer: run post-commit hook Phillip Wood via GitGitGadget
2019-10-15 14:26   ` [PATCH v2 0/6] sequencer: start running post-commit hook again Johannes Schindelin
2019-10-16  1:32     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09857dee784910b2123764be8cced9364dac4844.1571135132.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).