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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Oct 15, 2019 at 10:25 UTC
6a619ca03ce82988f2039ecdfd3565d54aa4d9ed
2 files changed
+33
-20
t/lib-rebase.sh
+28
@@ -118,3 +118,31 @@ make_empty () {
118
git commit --allow-empty -m "$1" &&
119
git tag "$1"
120
}
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
+5
-20
@@ -189,7 +189,6 @@ test_expect_success 'implicit interactive rebase does not invoke sequence editor
189
190
test_expect_success 'no changes are a nop' '
191
git checkout branch2 &&
192
- set_fake_editor &&
192
git rebase -i F &&
193
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
194
test $(git rev-parse I) = $(git rev-parse HEAD)
@@ -199,7 +198,6 @@ test_expect_success 'test the [branch] option' '
198
git checkout -b dead-end &&
199
git rm file6 &&
200
git commit -m "stop here" &&
202
- set_fake_editor &&
201
git rebase -i F branch2 &&
202
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
203
test $(git rev-parse I) = $(git rev-parse branch2) &&
@@ -208,7 +206,6 @@ test_expect_success 'test the [branch] option' '
206
207
test_expect_success 'test --onto <branch>' '
208
git checkout -b test-onto branch2 &&
211
- set_fake_editor &&
209
git rebase -i --onto branch1 F &&
210
test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
211
test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
@@ -218,7 +215,6 @@ test_expect_success 'test --onto <branch>' '
215
test_expect_success 'rebase on top of a non-conflicting commit' '
216
git checkout branch1 &&
217
git tag original-branch1 &&
221
- set_fake_editor &&
218
git rebase -i branch2 &&
219
test file6 = $(git diff --name-only original-branch1) &&
220
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
@@ -264,7 +260,6 @@ test_expect_success 'stop on conflicting pick' '
260
>>>>>>> 5d18e54... G
261
EOF
262
git tag new-branch1 &&
267
- set_fake_editor &&
263
test_must_fail git rebase -i master &&
264
test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
265
test_cmp expect .git/rebase-merge/patch &&
@@ -293,7 +288,6 @@ test_expect_success 'abort' '
288
test_expect_success 'abort with error when new base cannot be checked out' '
289
git rm --cached file1 &&
290
git commit -m "remove file in base" &&
296
- set_fake_editor &&
291
test_must_fail git rebase -i master > output 2>&1 &&
292
test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
293
output &&
@@ -308,7 +302,6 @@ test_expect_success 'retain authorship' '
302
test_tick &&
303
GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
304
git tag twerp &&
311
- set_fake_editor &&
305
git rebase -i --onto master HEAD^ &&
306
git show HEAD | grep "^Author: Twerp Snog"
307
'
@@ -326,7 +319,6 @@ test_expect_success 'retain authorship w/ conflicts' '
319
test_commit b conflict b conflict-b &&
320
GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
321
329
- set_fake_editor &&
322
test_must_fail git rebase -i conflict-a &&
323
echo resolved >conflict &&
324
git add conflict &&
@@ -357,7 +349,6 @@ test_expect_success 'retain authorship when squashing' '
349
350
test_expect_success REBASE_P '-p handles "no changes" gracefully' '
351
HEAD=$(git rev-parse HEAD) &&
360
- set_fake_editor &&
352
git rebase -i -p HEAD^ &&
353
git update-index --refresh &&
354
git diff-files --quiet &&
@@ -404,7 +395,6 @@ test_expect_success REBASE_P 'preserve merges with -p' '
395
git commit -m M file1 &&
396
git checkout -b to-be-rebased &&
397
test_tick &&
407
- set_fake_editor &&
398
git rebase -i -p --onto branch1 master &&
399
git update-index --refresh &&
400
git diff-files --quiet &&
@@ -450,7 +440,6 @@ test_expect_success '--continue tries to commit' '
440
test_expect_success 'verbose flag is heeded, even after --continue' '
441
git reset --hard master@{1} &&
442
test_tick &&
453
- set_fake_editor &&
443
test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
444
echo resolved > file1 &&
445
git add file1 &&
@@ -750,7 +739,6 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' '
739
GIT_EDITOR=: git commit --amend \
740
--author="Somebody else <somebody@else.com>" &&
741
test $(git rev-parse branch3) != $(git rev-parse branch4) &&
753
- set_fake_editor &&
742
git rebase -i branch3 &&
743
test $(git rev-parse branch3) = $(git rev-parse branch4)
744
@@ -775,7 +763,6 @@ test_expect_success 'submodule rebase setup' '
763
git commit -a -m "submodule second"
764
) &&
765
test_tick &&
778
- set_fake_editor &&
766
git commit -a -m "Three changes submodule"
767
'
768
@@ -800,7 +787,6 @@ test_expect_success 'submodule conflict setup' '
787
'
788
789
test_expect_success 'rebase -i continue with only submodule staged' '
803
- set_fake_editor &&
790
test_must_fail git rebase -i submodule-base &&
791
git add sub &&
792
git rebase --continue &&
@@ -810,7 +796,6 @@ test_expect_success 'rebase -i continue with only submodule staged' '
796
test_expect_success 'rebase -i continue with unstaged submodule' '
797
git checkout submodule-topic &&
798
git reset --hard &&
813
- set_fake_editor &&
799
test_must_fail git rebase -i submodule-base &&
800
git reset &&
801
git rebase --continue &&
@@ -823,7 +808,6 @@ test_expect_success 'avoid unnecessary reset' '
808
test-tool chmtime =123456789 file3 &&
809
git update-index --refresh &&
810
HEAD=$(git rev-parse HEAD) &&
826
- set_fake_editor &&
811
git rebase -i HEAD~4 &&
812
test $HEAD = $(git rev-parse HEAD) &&
813
MTIME=$(test-tool chmtime --get file3) &&
@@ -858,7 +842,6 @@ test_expect_success 'rebase -i can copy notes' '
842
test_commit n2 &&
843
test_commit n3 &&
844
git notes add -m"a note" n3 &&
861
- set_fake_editor &&
845
git rebase -i --onto n1 n2 &&
846
test "a note" = "$(git notes show HEAD)"
847
'
@@ -896,7 +879,6 @@ test_tick # Ensure that the rebased commits get a different timestamp.
879
test_expect_success 'always cherry-pick with --no-ff' '
880
git checkout no-ff-branch &&
881
git tag original-no-ff-branch &&
899
- set_fake_editor &&
882
git rebase -i --no-ff A &&
883
for p in 0 1 2
884
do
@@ -1044,7 +1026,6 @@ test_expect_success 'rebase --exec works without -i ' '
1026
1027
test_expect_success 'rebase -i --exec without <CMD>' '
1028
git reset --hard execute &&
1047
- set_fake_editor &&
1029
test_must_fail git rebase -i --exec 2>actual &&
1030
test_i18ngrep "requires a value" actual &&
1031
git checkout master
@@ -1180,7 +1161,6 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
1161
test_expect_success 'rebase -i produces readable reflog' '
1162
git reset --hard &&
1163
git branch -f branch-reflog-test H &&
1183
- set_fake_editor &&
1164
git rebase -i --onto I F branch-reflog-test &&
1165
cat >expect <<-\EOF &&
1166
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' '
1583
test_cmp expected actual
1584
'
1585
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
+
1591
test_done