]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit: forbid --pathspec-from-file --all
authorAlexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Mon, 16 Dec 2019 15:47:52 +0000 (15:47 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Dec 2019 22:14:14 +0000 (14:14 -0800)
I forgot this in my previous patch `--pathspec-from-file` for
`git commit` [1]. When both `--pathspec-from-file` and `--all` were
specified, `--all` took precedence and `--pathspec-from-file` was
ignored. Before `--pathspec-from-file` was implemented, this case was
prevented by this check in `parse_and_validate_options()` :

    die(_("paths '%s ...' with -a does not make sense"), argv[0]);

It is unfortunate that these two cases are disconnected. This came as
result of how the code was laid out before my patches, where `pathspec`
is parsed outside of `parse_and_validate_options()`. This branch is
already full of refactoring patches and I did not dare to go for another
one.

Fix by mirroring `die()` for `--pathspec-from-file` as well.

[1] Commit e440fc58 ("commit: support the --pathspec-from-file option" 2019-11-19)

Reported-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>
builtin/commit.c
t/t7526-commit-pathspec-file.sh

index ed40729355423e9cec59318c8e6d46dc53229b41..c040dc92a4d4523e43c25c0e426fdb305726833b 100644 (file)
@@ -347,6 +347,9 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
                if (interactive)
                        die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
 
+               if (all)
+                       die(_("--pathspec-from-file with -a does not make sense"));
+
                if (pathspec.nr)
                        die(_("--pathspec-from-file is incompatible with pathspec arguments"));
 
index a06b683534898e847ab7b0689c3b6850b8da4232..4b58901ed67c1349b255dd54977692f36cac988c 100755 (executable)
@@ -127,4 +127,10 @@ test_expect_success 'only touches what was listed' '
        verify_expect
 '
 
+test_expect_success '--pathspec-from-file and --all cannot be used together' '
+       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
+'
+
 test_done