diff mbox series

[02/16] commit: forbid --pathspec-from-file --all

Message ID c0980519ed319295c273d358b0547340cc511a6b.1576161385.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Extend --pathspec-from-file to git add, checkout | expand

Commit Message

Johannes Schindelin via GitGitGadget Dec. 12, 2019, 2:36 p.m. UTC
From: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>

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)

Co-authored-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
---
 builtin/commit.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Phillip Wood Dec. 16, 2019, 12:02 p.m. UTC | #1
Hi Alexandr

On 12/12/2019 14:36, Alexandr Miloslavskiy via GitGitGadget wrote:
> From: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
> 
> 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)
> 
> Co-authored-by: Phillip Wood <phillip.wood123@gmail.com>

Thanks for fixing this. If you want to credit me then I think
Reported-by: would be more appropriate as I didn't write this patch.
Also I tend to use phillip.wood@dunelm.org.uk for footers as it's a
portable email address (I should add a mailmap entry...). It would be
nice to have tests for the various error conditions at some point.

Best Wishes

Phillip

> Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
> ---
>  builtin/commit.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 2db2ad0de4..893a9f29b2 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -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"));
>  
>
Alexandr Miloslavskiy Dec. 16, 2019, 3:53 p.m. UTC | #2
On 16.12.2019 13:02, Phillip Wood wrote:

> Thanks for fixing this. If you want to credit me then I think
> Reported-by: would be more appropriate as I didn't write this patch.
> Also I tend to use phillip.wood@dunelm.org.uk for footers as it's a
> portable email address (I should add a mailmap entry...). It would be
> nice to have tests for the various error conditions at some point.

Thanks, I have addressed both issues in V2.
diff mbox series

Patch

diff --git a/builtin/commit.c b/builtin/commit.c
index 2db2ad0de4..893a9f29b2 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -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"));