All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Deveshi Dwivedi <deveshigurgaon@gmail.com>
Cc: git@vger.kernel.org, Victoria Dye <vdye@github.com>
Subject: Re: [PATCH] t1006: fix %(rest) test for object names with whitespace
Date: Thu, 19 Feb 2026 11:50:10 -0800	[thread overview]
Message-ID: <xmqqikbs4iod.fsf@gitster.g> (raw)
In-Reply-To: <20260219152407.12160-1-deveshigurgaon@gmail.com> (Deveshi Dwivedi's message of "Thu, 19 Feb 2026 15:24:07 +0000")

Deveshi Dwivedi <deveshigurgaon@gmail.com> writes:

> The '--batch-check with %(rest)' test in run_tests() used
> $object_name directly as input to git cat-file. When the
> object name contained whitespace (e.g., "HEAD:path with spaces"),
> this led to ambiguity between the object name and the %(rest)
> placeholder.
>
> As a result, git cat-file could not reliably determine where
> the object name ended and %(rest) began.
>
> Fix this by using the resolved object ID (OID) instead of the
> raw object name as input. OIDs are hexadecimal strings and
> never contain whitespace, making the split unambiguous. This
> also removes the need for the existing FIXME comment and the
> test_expect_failure workaround.
>
> Signed-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>
> ---
>  t/t1006-cat-file.sh | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)

I am not sure if this particular FIXME has much value, but ...

> diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
> index 0eee3bb878..cac88acf65 100755
> --- a/t/t1006-cat-file.sh
> +++ b/t/t1006-cat-file.sh
> @@ -194,18 +194,11 @@ $content"
>  	test_cmp expect actual
>      '
>  
> -    # FIXME: %(rest) is incompatible with object names that include whitespace,
> -    # e.g. HEAD:path/to/a/file with spaces. Use the resolved OID as input to
> -    # test this instead of the raw object name.
> -    if echo "$object_name" | grep -q " "; then
> -	test_rest=test_expect_failure
> -    else
> -	test_rest=test_expect_success
> -    fi
> -
> -    $test_rest '--batch-check with %(rest)' '
> +    # Use the resolved OID so %(rest) parsing is independent of whitespace
> +    # in object names (e.g. HEAD:path with spaces).
> +    test_expect_success '--batch-check with %(rest)' '
>  	echo "$type this is some extra content" >expect &&
> -	echo "$object_name    this is some extra content" |
> +	echo "$oid    this is some extra content" |

... I somehow doubt that this is what 9fd38038 (t1006: update
'run_tests' to test generic object specifiers, 2025-06-02) meant by
that comment.

I would have understood if the fix were more like

	test_expect_success '--batch-check with %(rest)' '
                case "$object_name" in
                ?*" "?* | ?*"       "?*) # has space or tab
                        token_to_test=$oid
                        ;;
                *)
                        token_to_test=$object_name
                        ;;
                esac &&
                echo "$type this is some extra content" >expect &&
		echo "$token_to_test this is some extra content" |
		git cat-file --batch-check="%(objecttype) %(rest) >actual &&
		test_cmp expect actual
	'

i.e., when testing the object with non-problemtic name, use that
name, but otherwise, use the resolved name to avoid breakage.  That
is because the whole point of 9fd38038, as I understand it from the
earlier part of the change (see "git show 9fd38038") was to test the
use of name as much as possible.

>  		git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
>  	test_cmp expect actual
>      '

  reply	other threads:[~2026-02-19 19:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19 15:24 [PATCH] t1006: fix %(rest) test for object names with whitespace Deveshi Dwivedi
2026-02-19 19:50 ` Junio C Hamano [this message]
2026-02-19 20:23   ` Victoria Dye
2026-02-19 20:48     ` Junio C Hamano
2026-02-20  3:30       ` Junio C Hamano
2026-02-20 16:59         ` Deveshi Dwivedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqikbs4iod.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=deveshigurgaon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=vdye@github.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.