t: add tests for error conditions with --pathspec-from-file
Also move some old tests into the new tests: it doesn't seem reasonable to have individual error condition tests. Old test for `git commit` was corrected, previously it was instructed to use stdin but wasn't provided with any stdin. While this works at the moment, it's not exactly perfect. Old tests for `git reset` were improved to test for a specific error message. Suggested-By: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alexandr Miloslavskiy committed
Dec 30, 2019 at 15:38 UTC
f94f7bd00d06c6b651a0e7afcc90ac86cc5f391b
5 files changed
+105
-12
t/t2026-checkout-pathspec-file.sh
+17
@@ -136,4 +136,21 @@ test_expect_success 'only touches what was listed' '
136
verify_expect
137
'
138
139
+test_expect_success 'error conditions' '
140
+ restore_checkpoint &&
141
+ echo fileA.t >list &&
142
+
143
+ test_must_fail git checkout --pathspec-from-file=list --detach 2>err &&
144
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --detach" err &&
145
+
146
+ test_must_fail git checkout --pathspec-from-file=list --patch 2>err &&
147
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
148
+
149
+ test_must_fail git checkout --pathspec-from-file=list -- fileA.t 2>err &&
150
+ test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
151
+
152
+ test_must_fail git checkout --pathspec-file-nul 2>err &&
153
+ test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err
154
+'
155
+
156
test_done
t/t2072-restore-pathspec-file.sh
+18
@@ -136,4 +136,22 @@ test_expect_success 'only touches what was listed' '
136
verify_expect
137
'
138
139
+test_expect_success 'error conditions' '
140
+ restore_checkpoint &&
141
+ echo fileA.t >list &&
142
+ >empty_list &&
143
+
144
+ test_must_fail git restore --pathspec-from-file=list --patch --source=HEAD^1 2>err &&
145
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
146
+
147
+ test_must_fail git restore --pathspec-from-file=list --source=HEAD^1 -- fileA.t 2>err &&
148
+ test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
149
+
150
+ test_must_fail git restore --pathspec-file-nul --source=HEAD^1 2>err &&
151
+ test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
152
+
153
+ test_must_fail git restore --pathspec-from-file=empty_list --source=HEAD^1 2>err &&
154
+ test_i18ngrep -e "you must specify path(s) to restore" err
155
+'
156
+
157
test_done
t/t3704-add-pathspec-file.sh
+25
@@ -124,4 +124,29 @@ test_expect_success 'only touches what was listed' '
124
verify_expect
125
'
126
127
+test_expect_success 'error conditions' '
128
+ restore_checkpoint &&
129
+ echo fileA.t >list &&
130
+ >empty_list &&
131
+
132
+ test_must_fail git add --pathspec-from-file=list --interactive 2>err &&
133
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
134
+
135
+ test_must_fail git add --pathspec-from-file=list --patch 2>err &&
136
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
137
+
138
+ test_must_fail git add --pathspec-from-file=list --edit 2>err &&
139
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --edit" err &&
140
+
141
+ test_must_fail git add --pathspec-from-file=list -- fileA.t 2>err &&
142
+ test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
143
+
144
+ test_must_fail git add --pathspec-file-nul 2>err &&
145
+ test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
146
+
147
+ # This case succeeds, but still prints to stderr
148
+ git add --pathspec-from-file=empty_list 2>err &&
149
+ test_i18ngrep -e "Nothing specified, nothing added." err
150
+'
151
+
152
test_done
t/t7107-reset-pathspec-file.sh
+21
-9
@@ -128,15 +128,6 @@ test_expect_success 'quotes not compatible with --pathspec-file-nul' '
128
test_must_fail verify_expect
129
'
130
131
-test_expect_success '--pathspec-from-file is not compatible with --soft or --hard' '
132
- restore_checkpoint &&
133
-
134
- git rm fileA.t &&
135
- echo fileA.t >list &&
136
- test_must_fail git reset --soft --pathspec-from-file=list &&
137
- test_must_fail git reset --hard --pathspec-from-file=list
138
-'
139
-
131
test_expect_success 'only touches what was listed' '
132
restore_checkpoint &&
133
@@ -152,4 +143,25 @@ test_expect_success 'only touches what was listed' '
143
verify_expect
144
'
145
146
+test_expect_success 'error conditions' '
147
+ restore_checkpoint &&
148
+ echo fileA.t >list &&
149
+ git rm fileA.t &&
150
+
151
+ test_must_fail git reset --pathspec-from-file=list --patch 2>err &&
152
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
153
+
154
+ test_must_fail git reset --pathspec-from-file=list -- fileA.t 2>err &&
155
+ test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
156
+
157
+ test_must_fail git reset --pathspec-file-nul 2>err &&
158
+ test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
159
+
160
+ test_must_fail git reset --soft --pathspec-from-file=list 2>err &&
161
+ test_i18ngrep -e "fatal: Cannot do soft reset with paths" err &&
162
+
163
+ test_must_fail git reset --hard --pathspec-from-file=list 2>err &&
164
+ test_i18ngrep -e "fatal: Cannot do hard reset with paths" err
165
+'
166
+
167
test_done
t/t7526-commit-pathspec-file.sh
+24
-3
@@ -127,10 +127,31 @@ test_expect_success 'only touches what was listed' '
127
verify_expect
128
'
129
130
-test_expect_success '--pathspec-from-file and --all cannot be used together' '
130
+test_expect_success 'error conditions' '
131
restore_checkpoint &&
132
- test_must_fail git commit --pathspec-from-file=- --all -m "Commit" 2>err &&
133
- test_i18ngrep "[-]-pathspec-from-file with -a does not make sense" err
132
+ echo fileA.t >list &&
133
+ >empty_list &&
134
+
135
+ test_must_fail git commit --pathspec-from-file=list --interactive -m "Commit" 2>err &&
136
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
137
+
138
+ test_must_fail git commit --pathspec-from-file=list --patch -m "Commit" 2>err &&
139
+ test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
140
+
141
+ test_must_fail git commit --pathspec-from-file=list --all -m "Commit" 2>err &&
142
+ test_i18ngrep -e "--pathspec-from-file with -a does not make sense" err &&
143
+
144
+ test_must_fail git commit --pathspec-from-file=list -m "Commit" -- fileA.t 2>err &&
145
+ test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
146
+
147
+ test_must_fail git commit --pathspec-file-nul -m "Commit" 2>err &&
148
+ test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
149
+
150
+ test_must_fail git commit --pathspec-from-file=empty_list --include -m "Commit" 2>err &&
151
+ test_i18ngrep -e "No paths with --include/--only does not make sense." err &&
152
+
153
+ test_must_fail git commit --pathspec-from-file=empty_list --only -m "Commit" 2>err &&
154
+ test_i18ngrep -e "No paths with --include/--only does not make sense." err
155
'
156
157
test_done