Re: [RFC PATCH 2/7] add: include magic part of pathspec on --refresh error
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 17, 2021, 22:20 UTC
- Message-ID
- <xmqq5z2qjpzt.fsf@gitster.g>
- In-Reply-To
- <970b7156c2697e65778ec85751733a3adc53c1be.1613593946.git.matheus.bernardino@usp.br>
Matheus Tavares <matheus.bernardino@usp.br> writes:
> When `git add --refresh <pathspec>` doesn't find any matches for the > given pathspec, it prints an error message using the `match` field of > the `struct pathspec_item`. However, this field doesn't contain the > magic part of the pathspec. Instead, let's use the `original` field.
I assume that this is what already happens when there is no "--refresh" on the command line? I.e.
$ cd t
$ git add ':(icase)foo'
fatal: pathspec ':(icase)foo' did not match any files
$ git add --refresh ':(icase)foo'
fatal: pathspec 't/foo' did not match any filesand you are unifying the discrepancy between the two to match the former.
Makes sense.
Show 37 quoted lines
>
> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
> ---
> builtin/add.c | 2 +-
> t/t3700-add.sh | 6 ++++++
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/add.c b/builtin/add.c
> index f757de45ea..8c96c23778 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -180,7 +180,7 @@ static void refresh(int verbose, const struct pathspec *pathspec)
> for (i = 0; i < pathspec->nr; i++) {
> if (!seen[i])
> die(_("pathspec '%s' did not match any files"),
> - pathspec->items[i].match);
> + pathspec->items[i].original);
> }
> free(seen);
> }
> diff --git a/t/t3700-add.sh b/t/t3700-add.sh
> index fc81f2ef00..fe72204066 100755
> --- a/t/t3700-add.sh
> +++ b/t/t3700-add.sh
> @@ -196,6 +196,12 @@ test_expect_success 'git add --refresh with pathspec' '
> grep baz actual
> '
>
> +test_expect_success 'git add --refresh correctly reports no match error' "
> + echo \"fatal: pathspec ':(icase)nonexistent' did not match any files\" >expect &&
> + test_must_fail git add --refresh ':(icase)nonexistent' 2>actual &&
> + test_i18ncmp expect actual
> +"
> +
> test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' '
> git reset --hard &&
> date >foo1 &&