Re: [RFC PATCH 6/6] ls-tree: introduce '--pattern' option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Thu, 17 Nov 2022, Teng Long wrote:

> diff --git a/t/t3106-ls-tree-pattern.sh b/t/t3106-ls-tree-pattern.sh
> new file mode 100755
> index 00000000000..e4a81c8c47e
> --- /dev/null
> +++ b/t/t3106-ls-tree-pattern.sh
> @@ -0,0 +1,70 @@
> +#!/bin/sh
> +
> +test_description='ls-tree pattern'
> +
> +TEST_PASSES_SANITIZE_LEAK=true
> +. ./test-lib.sh
> +. "$TEST_DIRECTORY"/lib-t3100.sh
> +
> +test_expect_success 'setup' '
> +	setup_basic_ls_tree_data
> +'
> +
> +test_expect_success 'ls-tree pattern usage' '
> +	test_expect_code 129 git ls-tree --pattern HEAD &&
> +	test_expect_code 128 git ls-tree --pattern "" HEAD >err 2>&1 &&
> +	grep "Not a valid pattern, the value is empty" err
> +'
> +
> +test_expect_success 'combine with "--object-only"' '
> +	cat > expect <<-EOF &&
> +		6da7993
> +	EOF
> +
> +	git ls-tree --object-only --abbrev=7 --pattern "6da7993" HEAD > actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'combine with "--name-only"' '
> +	cat > expect <<-EOF &&
> +		.gitmodules
> +		top-file.t
> +	EOF
> +
> +	git ls-tree --name-only --pattern "\." HEAD > actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'combine with "--long"' '
> +	cat > expect <<-EOF &&
> +		100644 blob 6da7993      61	.gitmodules
> +		100644 blob 02dad95       9	top-file.t
> +	EOF
> +	git ls-tree --long --abbrev=7 --pattern "blob" HEAD > actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'combine with "--format"' '
> +	# Change the output format by replacing space separators with asterisks.
> +	format="%(objectmode)*%(objecttype)*%(objectname)%x09%(path)" &&
> +	pattern="100644\*blob" &&
> +
> +	cat > expect <<-EOF &&
> +		100644*blob*6da7993	.gitmodules
> +		100644*blob*02dad95	top-file.t
> +	EOF
> +
> +	git ls-tree --abbrev=7 --format "$format" --pattern "$pattern" HEAD >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'default output format (only with "--pattern" option)' '
> +	cat > expect <<-EOF &&
> +		100644 blob 6da7993ca1a3435f63c598464f77bdc6dae15aa5	.gitmodules
> +		100644 blob 02dad956d9274a70f7fafe45a5ffa2e123acd9a8	top-file.t
> +	EOF
> +	git ls-tree --pattern "blob" HEAD > actual &&
> +	test_cmp expect actual
> +'
> +
> +test_done

The hard-coded object IDs break the `linux-sha256` job, as pointed out in
https://github.com/git/git/blob/6ab7651d8669/whats-cooking.txt#L522-L537.

Please squash this in to address this (Junio, please feel free to
cherry-pick this on top of `tl/ls-tree--pattern` to reduce the number of
CI failures):

-- snipsnap --
Subject: [PATCH] fixup! ls-tree: introduce '--pattern' option

We need to avoid hard-coding OIDs because of the SHA-256 support.

Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx>
---
 t/t3106-ls-tree-pattern.sh | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/t/t3106-ls-tree-pattern.sh b/t/t3106-ls-tree-pattern.sh
index e4a81c8c47e..8aaca307804 100755
--- a/t/t3106-ls-tree-pattern.sh
+++ b/t/t3106-ls-tree-pattern.sh
@@ -17,11 +17,12 @@ test_expect_success 'ls-tree pattern usage' '
 '

 test_expect_success 'combine with "--object-only"' '
+	oid="$(git rev-parse --short HEAD:.gitmodules)" &&
 	cat > expect <<-EOF &&
-		6da7993
+		$oid
 	EOF

-	git ls-tree --object-only --abbrev=7 --pattern "6da7993" HEAD > actual &&
+	git ls-tree --object-only --abbrev=7 --pattern "$oid" HEAD > actual &&
 	test_cmp expect actual
 '

@@ -36,22 +37,26 @@ test_expect_success 'combine with "--name-only"' '
 '

 test_expect_success 'combine with "--long"' '
+	oid1="$(git rev-parse --short HEAD:.gitmodules)" &&
+	oid2="$(git rev-parse --short HEAD:top-file.t)" &&
 	cat > expect <<-EOF &&
-		100644 blob 6da7993      61	.gitmodules
-		100644 blob 02dad95       9	top-file.t
+		100644 blob $oid1      61	.gitmodules
+		100644 blob $oid2       9	top-file.t
 	EOF
 	git ls-tree --long --abbrev=7 --pattern "blob" HEAD > actual &&
 	test_cmp expect actual
 '

 test_expect_success 'combine with "--format"' '
+	oid1="$(git rev-parse --short HEAD:.gitmodules)" &&
+	oid2="$(git rev-parse --short HEAD:top-file.t)" &&
 	# Change the output format by replacing space separators with asterisks.
 	format="%(objectmode)*%(objecttype)*%(objectname)%x09%(path)" &&
 	pattern="100644\*blob" &&

 	cat > expect <<-EOF &&
-		100644*blob*6da7993	.gitmodules
-		100644*blob*02dad95	top-file.t
+		100644*blob*$oid1	.gitmodules
+		100644*blob*$oid2	top-file.t
 	EOF

 	git ls-tree --abbrev=7 --format "$format" --pattern "$pattern" HEAD >actual &&
@@ -59,9 +64,11 @@ test_expect_success 'combine with "--format"' '
 '

 test_expect_success 'default output format (only with "--pattern" option)' '
+	oid1="$(git rev-parse HEAD:.gitmodules)" &&
+	oid2="$(git rev-parse HEAD:top-file.t)" &&
 	cat > expect <<-EOF &&
-		100644 blob 6da7993ca1a3435f63c598464f77bdc6dae15aa5	.gitmodules
-		100644 blob 02dad956d9274a70f7fafe45a5ffa2e123acd9a8	top-file.t
+		100644 blob $oid1	.gitmodules
+		100644 blob $oid2	top-file.t
 	EOF
 	git ls-tree --pattern "blob" HEAD > actual &&
 	test_cmp expect actual
--
2.38.1.windows.1.24.g5ff6506c583.dirty





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux