Skip to content

Commit 6a619ca

Browse files
phillipwoodgitster
authored andcommitted
t3404: remove uneeded calls to set_fake_editor
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b2dbacb commit 6a619ca

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

t/lib-rebase.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,31 @@ make_empty () {
118118
git commit --allow-empty -m "$1" &&
119119
git tag "$1"
120120
}
121+
122+
# Call this (inside test_expect_success) at the end of a test file to
123+
# check that no tests have changed editor related environment
124+
# variables or config settings
125+
test_editor_unchanged () {
126+
# We're only interested in exported variables hence 'sh -c'
127+
sh -c 'cat >actual <<-EOF
128+
EDITOR=$EDITOR
129+
FAKE_COMMIT_AMEND=$FAKE_COMMIT_AMEND
130+
FAKE_COMMIT_MESSAGE=$FAKE_COMMIT_MESSAGE
131+
FAKE_LINES=$FAKE_LINES
132+
GIT_EDITOR=$GIT_EDITOR
133+
GIT_SEQUENCE_EDITOR=$GIT_SEQUENCE_EDITOR
134+
core.editor=$(git config core.editor)
135+
sequence.editor=$(git config sequence.editor)
136+
EOF'
137+
cat >expect <<-\EOF
138+
EDITOR=:
139+
FAKE_COMMIT_AMEND=
140+
FAKE_COMMIT_MESSAGE=
141+
FAKE_LINES=
142+
GIT_EDITOR=
143+
GIT_SEQUENCE_EDITOR=
144+
core.editor=
145+
sequence.editor=
146+
EOF
147+
test_cmp expect actual
148+
}

t/t3404-rebase-interactive.sh

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ test_expect_success 'implicit interactive rebase does not invoke sequence editor
189189

190190
test_expect_success 'no changes are a nop' '
191191
git checkout branch2 &&
192-
set_fake_editor &&
193192
git rebase -i F &&
194193
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
195194
test $(git rev-parse I) = $(git rev-parse HEAD)
@@ -199,7 +198,6 @@ test_expect_success 'test the [branch] option' '
199198
git checkout -b dead-end &&
200199
git rm file6 &&
201200
git commit -m "stop here" &&
202-
set_fake_editor &&
203201
git rebase -i F branch2 &&
204202
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
205203
test $(git rev-parse I) = $(git rev-parse branch2) &&
@@ -208,7 +206,6 @@ test_expect_success 'test the [branch] option' '
208206

209207
test_expect_success 'test --onto <branch>' '
210208
git checkout -b test-onto branch2 &&
211-
set_fake_editor &&
212209
git rebase -i --onto branch1 F &&
213210
test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
214211
test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
@@ -218,7 +215,6 @@ test_expect_success 'test --onto <branch>' '
218215
test_expect_success 'rebase on top of a non-conflicting commit' '
219216
git checkout branch1 &&
220217
git tag original-branch1 &&
221-
set_fake_editor &&
222218
git rebase -i branch2 &&
223219
test file6 = $(git diff --name-only original-branch1) &&
224220
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
@@ -264,7 +260,6 @@ test_expect_success 'stop on conflicting pick' '
264260
>>>>>>> 5d18e54... G
265261
EOF
266262
git tag new-branch1 &&
267-
set_fake_editor &&
268263
test_must_fail git rebase -i master &&
269264
test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
270265
test_cmp expect .git/rebase-merge/patch &&
@@ -293,7 +288,6 @@ test_expect_success 'abort' '
293288
test_expect_success 'abort with error when new base cannot be checked out' '
294289
git rm --cached file1 &&
295290
git commit -m "remove file in base" &&
296-
set_fake_editor &&
297291
test_must_fail git rebase -i master > output 2>&1 &&
298292
test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
299293
output &&
@@ -308,7 +302,6 @@ test_expect_success 'retain authorship' '
308302
test_tick &&
309303
GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
310304
git tag twerp &&
311-
set_fake_editor &&
312305
git rebase -i --onto master HEAD^ &&
313306
git show HEAD | grep "^Author: Twerp Snog"
314307
'
@@ -326,7 +319,6 @@ test_expect_success 'retain authorship w/ conflicts' '
326319
test_commit b conflict b conflict-b &&
327320
GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
328321
329-
set_fake_editor &&
330322
test_must_fail git rebase -i conflict-a &&
331323
echo resolved >conflict &&
332324
git add conflict &&
@@ -357,7 +349,6 @@ test_expect_success 'retain authorship when squashing' '
357349

358350
test_expect_success REBASE_P '-p handles "no changes" gracefully' '
359351
HEAD=$(git rev-parse HEAD) &&
360-
set_fake_editor &&
361352
git rebase -i -p HEAD^ &&
362353
git update-index --refresh &&
363354
git diff-files --quiet &&
@@ -404,7 +395,6 @@ test_expect_success REBASE_P 'preserve merges with -p' '
404395
git commit -m M file1 &&
405396
git checkout -b to-be-rebased &&
406397
test_tick &&
407-
set_fake_editor &&
408398
git rebase -i -p --onto branch1 master &&
409399
git update-index --refresh &&
410400
git diff-files --quiet &&
@@ -450,7 +440,6 @@ test_expect_success '--continue tries to commit' '
450440
test_expect_success 'verbose flag is heeded, even after --continue' '
451441
git reset --hard master@{1} &&
452442
test_tick &&
453-
set_fake_editor &&
454443
test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
455444
echo resolved > file1 &&
456445
git add file1 &&
@@ -750,7 +739,6 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' '
750739
GIT_EDITOR=: git commit --amend \
751740
--author="Somebody else <[email protected]>" &&
752741
test $(git rev-parse branch3) != $(git rev-parse branch4) &&
753-
set_fake_editor &&
754742
git rebase -i branch3 &&
755743
test $(git rev-parse branch3) = $(git rev-parse branch4)
756744
@@ -775,7 +763,6 @@ test_expect_success 'submodule rebase setup' '
775763
git commit -a -m "submodule second"
776764
) &&
777765
test_tick &&
778-
set_fake_editor &&
779766
git commit -a -m "Three changes submodule"
780767
'
781768

@@ -800,7 +787,6 @@ test_expect_success 'submodule conflict setup' '
800787
'
801788

802789
test_expect_success 'rebase -i continue with only submodule staged' '
803-
set_fake_editor &&
804790
test_must_fail git rebase -i submodule-base &&
805791
git add sub &&
806792
git rebase --continue &&
@@ -810,7 +796,6 @@ test_expect_success 'rebase -i continue with only submodule staged' '
810796
test_expect_success 'rebase -i continue with unstaged submodule' '
811797
git checkout submodule-topic &&
812798
git reset --hard &&
813-
set_fake_editor &&
814799
test_must_fail git rebase -i submodule-base &&
815800
git reset &&
816801
git rebase --continue &&
@@ -823,7 +808,6 @@ test_expect_success 'avoid unnecessary reset' '
823808
test-tool chmtime =123456789 file3 &&
824809
git update-index --refresh &&
825810
HEAD=$(git rev-parse HEAD) &&
826-
set_fake_editor &&
827811
git rebase -i HEAD~4 &&
828812
test $HEAD = $(git rev-parse HEAD) &&
829813
MTIME=$(test-tool chmtime --get file3) &&
@@ -858,7 +842,6 @@ test_expect_success 'rebase -i can copy notes' '
858842
test_commit n2 &&
859843
test_commit n3 &&
860844
git notes add -m"a note" n3 &&
861-
set_fake_editor &&
862845
git rebase -i --onto n1 n2 &&
863846
test "a note" = "$(git notes show HEAD)"
864847
'
@@ -896,7 +879,6 @@ test_tick # Ensure that the rebased commits get a different timestamp.
896879
test_expect_success 'always cherry-pick with --no-ff' '
897880
git checkout no-ff-branch &&
898881
git tag original-no-ff-branch &&
899-
set_fake_editor &&
900882
git rebase -i --no-ff A &&
901883
for p in 0 1 2
902884
do
@@ -1044,7 +1026,6 @@ test_expect_success 'rebase --exec works without -i ' '
10441026

10451027
test_expect_success 'rebase -i --exec without <CMD>' '
10461028
git reset --hard execute &&
1047-
set_fake_editor &&
10481029
test_must_fail git rebase -i --exec 2>actual &&
10491030
test_i18ngrep "requires a value" actual &&
10501031
git checkout master
@@ -1180,7 +1161,6 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
11801161
test_expect_success 'rebase -i produces readable reflog' '
11811162
git reset --hard &&
11821163
git branch -f branch-reflog-test H &&
1183-
set_fake_editor &&
11841164
git rebase -i --onto I F branch-reflog-test &&
11851165
cat >expect <<-\EOF &&
11861166
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' '
16031583
test_cmp expected actual
16041584
'
16051585

1586+
# This must be the last test in this file
1587+
test_expect_success '$EDITOR and friends are unchanged' '
1588+
test_editor_unchanged
1589+
'
1590+
16061591
test_done

0 commit comments

Comments
 (0)