]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: add tests for error conditions with --pathspec-from-file
authorAlexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Mon, 30 Dec 2019 15:38:38 +0000 (15:38 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Jan 2020 20:14:15 +0000 (12:14 -0800)
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>
t/t2026-checkout-pathspec-file.sh
t/t2072-restore-pathspec-file.sh
t/t3704-add-pathspec-file.sh
t/t7107-reset-pathspec-file.sh
t/t7526-commit-pathspec-file.sh

index f62fd274404e1e5e5265bdc2b6b367a1d984a7f8..0926312370be3b922471901d71e35c5c59c18404 100755 (executable)
@@ -136,4 +136,21 @@ test_expect_success 'only touches what was listed' '
        verify_expect
 '
 
+test_expect_success 'error conditions' '
+       restore_checkpoint &&
+       echo fileA.t >list &&
+
+       test_must_fail git checkout --pathspec-from-file=list --detach 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --detach" err &&
+
+       test_must_fail git checkout --pathspec-from-file=list --patch 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
+
+       test_must_fail git checkout --pathspec-from-file=list -- fileA.t 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
+
+       test_must_fail git checkout --pathspec-file-nul 2>err &&
+       test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err
+'
+
 test_done
index db58e83735080269a85f80716678ab19838c434b..5c7abbbce3a8a7a138b17f1d5494cfea8e2a9a9b 100755 (executable)
@@ -136,4 +136,22 @@ test_expect_success 'only touches what was listed' '
        verify_expect
 '
 
+test_expect_success 'error conditions' '
+       restore_checkpoint &&
+       echo fileA.t >list &&
+       >empty_list &&
+
+       test_must_fail git restore --pathspec-from-file=list --patch --source=HEAD^1 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
+
+       test_must_fail git restore --pathspec-from-file=list --source=HEAD^1 -- fileA.t 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
+
+       test_must_fail git restore --pathspec-file-nul --source=HEAD^1 2>err &&
+       test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
+
+       test_must_fail git restore --pathspec-from-file=empty_list --source=HEAD^1 2>err &&
+       test_i18ngrep -e "you must specify path(s) to restore" err
+'
+
 test_done
index 3cfdb669b7a5a1bc4b915abb0c880f067bfbd7b9..a1696e1a39caa779b885fd5deefac764941b5dc1 100755 (executable)
@@ -124,4 +124,29 @@ test_expect_success 'only touches what was listed' '
        verify_expect
 '
 
+test_expect_success 'error conditions' '
+       restore_checkpoint &&
+       echo fileA.t >list &&
+       >empty_list &&
+
+       test_must_fail git add --pathspec-from-file=list --interactive 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
+
+       test_must_fail git add --pathspec-from-file=list --patch 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
+
+       test_must_fail git add --pathspec-from-file=list --edit 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --edit" err &&
+
+       test_must_fail git add --pathspec-from-file=list -- fileA.t 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
+
+       test_must_fail git add --pathspec-file-nul 2>err &&
+       test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
+
+       # This case succeeds, but still prints to stderr
+       git add --pathspec-from-file=empty_list 2>err &&
+       test_i18ngrep -e "Nothing specified, nothing added." err
+'
+
 test_done
index 6b1a731fffe65f10259a5200e071c4767181d759..975a9a930ae756e6c44a891241daef0a21ca8dbb 100755 (executable)
@@ -128,15 +128,6 @@ test_expect_success 'quotes not compatible with --pathspec-file-nul' '
        test_must_fail verify_expect
 '
 
-test_expect_success '--pathspec-from-file is not compatible with --soft or --hard' '
-       restore_checkpoint &&
-
-       git rm fileA.t &&
-       echo fileA.t >list &&
-       test_must_fail git reset --soft --pathspec-from-file=list &&
-       test_must_fail git reset --hard --pathspec-from-file=list
-'
-
 test_expect_success 'only touches what was listed' '
        restore_checkpoint &&
 
@@ -152,4 +143,25 @@ test_expect_success 'only touches what was listed' '
        verify_expect
 '
 
+test_expect_success 'error conditions' '
+       restore_checkpoint &&
+       echo fileA.t >list &&
+       git rm fileA.t &&
+
+       test_must_fail git reset --pathspec-from-file=list --patch 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
+
+       test_must_fail git reset --pathspec-from-file=list -- fileA.t 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
+
+       test_must_fail git reset --pathspec-file-nul 2>err &&
+       test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
+
+       test_must_fail git reset --soft --pathspec-from-file=list 2>err &&
+       test_i18ngrep -e "fatal: Cannot do soft reset with paths" err &&
+
+       test_must_fail git reset --hard --pathspec-from-file=list 2>err &&
+       test_i18ngrep -e "fatal: Cannot do hard reset with paths" err
+'
+
 test_done
index 4b58901ed67c1349b255dd54977692f36cac988c..336197449fa68a22450de9029d36eca252dbed61 100755 (executable)
@@ -127,10 +127,31 @@ test_expect_success 'only touches what was listed' '
        verify_expect
 '
 
-test_expect_success '--pathspec-from-file and --all cannot be used together' '
+test_expect_success 'error conditions' '
        restore_checkpoint &&
-       test_must_fail git commit --pathspec-from-file=- --all -m "Commit" 2>err &&
-       test_i18ngrep "[-]-pathspec-from-file with -a does not make sense" err
+       echo fileA.t >list &&
+       >empty_list &&
+
+       test_must_fail git commit --pathspec-from-file=list --interactive -m "Commit" 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
+
+       test_must_fail git commit --pathspec-from-file=list --patch -m "Commit" 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
+
+       test_must_fail git commit --pathspec-from-file=list --all -m "Commit" 2>err &&
+       test_i18ngrep -e "--pathspec-from-file with -a does not make sense" err &&
+
+       test_must_fail git commit --pathspec-from-file=list -m "Commit" -- fileA.t 2>err &&
+       test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
+
+       test_must_fail git commit --pathspec-file-nul -m "Commit" 2>err &&
+       test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
+
+       test_must_fail git commit --pathspec-from-file=empty_list --include -m "Commit" 2>err &&
+       test_i18ngrep -e "No paths with --include/--only does not make sense." err &&
+
+       test_must_fail git commit --pathspec-from-file=empty_list --only -m "Commit" 2>err &&
+       test_i18ngrep -e "No paths with --include/--only does not make sense." err
 '
 
 test_done