diff mbox series

ls-tree: test for the regression in 9c4d58ff2c3

Message ID patch-1.1-0fdfec624eb-20220531T171908Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series ls-tree: test for the regression in 9c4d58ff2c3 | expand

Commit Message

Ævar Arnfjörð Bjarmason May 31, 2022, 5:21 p.m. UTC
Add a test for the regression introduced in my 9c4d58ff2c3 (ls-tree:
split up "fast path" callbacks, 2022-03-23) and fixed in
350296cc789 (ls-tree: `-l` should not imply recursive listing,
2022-04-04), and test for the test of ls-tree option/mode combinations
to make sure we don't have other blind spots.

The setup for these tests can be shared with those added in the
1041d58b4d9 (Merge branch 'tl/ls-tree-oid-only', 2022-04-04) topic, so
let's create a new t/lib-t3100.sh to help them share data.

The existing tests in "t3104-ls-tree-format.sh" didn't deal with a
submodule, which they'll now encounter with as the
setup_basic_ls_tree_data() sets one up.

This extensive testing should give us confidence that there were no
further regressions in this area. The lack of testing was noted back
in [1], but unfortunately we didn't cover that blind-spot before
9c4d58ff2c3.

1. https://lore.kernel.org/git/211115.86o86lqe3c.gmgdl@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

On Thu, Apr 07 2022, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>>>>> Let's not go too cute like this.  This forces the caller to remember
>>>>> which among 6, 7, and 8 corresponds to which option.  It is too ugly
>>>>> to live.
>>>>
>>>> I think it's rather elegant actually, but to be fair it would, per:
>>>>
>>>>    git grep '<&[1-9]| [1-9]<<-'
>>>>
>>>> Be the user with the most FD's using this sort of pattern.
>>>
>>> Please give a clear explanation why "-d" has to be 6, "-r" 7 and
>>> "-t" 8, that can be used by developers as a memory aid to help them
>>> write new tests using the helper.
>>
>> It's documented when test-lib.sh does the redirection, since Fabian
>> Stelzer's a6714088e0c (test-lib: make BAIL_OUT() work in tests and
>> prereq, 2021-12-01).
>
> Sorry, but that is not what I asked.  I know what we use lower file
> descriptors for, and I didn't ask why we start from 6 (as opposed to
> 3).
>
> The updated helper forces our developers to know that the expected
> result for "-d" has to go to #6 (not #7 or #8), and "-r" to #7 (not
> #6 or #8), etc., in order to write new tests using it, and in order
> to spot a mistake while reviewing such new tests.
>
> It is an invitation to unmaintainable mess.  Don't encourage it.

I came up with this at the time, but didn't submit it since we were in
the rc period.

But since we're past that I think it makes sense to have a test for
the regression we fixed, the below is a lot less magical, but larger
by line count. I think this alternate test implementation should
address the concerns you had.

Range-diff:
1:  ed83b3b74ab ! 1:  0fdfec624eb ls-tree: fix --long implying -r regression in 9c4d58ff2c3
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    ls-tree: fix --long implying -r regression in 9c4d58ff2c3
    +    ls-tree: test for the regression in 9c4d58ff2c3
     
    -    Fix a regression introduced in 9c4d58ff2c3 (ls-tree: split up "fast
    -    path" callbacks, 2022-03-23), and improve the tests added in the
    -    1041d58b4d9 (Merge branch 'tl/ls-tree-oid-only', 2022-04-04) topic it
    -    was merged as part of to test the full expected output of various
    -    "ls-tree" options with and without -r.
    +    Add a test for the regression introduced in my 9c4d58ff2c3 (ls-tree:
    +    split up "fast path" callbacks, 2022-03-23) and fixed in
    +    350296cc789 (ls-tree: `-l` should not imply recursive listing,
    +    2022-04-04), and test for the test of ls-tree option/mode combinations
    +    to make sure we don't have other blind spots.
     
    -    Let's fix it, and also add tests not only for that blindspot, but also
    -    any other potential blindspots. To that end test the "modes" of -d, -r
    -    and -t (as well as "no mode") against all of the format options.
    +    The setup for these tests can be shared with those added in the
    +    1041d58b4d9 (Merge branch 'tl/ls-tree-oid-only', 2022-04-04) topic, so
    +    let's create a new t/lib-t3100.sh to help them share data.
     
    -    These tests all pass with that topic reverted (except those that would
    -    fail because they're testing the new --object-only feature introduced
    -    in that topic), which should give us confidence that there were no
    -    further regressions in this area.
    +    The existing tests in "t3104-ls-tree-format.sh" didn't deal with a
    +    submodule, which they'll now encounter with as the
    +    setup_basic_ls_tree_data() sets one up.
    +
    +    This extensive testing should give us confidence that there were no
    +    further regressions in this area. The lack of testing was noted back
    +    in [1], but unfortunately we didn't cover that blind-spot before
    +    9c4d58ff2c3.
    +
    +    1. https://lore.kernel.org/git/211115.86o86lqe3c.gmgdl@evledraar.gmail.com/
     
    -    Reported-By: Josh Steadmon <steadmon@google.com>
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    - ## builtin/ls-tree.c ##
    -@@ builtin/ls-tree.c: static int show_tree_long(const struct object_id *oid, struct strbuf *base,
    - 	printf("%06o %s %s %7s\t", data.mode, type_name(data.type),
    - 	       find_unique_abbrev(data.oid, abbrev), size_text);
    - 	show_tree_common_default_long(base, pathname, data.base->len);
    --	return 1;
    -+	return recurse;
    - }
    - 
    - static int show_tree_name_only(const struct object_id *oid, struct strbuf *base,
    + ## t/lib-t3100.sh (new) ##
    +@@
    ++#!/bin/sh
    ++
    ++setup_basic_ls_tree_data () {
    ++	mkdir dir &&
    ++	test_commit dir/sub-file &&
    ++	test_commit top-file &&
    ++	git clone . submodule &&
    ++	git submodule add ./submodule &&
    ++	git commit -m"add submodule"
    ++}
     
      ## t/t3104-ls-tree-format.sh ##
    -@@ t/t3104-ls-tree-format.sh: test_ls_tree_format () {
    - 	fmtopts=$3 &&
    - 	shift 2 &&
    +@@ t/t3104-ls-tree-format.sh: test_description='ls-tree --format'
    + 
    + TEST_PASSES_SANITIZE_LEAK=true
    + . ./test-lib.sh
    ++. "$TEST_DIRECTORY"/lib-t3100.sh
    + 
    + test_expect_success 'ls-tree --format usage' '
    + 	test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
    +@@ t/t3104-ls-tree-format.sh: test_expect_success 'ls-tree --format usage' '
    + '
    + 
    + test_expect_success 'setup' '
    +-	mkdir dir &&
    +-	test_commit dir/sub-file &&
    +-	test_commit top-file
    ++	setup_basic_ls_tree_data
    + '
      
    + test_ls_tree_format () {
    +
    + ## t/t3105-ls-tree-output.sh (new) ##
    +@@
    ++#!/bin/sh
    ++
    ++test_description='ls-tree output'
    ++
    ++TEST_PASSES_SANITIZE_LEAK=true
    ++. ./test-lib.sh
    ++. "$TEST_DIRECTORY"/lib-t3100.sh
    ++
    ++test_expect_success 'ls-tree --format usage' '
    ++	test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
    ++	test_expect_code 129 git ls-tree --format=fmt --name-only HEAD &&
    ++	test_expect_code 129 git ls-tree --format=fmt --name-status HEAD
    ++'
    ++
    ++test_expect_success 'setup' '
    ++	setup_basic_ls_tree_data
    ++'
    ++
    ++test_ls_tree_format_mode_output () {
    ++	local opts=$1 &&
    ++	shift &&
     +	cat >expect &&
    -+	cat <&6 >expect.-d &&
    -+	cat <&7 >expect.-r &&
    -+	cat <&8 >expect.-t &&
     +
    -+	for opt in '' '-d' '-r' '-t'
    ++	while test $# -gt 0
     +	do
    -+		test_expect_success "'ls-tree $opts${opt:+ $opt}' output" '
    -+			git ls-tree ${opt:+$opt }$opts $opt HEAD >actual &&
    -+			test_cmp expect${opt:+.$opt} actual
    ++		local mode="$1" &&
    ++		shift &&
    ++
    ++		test_expect_success "'ls-tree $opts${mode:+ $mode}' output" '
    ++			git ls-tree ${mode:+$mode }$opts HEAD >actual &&
    ++			test_cmp expect actual
     +		'
    ++
    ++		case "$opts" in
    ++		--full-tree)
    ++			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir, fails)" '
    ++				test_must_fail git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../
    ++			'
    ++			;;
    ++		*)
    ++			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir)" '
    ++				git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../ >actual &&
    ++				test_cmp expect actual
    ++			'
    ++			;;
    ++		esac
     +	done
    ++}
     +
    - 	test_expect_success "ls-tree '--format=<$format>' is like options '$opts $fmtopts'" '
    - 		git ls-tree $opts -r HEAD >expect &&
    - 		git ls-tree --format="$format" -r $fmtopts HEAD >actual &&
    -@@ t/t3104-ls-tree-format.sh: test_ls_tree_format () {
    - 
    - test_ls_tree_format \
    - 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
    --	""
    -+	"" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	OUT_D
    -+	100644 blob $(git rev-parse HEAD:dir/sub-file.t)	dir/sub-file.t
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_R
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_T
    - 
    - test_ls_tree_format \
    - 	"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
    --	"--long"
    -+	"--long" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    -+	040000 tree $(git rev-parse HEAD:dir)       -	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)       9	top-file.t
    -+	OUT
    -+	040000 tree $(git rev-parse HEAD:dir)       -	dir
    -+	OUT_D
    -+	100644 blob $(git rev-parse HEAD:dir/sub-file.t)      13	dir/sub-file.t
    -+	100644 blob $(git rev-parse HEAD:top-file.t)       9	top-file.t
    -+	OUT_R
    -+	040000 tree $(git rev-parse HEAD:dir)       -	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)       9	top-file.t
    -+	OUT_T
    - 
    - test_ls_tree_format \
    - 	"%(path)" \
    --	"--name-only"
    -+	"--name-only" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    ++# test exact output of option (none, --long, ...) and mode (none and
    ++# -d, -r -t) and combinations
    ++test_expect_success 'setup: HEAD_* variables' '
    ++	HEAD_gitmodules=$(git rev-parse HEAD:.gitmodules) &&
    ++	HEAD_dir=$(git rev-parse HEAD:dir) &&
    ++	HEAD_top_file=$(git rev-parse HEAD:top-file.t) &&
    ++	HEAD_submodule=$(git rev-parse HEAD:submodule) &&
    ++	HEAD_dir_sub_file=$(git rev-parse HEAD:dir/sub-file.t)
    ++'
    ++## opt =
    ++test_ls_tree_format_mode_output "" "" "-t" <<-EOF
    ++	100644 blob $HEAD_gitmodules	.gitmodules
    ++	040000 tree $HEAD_dir	dir
    ++	160000 commit $HEAD_submodule	submodule
    ++	100644 blob $HEAD_top_file	top-file.t
    ++	EOF
    ++test_ls_tree_format_mode_output "" "-d" <<-EOF
    ++	040000 tree $HEAD_dir	dir
    ++	160000 commit $HEAD_submodule	submodule
    ++	EOF
    ++test_ls_tree_format_mode_output "" "-r" <<-EOF
    ++	100644 blob $HEAD_gitmodules	.gitmodules
    ++	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
    ++	160000 commit $HEAD_submodule	submodule
    ++	100644 blob $HEAD_top_file	top-file.t
    ++	EOF
    ++## opt = --long
    ++test_ls_tree_format_mode_output "--long" "" "-t" <<-EOF
    ++	100644 blob $HEAD_gitmodules      61	.gitmodules
    ++	040000 tree $HEAD_dir       -	dir
    ++	160000 commit $HEAD_submodule       -	submodule
    ++	100644 blob $HEAD_top_file       9	top-file.t
    ++	EOF
    ++test_ls_tree_format_mode_output "--long" "-d" <<-EOF
    ++	040000 tree $HEAD_dir       -	dir
    ++	160000 commit $HEAD_submodule       -	submodule
    ++	EOF
    ++test_ls_tree_format_mode_output "--long" "-r" <<-EOF
    ++	100644 blob $HEAD_gitmodules      61	.gitmodules
    ++	100644 blob $HEAD_dir_sub_file      13	dir/sub-file.t
    ++	160000 commit $HEAD_submodule       -	submodule
    ++	100644 blob $HEAD_top_file       9	top-file.t
    ++	EOF
    ++## opt = --name-only
    ++test_ls_tree_format_mode_output "--name-only" "" "-t" <<-EOF
    ++	.gitmodules
     +	dir
    ++	submodule
     +	top-file.t
    -+	OUT
    ++	EOF
    ++test_ls_tree_format_mode_output "--name-only" "-d" <<-EOF
     +	dir
    -+	OUT_D
    ++	submodule
    ++	EOF
    ++test_ls_tree_format_mode_output "--name-only" "-r" <<-EOF
    ++	.gitmodules
     +	dir/sub-file.t
    ++	submodule
     +	top-file.t
    -+	OUT_R
    -+	dir
    -+	top-file.t
    -+	OUT_T
    - 
    - test_ls_tree_format \
    - 	"%(objectname)" \
    --	"--object-only"
    -+	"--object-only" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    -+	$(git rev-parse HEAD:dir)
    -+	$(git rev-parse HEAD:top-file.t)
    -+	OUT
    -+	$(git rev-parse HEAD:dir)
    -+	OUT_D
    -+	$(git rev-parse HEAD:dir/sub-file.t)
    -+	$(git rev-parse HEAD:top-file.t)
    -+	OUT_R
    -+	$(git rev-parse HEAD:dir)
    -+	$(git rev-parse HEAD:top-file.t)
    -+	OUT_T
    - 
    - test_ls_tree_format \
    - 	"%(objectname)" \
    - 	"--object-only --abbrev" \
    --	"--abbrev"
    -+	"--abbrev" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    -+	$(git rev-parse HEAD:dir | test_copy_bytes 7)
    -+	$(git rev-parse HEAD:top-file.t| test_copy_bytes 7)
    -+	OUT
    -+	$(git rev-parse HEAD:dir | test_copy_bytes 7)
    -+	OUT_D
    -+	$(git rev-parse HEAD:dir/sub-file.t | test_copy_bytes 7)
    -+	$(git rev-parse HEAD:top-file.t | test_copy_bytes 7)
    -+	OUT_R
    -+	$(git rev-parse HEAD:dir | test_copy_bytes 7)
    -+	$(git rev-parse HEAD:top-file.t | test_copy_bytes 7)
    -+	OUT_T
    - 
    - test_ls_tree_format \
    - 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
    - 	"-t" \
    --	"-t"
    -+	"-t" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	OUT_D
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:dir/sub-file.t)	dir/sub-file.t
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_R
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_T
    - 
    - test_ls_tree_format \
    - 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
    - 	"--full-name" \
    --	"--full-name"
    -+	"--full-name" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	OUT_D
    -+	100644 blob $(git rev-parse HEAD:dir/sub-file.t)	dir/sub-file.t
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_R
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_T
    - 
    - test_ls_tree_format \
    - 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
    - 	"--full-tree" \
    --	"--full-tree"
    -+	"--full-tree" \
    -+	<<-OUT 6<<-OUT_D 7<<-OUT_R 8<<-OUT_T
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	OUT_D
    -+	100644 blob $(git rev-parse HEAD:dir/sub-file.t)	dir/sub-file.t
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_R
    -+	040000 tree $(git rev-parse HEAD:dir)	dir
    -+	100644 blob $(git rev-parse HEAD:top-file.t)	top-file.t
    -+	OUT_T
    - 
    - test_done
    ++	EOF
    ++## opt = --object-only
    ++test_ls_tree_format_mode_output "--object-only" "" "-t" <<-EOF
    ++	$HEAD_gitmodules
    ++	$HEAD_dir
    ++	$HEAD_submodule
    ++	$HEAD_top_file
    ++	EOF
    ++test_ls_tree_format_mode_output "--object-only" "-d" <<-EOF
    ++	$HEAD_dir
    ++	$HEAD_submodule
    ++	EOF
    ++test_ls_tree_format_mode_output "--object-only" "-r" <<-EOF
    ++	$HEAD_gitmodules
    ++	$HEAD_dir_sub_file
    ++	$HEAD_submodule
    ++	$HEAD_top_file
    ++	EOF
    ++## opt = --object-only --abbrev
    ++test_expect_success 'setup: HEAD_short_* variables' '
    ++	HEAD_short_gitmodules=$(git rev-parse --short HEAD:.gitmodules) &&
    ++	HEAD_short_dir=$(git rev-parse --short HEAD:dir) &&
    ++	HEAD_short_top_file=$(git rev-parse --short HEAD:top-file.t) &&
    ++	HEAD_short_submodule=$(git rev-parse --short HEAD:submodule) &&
    ++	HEAD_short_dir_sub_file=$(git rev-parse --short HEAD:dir/sub-file.t)
    ++'
    ++test_ls_tree_format_mode_output "--object-only --abbrev" "" "-t" <<-EOF
    ++	$HEAD_short_gitmodules
    ++	$HEAD_short_dir
    ++	$HEAD_short_submodule
    ++	$HEAD_short_top_file
    ++	EOF
    ++test_ls_tree_format_mode_output "--object-only --abbrev" "-d" <<-EOF
    ++	$HEAD_short_dir
    ++	$HEAD_short_submodule
    ++	EOF
    ++test_ls_tree_format_mode_output "--object-only --abbrev" "-r" <<-EOF
    ++	$HEAD_short_gitmodules
    ++	$HEAD_short_dir_sub_file
    ++	$HEAD_short_submodule
    ++	$HEAD_short_top_file
    ++	EOF
    ++## opt = --full-name
    ++test_ls_tree_format_mode_output "--full-name" "" <<-EOF
    ++	100644 blob $HEAD_gitmodules	.gitmodules
    ++	040000 tree $HEAD_dir	dir
    ++	160000 commit $HEAD_submodule	submodule
    ++	100644 blob $HEAD_top_file	top-file.t
    ++	EOF
    ++test_ls_tree_format_mode_output "--full-name" "-d" <<-EOF
    ++	040000 tree $HEAD_dir	dir
    ++	160000 commit $HEAD_submodule	submodule
    ++	EOF
    ++test_ls_tree_format_mode_output "--full-name" "-r" <<-EOF
    ++	100644 blob $HEAD_gitmodules	.gitmodules
    ++	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
    ++	160000 commit $HEAD_submodule	submodule
    ++	100644 blob $HEAD_top_file	top-file.t
    ++	EOF
    ++test_ls_tree_format_mode_output "--full-name" "-t" <<-EOF
    ++	100644 blob $HEAD_gitmodules	.gitmodules
    ++	040000 tree $HEAD_dir	dir
    ++	160000 commit $HEAD_submodule	submodule
    ++	100644 blob $HEAD_top_file	top-file.t
    ++	EOF
    ++## opt = --full-tree
    ++test_ls_tree_format_mode_output "--full-tree" "" "-t" <<-EOF
    ++	100644 blob $HEAD_gitmodules	.gitmodules
    ++	040000 tree $HEAD_dir	dir
    ++	160000 commit $HEAD_submodule	submodule
    ++	100644 blob $HEAD_top_file	top-file.t
    ++	EOF
    ++test_ls_tree_format_mode_output "--full-tree" "-d" <<-EOF
    ++	040000 tree $HEAD_dir	dir
    ++	160000 commit $HEAD_submodule	submodule
    ++	EOF
    ++test_ls_tree_format_mode_output "--full-tree" "-r" <<-EOF
    ++	100644 blob $HEAD_gitmodules	.gitmodules
    ++	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
    ++	160000 commit $HEAD_submodule	submodule
    ++	100644 blob $HEAD_top_file	top-file.t
    ++	EOF
    ++
    ++test_done

 t/lib-t3100.sh            |  10 ++
 t/t3104-ls-tree-format.sh |   5 +-
 t/t3105-ls-tree-output.sh | 192 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+), 3 deletions(-)
 create mode 100644 t/lib-t3100.sh
 create mode 100755 t/t3105-ls-tree-output.sh

Comments

Johannes Schindelin June 2, 2022, 3:18 p.m. UTC | #1
Hi Ævar,

On Tue, 31 May 2022, Ævar Arnfjörð Bjarmason wrote:

> Add a test for the regression introduced in my 9c4d58ff2c3 (ls-tree:
> split up "fast path" callbacks, 2022-03-23) and fixed in
> 350296cc789 (ls-tree: `-l` should not imply recursive listing,
> 2022-04-04), and test for the test of ls-tree option/mode combinations
> to make sure we don't have other blind spots.

That's adding a lot of new test cases, which is not free of cost.

> Range-diff:
> [... 433 lines, essentially a rewrite...]

Pasting 443 lines of range-diff also is not free of cost.

> diff --git a/t/t3105-ls-tree-output.sh b/t/t3105-ls-tree-output.sh
> new file mode 100755
> index 00000000000..29511d9331b
> --- /dev/null
> +++ b/t/t3105-ls-tree-output.sh
> @@ -0,0 +1,192 @@
> +#!/bin/sh
> +
> +test_description='ls-tree output'
> +
> [...]
> +'
> +
> +test_ls_tree_format_mode_output () {
> +	local opts=$1 &&

This line does not quote `$1`, but...

> +	shift &&
> +	cat >expect &&
> +
> +	while test $# -gt 0
> +	do
> +		local mode="$1" &&
> +		shift &&
> +
> +		test_expect_success "'ls-tree $opts${mode:+ $mode}' output" '
> +			git ls-tree ${mode:+$mode }$opts HEAD >actual &&
> +			test_cmp expect actual
> +		'
> +
> +		case "$opts" in
> +		--full-tree)
> +			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir, fails)" '
> +				test_must_fail git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../
> +			'
> +			;;
> +		*)
> +			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir)" '
> +				git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../ >actual &&
> +				test_cmp expect actual
> +			'
> +			;;
> +		esac
> +	done
> +}
> +
> [...]
> +## opt = --object-only --abbrev
> +test_expect_success 'setup: HEAD_short_* variables' '
> +	HEAD_short_gitmodules=$(git rev-parse --short HEAD:.gitmodules) &&
> +	HEAD_short_dir=$(git rev-parse --short HEAD:dir) &&
> +	HEAD_short_top_file=$(git rev-parse --short HEAD:top-file.t) &&
> +	HEAD_short_submodule=$(git rev-parse --short HEAD:submodule) &&
> +	HEAD_short_dir_sub_file=$(git rev-parse --short HEAD:dir/sub-file.t)
> +'
> +test_ls_tree_format_mode_output "--object-only --abbrev" "" "-t" <<-EOF

... this line passes a first argument that contains spaces. Hence the
tests fail in CI:
https://github.com/git/git/runs/6703333447?check_suite_focus=true

Further, since this failure is outside of any `test_expect_success` or
`test_expect_failure`, the error message about this is not even included
in the weblogs (but of course it is included in the full logs that are
included in the build artifacts). For the record, here is the error
message:

	[...]

	ok 35 - 'ls-tree --object-only -r' output (via subdir)
	+ git rev-parse --short HEAD:.gitmodules
	+ HEAD_short_gitmodules=6da7993
	+ git rev-parse --short HEAD:dir
	+ HEAD_short_dir=aba57e0
	+ git rev-parse --short HEAD:top-file.t
	+ HEAD_short_top_file=02dad95
	+ git rev-parse --short HEAD:submodule
	+ HEAD_short_submodule=61a63ac
	+ git rev-parse --short HEAD:dir/sub-file.t
	+ HEAD_short_dir_sub_file=a150abd

	ok 36 - setup: HEAD_short_* variables
	t3105-ls-tree-output.sh: 20: local: --abbrev: bad variable name
	FATAL: Unexpected exit with code 2

Note: I am only pointing out why the CI/PR run fails, I have not formed
any opinion on the actual code other than noticing a lot of what might be
repetitive lines and suspecting that adding this many new test cases
increases the runtime of the test suite and thereby adds to developer
friction and the benefit (namely, to catch future regressions) might not
justify that. But again, I have not fully formed an opinion about this
patch.

Ciao,
Johannes
Junio C Hamano June 2, 2022, 5:48 p.m. UTC | #2
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> +test_ls_tree_format_mode_output () {
>> +	local opts=$1 &&
>
> This line does not quote `$1`, but...
>
> ... this line passes a first argument that contains spaces. Hence the
> tests fail in CI:
> https://github.com/git/git/runs/6703333447?check_suite_focus=true

We had a portability discussion not so in distant past on "local".

  https://lore.kernel.org/git/xmqqsftc3nd6.fsf@gitster.g/

The conclusion from the thread IIRC is

 * Very safe

	local var; var=$1

 * Probably OK

	local var="$1"

 * Not portable

	local var=$1

Thanks.
Ævar Arnfjörð Bjarmason June 3, 2022, 9:54 a.m. UTC | #3
On Thu, Jun 02 2022, Johannes Schindelin wrote:

> On Tue, 31 May 2022, Ævar Arnfjörð Bjarmason wrote:
> [...]
>> +test_ls_tree_format_mode_output () {
>> +	local opts=$1 &&
>
> This line does not quote `$1`, but...

Well spotted, thanks, I don't know how I missed that, will fix it &
re-roll, but per changed $subject...

> [...]
> ... this line passes a first argument that contains spaces. Hence the
> tests fail in CI:
> https://github.com/git/git/runs/6703333447?check_suite_focus=true
>
> Further, since this failure is outside of any `test_expect_success` or
> `test_expect_failure`, the error message about this is not even included
> in the weblogs (but of course it is included in the full logs that are
> included in the build artifacts). For the record, here is the error
> message:

...this part of it though seems like a pretty bad regression in your
merged-to-next js/ci-github-workflow-markup topic, which just happens to
be unearthed by this CI failure.

On top of master this patch will get this CI failure:
https://github.com/avar/git/runs/6675920732?check_suite_focus=true#step:5:598;
Ending in ("[...]" edit is mine):
	
	 ok 35 - 'ls-tree --object-only -r' output (via subdir)
	+ git rev-parse --short HEAD:.gitmodules
	[...]
	+ HEAD_short_dir_sub_file=a150abd
	
	ok 36 - setup: HEAD_short_* variables
	t3105-ls-tree-output.sh: 20: local: --abbrev: bad variable name
	FATAL: Unexpected exit with code 2

So here we see that we got to test 36, and then got this error. All of
which is after the step we focused on to begin with would have shown:
	
	 Test Summary Report
	-------------------
	t3105-ls-tree-output.sh                          (Wstat: 256 Tests: 36 Failed: 0)
	  Non-zero exit status: 1
	  Parse errors: No plan found in TAP output

I.e. telling us we had a TAP parse error, so something like this was
going on.

But now we'll instead get ("=>" edit is mine, it didn't copy/paste):

	=> Run tests
	=== Failed test: t3105-ls-tree-output ===
	The full logs are in the artifacts attached to this run.
	Error: Process completed with exit code 1.

Where expanding the "=>" in "Run tests" will get us the "Test summary
report" from before, but now we have no "ci/print-test-failures.sh" step
to emit the output we got from the test, and we just get a cryptic error
about t3105 having failed *somewhere*.

As noted in the breadcrumb trail leading from "[2]" in [1] this is a
fundamental limitation of the approach you picked for
--github-workflow-markup. You're tasking the test-lib.sh to emit
well-formed output, but as shown here we can die prematurely on "eval"
failures.

But this does look easy to "solve" with a quicker fix, just bringing
back the "ci/print-test-failures.sh" step so you can at least expand it,
and not have to go to the "summary" and download the *.zip of the log
itself. As that shows we still have the raw log there, it just didn't
make it to the new GitHub Markdown formatting mechanism.

1. https://lore.kernel.org/git/220324.8635j7nyvw.gmgdl@evledraar.gmail.com/
Junio C Hamano June 3, 2022, 7:27 p.m. UTC | #4
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

>> Further, since this failure is outside of any `test_expect_success` or
>> `test_expect_failure`, the error message about this is not even included
>> in the weblogs (but of course it is included in the full logs that are
>> included in the build artifacts). For the record, here is the error
>> message:
>
> ...this part of it though seems like a pretty bad regression in your
> merged-to-next js/ci-github-workflow-markup topic, which just happens to
> be unearthed by this CI failure.

Indeed it makes it impossible to figure it out things like this
case.  But ...

> But this does look easy to "solve" with a quicker fix, just bringing
> back the "ci/print-test-failures.sh" step so you can at least expand it,
> and not have to go to the "summary" and download the *.zip of the log
> itself. As that shows we still have the raw log there, it just didn't
> make it to the new GitHub Markdown formatting mechanism.

... it seems a solution is possible?  Care to send in a patch (or
perhaps Dscho already has a counter-proposal)?

Thanks.
Ævar Arnfjörð Bjarmason June 3, 2022, 11:13 p.m. UTC | #5
On Fri, Jun 03 2022, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>>> Further, since this failure is outside of any `test_expect_success` or
>>> `test_expect_failure`, the error message about this is not even included
>>> in the weblogs (but of course it is included in the full logs that are
>>> included in the build artifacts). For the record, here is the error
>>> message:
>>
>> ...this part of it though seems like a pretty bad regression in your
>> merged-to-next js/ci-github-workflow-markup topic, which just happens to
>> be unearthed by this CI failure.
>
> Indeed it makes it impossible to figure it out things like this
> case.  But ...
>
>> But this does look easy to "solve" with a quicker fix, just bringing
>> back the "ci/print-test-failures.sh" step so you can at least expand it,
>> and not have to go to the "summary" and download the *.zip of the log
>> itself. As that shows we still have the raw log there, it just didn't
>> make it to the new GitHub Markdown formatting mechanism.
>
> ... it seems a solution is possible?  Care to send in a patch (or
> perhaps Dscho already has a counter-proposal)?

The only thing I have at the moment is:

    1. git revert -m 1 bd37e9e41f5
    2. merge: https://lore.kernel.org/git/cover-v6-00.29-00000000000-20220525T094123Z-avarab@gmail.com/
    3. merge: https://lore.kernel.org/git/cover-v6-00.14-00000000000-20220525T100743Z-avarab@gmail.com/

I.e. to pick this in the sequence I'd proposed doing & have tested
thoroughly.

It also addresses other noted some other regressions in "next", but as
noted e.g. in [A] there's other issues in "next", e.g. that even the
"raw" trace logs are altered as a side-effect of running with
--github-workflow-markup, and of course the major UX slowdowns.

So I think the better way forward would be to do that & leave out [B],
i.e. make the new output format optional, and wait until outstanding
issues are fixed until we flip the default.

But do I have something that neatly fixes the issue(s) on top of "next"
without a revert & re-apply? No, sorry.

In case you want to go for that the resolution for [2] is [C], and a
"git rm ci/run-build-and-tests.sh ci/run-static-analysis.sh".

A. https://lore.kernel.org/git/patch-v6-13.14-fbe0d99c6b3-20220525T100743Z-avarab@gmail.com/
B. https://lore.kernel.org/git/patch-v6-14.14-0b02b186c87-20220525T100743Z-avarab@gmail.com/
C. 
	diff --git a/Makefile b/Makefile
	index 19f3756f7eb..c2b0a728df5 100644
	--- a/Makefile
	+++ b/Makefile
	@@ -3618,3 +3618,4 @@ ci-static-analysis: ci-check-directional-formatting
	 ci-static-analysis: check-builtins
	 ci-static-analysis: check-coccicheck
	 ci-static-analysis: hdr-check
	+ci-static-analysis: check-pot
	diff --git a/ci/lib.sh b/ci/lib.sh
	index 80e89f89b7f..9c54c1330e6 100755
	--- a/ci/lib.sh
	+++ b/ci/lib.sh
	@@ -270,7 +270,7 @@ linux-TEST-vars)
	        setenv --test GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS 1
	        setenv --test GIT_TEST_MULTI_PACK_INDEX 1
	        setenv --test GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP 1
	-       setenv --test GIT_TEST_ADD_I_USE_BUILTIN 1
	+       setenv --test GIT_TEST_ADD_I_USE_BUILTIN 0
	        setenv --test GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME master
	        setenv --test GIT_TEST_WRITE_REV_INDEX 1
	        setenv --test GIT_TEST_CHECKOUT_WORKERS 2
Junio C Hamano June 7, 2022, 6:25 p.m. UTC | #6
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> On Fri, Jun 03 2022, Junio C Hamano wrote:
>
>> Indeed it makes it impossible to figure it out things like this
>> case.  But ...
>>
>>> But this does look easy to "solve" with a quicker fix, just bringing
>>> back the "ci/print-test-failures.sh" step so you can at least expand it,
>>> and not have to go to the "summary" and download the *.zip of the log
>>> itself. As that shows we still have the raw log there, it just didn't
>>> make it to the new GitHub Markdown formatting mechanism.
>>
>> ... it seems a solution is possible?  Care to send in a patch (or
>> perhaps Dscho already has a counter-proposal)?
>
> The only thing I have at the moment is:
>
>     1. git revert -m 1 bd37e9e41f5
>     2. merge: https://lore.kernel.org/git/cover-v6-00.29-00000000000-20220525T094123Z-avarab@gmail.com/
>     3. merge: https://lore.kernel.org/git/cover-v6-00.14-00000000000-20220525T100743Z-avarab@gmail.com/
>
> I.e. to pick this in the sequence I'd proposed doing & have tested
> thoroughly.

I know you two have difference in opinions, but throwing away
everything the other party did and forcing your stuff in is not a
very effective way to work together.

> It also addresses other noted some other regressions in "next", but as
> noted e.g. in [A] there's other issues in "next", e.g. that even the
> "raw" trace logs are altered as a side-effect of running with
> --github-workflow-markup, and of course the major UX slowdowns.

Dscho?  I know you do not care about the UX slowdown as much as
others, but I am sure you do not consider what is in 'next' is
perfect. It seems to need further work to go back to the feature
parity with what it replaced.
Ævar Arnfjörð Bjarmason June 7, 2022, 9:40 p.m. UTC | #7
On Tue, Jun 07 2022, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> On Fri, Jun 03 2022, Junio C Hamano wrote:
>>
>>> Indeed it makes it impossible to figure it out things like this
>>> case.  But ...
>>>
>>>> But this does look easy to "solve" with a quicker fix, just bringing
>>>> back the "ci/print-test-failures.sh" step so you can at least expand it,
>>>> and not have to go to the "summary" and download the *.zip of the log
>>>> itself. As that shows we still have the raw log there, it just didn't
>>>> make it to the new GitHub Markdown formatting mechanism.
>>>
>>> ... it seems a solution is possible?  Care to send in a patch (or
>>> perhaps Dscho already has a counter-proposal)?
>>
>> The only thing I have at the moment is:
>>
>>     1. git revert -m 1 bd37e9e41f5
>>     2. merge: https://lore.kernel.org/git/cover-v6-00.29-00000000000-20220525T094123Z-avarab@gmail.com/
>>     3. merge: https://lore.kernel.org/git/cover-v6-00.14-00000000000-20220525T100743Z-avarab@gmail.com/
>>
>> I.e. to pick this in the sequence I'd proposed doing & have tested
>> thoroughly.
>
> I know you two have difference in opinions, but throwing away
> everything the other party did and forcing your stuff in is not a
> very effective way to work together.

I'm suggesting getting Johannes's patches in combined with the changes &
bugfixes I'd proposed.

So no, not throwing that work away, it would (applied up to 14/14) give
you functionally the same end result that's on "next" now as far as the
new GitHub Markdown output is concerned. The [3] above has links to the
relevant CI output.

I had tried to rebase the above [2] on top of "next" before this
discussion started, I agree that would be ideal, but it's a much larger
logical change that I don't have time to pursue now.

I.e. there's a reason I proposed doing it in that order, a logical
rebasing of [2] on top of bd37e9e41f5 would involve a lot of backing out
of the existing direction taken there. I.e. the whole part where the
split by "steps" provides much of the ci/* specific code in bd37e9e41f5
for free.

>> It also addresses other noted some other regressions in "next", but as
>> noted e.g. in [A] there's other issues in "next", e.g. that even the
>> "raw" trace logs are altered as a side-effect of running with
>> --github-workflow-markup, and of course the major UX slowdowns.
>
> Dscho?  I know you do not care about the UX slowdown as much as
> others, but I am sure you do not consider what is in 'next' is
> perfect. It seems to need further work to go back to the feature
> parity with what it replaced.

Just to be clear [3] up to 14/14 would still exhibit this particular
bug, but with 13/14 it wouldn't from the links in [3] the relevant
outputs are:

 "next" (well, similar): https://github.com/avar/git/runs/6571972194?check_suite_focus=true
 [3] with 14/14: https://github.com/avar/git/runs/6588407676?check_suite_focus=true
 [3] with 13/14: https://github.com/avar/git/runs/6588579493?check_suite_focus=true

I really would like to get is out of this long-running ci/ limbo,
perhaps Johannes has some proposed patches, but I don't think fixing the
outstanding bugs is going to be trivial or easy.  Some of it's hard to
tease apart, e.g. the altered *.out logs seem to require some tricky
test-lib.sh and test-lib-functions.sh changes.

I don't see why wouldn't get all of that code in now though, just hidden
behind a flag, that would take the pressure off dealing with the current
regressions, [2] with 13/14 would do that. Then once those outstanding
issues are fixed we'd just need the one-line 14/14 change to flip the
default CI output.

But is it the smallest possible change on top of what's now in "next"?
No, of course not.

But I don't have those hypothetical patches, just the above. That's all
I meant in reply to the "care to send in a patch?"  upthread.
Johannes Schindelin June 8, 2022, 8:04 a.m. UTC | #8
Hi Junio,

On Tue, 7 Jun 2022, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
> > On Fri, Jun 03 2022, Junio C Hamano wrote:
> >
> >> Indeed it makes it impossible to figure it out things like this case.
> >> But ...
> >>
> >>> But this does look easy to "solve" with a quicker fix, just bringing
> >>> back the "ci/print-test-failures.sh" step so you can at least expand
> >>> it, and not have to go to the "summary" and download the *.zip of
> >>> the log itself.

I agree that re-adding the `ci/print-test-failures.sh` step makes sense,
given the recent experience.

> >>> As that shows we still have the raw log there, it just didn't make
> >>> it to the new GitHub Markdown formatting mechanism.
> >>
> >> ... it seems a solution is possible?  Care to send in a patch (or
> >> perhaps Dscho already has a counter-proposal)?

I will work on this.

> > The only thing I have at the moment is:
> >
> >     1. git revert -m 1 bd37e9e41f5
> >     2. merge: https://lore.kernel.org/git/cover-v6-00.29-00000000000-20220525T094123Z-avarab@gmail.com/
> >     3. merge: https://lore.kernel.org/git/cover-v6-00.14-00000000000-20220525T100743Z-avarab@gmail.com/
> >
> > I.e. to pick this in the sequence I'd proposed doing & have tested
> > thoroughly.
>
> I know you two have difference in opinions, but throwing away everything
> the other party did and forcing your stuff in is not a very effective
> way to work together.

I had already pointed out a rather terrible issue in that 29-strong patch
series: Dropping Azure Pipelines support makes it unnecessarily harder to
work on Git security issues. And it's not like we have an armada of people
working on those. I, for one, am pretty worn out from the recent work.

It might not be the intention of that patch series to make my life harder,
but it sure would be its impact. And intent does not excuse impact.

I therefore had to conclude that the patch series in this form cannot be
merged.

I recall that other reviews reached the same consensus, that this
29-strong patch series is too unfocused on any particular goal. So maybe
calling this "my opinion" is not exactly fair.

> > It also addresses other noted some other regressions in "next", but as
> > noted e.g. in [A] there's other issues in "next", e.g. that even the
> > "raw" trace logs are altered as a side-effect of running with
> > --github-workflow-markup, and of course the major UX slowdowns.
>
> Dscho?  I know you do not care about the UX slowdown as much as
> others, but I am sure you do not consider what is in 'next' is
> perfect. It seems to need further work to go back to the feature
> parity with what it replaced.

Indeed, I do not consider it perfect. I even said so much in every
iteration's cover letter ;-)

I will work on bringing back the `print-test-failures` step.

Ciao,
Dscho
Ævar Arnfjörð Bjarmason June 9, 2022, 7:43 p.m. UTC | #9
On Wed, Jun 08 2022, Johannes Schindelin wrote:

> Hi Junio,
>
> On Tue, 7 Jun 2022, Junio C Hamano wrote:
>
>> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>>
>> > On Fri, Jun 03 2022, Junio C Hamano wrote:
>> >
>> >> Indeed it makes it impossible to figure it out things like this case.
>> >> But ...
>> >>
>> >>> But this does look easy to "solve" with a quicker fix, just bringing
>> >>> back the "ci/print-test-failures.sh" step so you can at least expand
>> >>> it, and not have to go to the "summary" and download the *.zip of
>> >>> the log itself.
>
> I agree that re-adding the `ci/print-test-failures.sh` step makes sense,
> given the recent experience.
>
>> >>> As that shows we still have the raw log there, it just didn't make
>> >>> it to the new GitHub Markdown formatting mechanism.
>> >>
>> >> ... it seems a solution is possible?  Care to send in a patch (or
>> >> perhaps Dscho already has a counter-proposal)?
>
> I will work on this.
>
>> > The only thing I have at the moment is:
>> >
>> >     1. git revert -m 1 bd37e9e41f5
>> >     2. merge: https://lore.kernel.org/git/cover-v6-00.29-00000000000-20220525T094123Z-avarab@gmail.com/
>> >     3. merge: https://lore.kernel.org/git/cover-v6-00.14-00000000000-20220525T100743Z-avarab@gmail.com/
>> >
>> > I.e. to pick this in the sequence I'd proposed doing & have tested
>> > thoroughly.
>>
>> I know you two have difference in opinions, but throwing away everything
>> the other party did and forcing your stuff in is not a very effective
>> way to work together.
>
> I had already pointed out a rather terrible issue in that 29-strong patch
> series: Dropping Azure Pipelines support makes it unnecessarily harder to
> work on Git security issues. And it's not like we have an armada of people
> working on those. I, for one, am pretty worn out from the recent work.
>
> It might not be the intention of that patch series to make my life harder,
> but it sure would be its impact. And intent does not excuse impact.
>
> I therefore had to conclude that the patch series in this form cannot be
> merged.

You raised the same concern in February, and I made some practical
suggestions for how to proceed with that in:

    https://lore.kernel.org/git/220222.86y2236ndp.gmgdl@evledraar.gmail.com/

You didn't reply, and here was a reminder in late March:

    https://lore.kernel.org/git/cover-v2-00.25-00000000000-20220325T182534Z-avarab@gmail.com/

You then had a similar concern, and I replied again in early April
saying I'd be happy to acomodate you, if you could reply to that
original E-Mail and clarify what you'd like exactly:

    https://lore.kernel.org/git/220406.86bkxeecoi.gmgdl@evledraar.gmail.com/

And here's a mention of it again in late April:

    https://lore.kernel.org/git/220421.86fsm66zmz.gmgdl@evledraar.gmail.com/

Then a few weeks ago you brought up the same point, and I replied again
you to please reply to that E-mail from back in February:

    https://lore.kernel.org/git/220524.86y1yrwaw0.gmgdl@evledraar.gmail.com/

So really Johannes, I'm completely fine with accommodating you.

But when you suggest that some ad-hoc combination of out-of-tree code
and not-used-in-tree code you have must not be touched *and* you're
seemingly unwilling to figure out some way forward you're not being very
helpful.

Instead you just keep repeating that something must not be changed, and
when it's pointed out to you that that would block someone else's
patches, but would you be OK with X, Y or Z you seemingly just blackhole
the replies you get.

So can you reply to that this time? Thanks.

> I recall that other reviews reached the same consensus, that this
> 29-strong patch series is too unfocused on any particular goal. So maybe
> calling this "my opinion" is not exactly fair.

Yes, that's something others brought up, but it's unrelated to the Azure
issue you're raising here. That change was contained within the first 6
or so patches of that series.
diff mbox series

Patch

diff --git a/t/lib-t3100.sh b/t/lib-t3100.sh
new file mode 100644
index 00000000000..eabb5fd8034
--- /dev/null
+++ b/t/lib-t3100.sh
@@ -0,0 +1,10 @@ 
+#!/bin/sh
+
+setup_basic_ls_tree_data () {
+	mkdir dir &&
+	test_commit dir/sub-file &&
+	test_commit top-file &&
+	git clone . submodule &&
+	git submodule add ./submodule &&
+	git commit -m"add submodule"
+}
diff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh
index 0769a933d69..383896667b6 100755
--- a/t/t3104-ls-tree-format.sh
+++ b/t/t3104-ls-tree-format.sh
@@ -4,6 +4,7 @@  test_description='ls-tree --format'
 
 TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-t3100.sh
 
 test_expect_success 'ls-tree --format usage' '
 	test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
@@ -12,9 +13,7 @@  test_expect_success 'ls-tree --format usage' '
 '
 
 test_expect_success 'setup' '
-	mkdir dir &&
-	test_commit dir/sub-file &&
-	test_commit top-file
+	setup_basic_ls_tree_data
 '
 
 test_ls_tree_format () {
diff --git a/t/t3105-ls-tree-output.sh b/t/t3105-ls-tree-output.sh
new file mode 100755
index 00000000000..29511d9331b
--- /dev/null
+++ b/t/t3105-ls-tree-output.sh
@@ -0,0 +1,192 @@ 
+#!/bin/sh
+
+test_description='ls-tree output'
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-t3100.sh
+
+test_expect_success 'ls-tree --format usage' '
+	test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
+	test_expect_code 129 git ls-tree --format=fmt --name-only HEAD &&
+	test_expect_code 129 git ls-tree --format=fmt --name-status HEAD
+'
+
+test_expect_success 'setup' '
+	setup_basic_ls_tree_data
+'
+
+test_ls_tree_format_mode_output () {
+	local opts=$1 &&
+	shift &&
+	cat >expect &&
+
+	while test $# -gt 0
+	do
+		local mode="$1" &&
+		shift &&
+
+		test_expect_success "'ls-tree $opts${mode:+ $mode}' output" '
+			git ls-tree ${mode:+$mode }$opts HEAD >actual &&
+			test_cmp expect actual
+		'
+
+		case "$opts" in
+		--full-tree)
+			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir, fails)" '
+				test_must_fail git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../
+			'
+			;;
+		*)
+			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir)" '
+				git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../ >actual &&
+				test_cmp expect actual
+			'
+			;;
+		esac
+	done
+}
+
+# test exact output of option (none, --long, ...) and mode (none and
+# -d, -r -t) and combinations
+test_expect_success 'setup: HEAD_* variables' '
+	HEAD_gitmodules=$(git rev-parse HEAD:.gitmodules) &&
+	HEAD_dir=$(git rev-parse HEAD:dir) &&
+	HEAD_top_file=$(git rev-parse HEAD:top-file.t) &&
+	HEAD_submodule=$(git rev-parse HEAD:submodule) &&
+	HEAD_dir_sub_file=$(git rev-parse HEAD:dir/sub-file.t)
+'
+## opt =
+test_ls_tree_format_mode_output "" "" "-t" <<-EOF
+	100644 blob $HEAD_gitmodules	.gitmodules
+	040000 tree $HEAD_dir	dir
+	160000 commit $HEAD_submodule	submodule
+	100644 blob $HEAD_top_file	top-file.t
+	EOF
+test_ls_tree_format_mode_output "" "-d" <<-EOF
+	040000 tree $HEAD_dir	dir
+	160000 commit $HEAD_submodule	submodule
+	EOF
+test_ls_tree_format_mode_output "" "-r" <<-EOF
+	100644 blob $HEAD_gitmodules	.gitmodules
+	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
+	160000 commit $HEAD_submodule	submodule
+	100644 blob $HEAD_top_file	top-file.t
+	EOF
+## opt = --long
+test_ls_tree_format_mode_output "--long" "" "-t" <<-EOF
+	100644 blob $HEAD_gitmodules      61	.gitmodules
+	040000 tree $HEAD_dir       -	dir
+	160000 commit $HEAD_submodule       -	submodule
+	100644 blob $HEAD_top_file       9	top-file.t
+	EOF
+test_ls_tree_format_mode_output "--long" "-d" <<-EOF
+	040000 tree $HEAD_dir       -	dir
+	160000 commit $HEAD_submodule       -	submodule
+	EOF
+test_ls_tree_format_mode_output "--long" "-r" <<-EOF
+	100644 blob $HEAD_gitmodules      61	.gitmodules
+	100644 blob $HEAD_dir_sub_file      13	dir/sub-file.t
+	160000 commit $HEAD_submodule       -	submodule
+	100644 blob $HEAD_top_file       9	top-file.t
+	EOF
+## opt = --name-only
+test_ls_tree_format_mode_output "--name-only" "" "-t" <<-EOF
+	.gitmodules
+	dir
+	submodule
+	top-file.t
+	EOF
+test_ls_tree_format_mode_output "--name-only" "-d" <<-EOF
+	dir
+	submodule
+	EOF
+test_ls_tree_format_mode_output "--name-only" "-r" <<-EOF
+	.gitmodules
+	dir/sub-file.t
+	submodule
+	top-file.t
+	EOF
+## opt = --object-only
+test_ls_tree_format_mode_output "--object-only" "" "-t" <<-EOF
+	$HEAD_gitmodules
+	$HEAD_dir
+	$HEAD_submodule
+	$HEAD_top_file
+	EOF
+test_ls_tree_format_mode_output "--object-only" "-d" <<-EOF
+	$HEAD_dir
+	$HEAD_submodule
+	EOF
+test_ls_tree_format_mode_output "--object-only" "-r" <<-EOF
+	$HEAD_gitmodules
+	$HEAD_dir_sub_file
+	$HEAD_submodule
+	$HEAD_top_file
+	EOF
+## opt = --object-only --abbrev
+test_expect_success 'setup: HEAD_short_* variables' '
+	HEAD_short_gitmodules=$(git rev-parse --short HEAD:.gitmodules) &&
+	HEAD_short_dir=$(git rev-parse --short HEAD:dir) &&
+	HEAD_short_top_file=$(git rev-parse --short HEAD:top-file.t) &&
+	HEAD_short_submodule=$(git rev-parse --short HEAD:submodule) &&
+	HEAD_short_dir_sub_file=$(git rev-parse --short HEAD:dir/sub-file.t)
+'
+test_ls_tree_format_mode_output "--object-only --abbrev" "" "-t" <<-EOF
+	$HEAD_short_gitmodules
+	$HEAD_short_dir
+	$HEAD_short_submodule
+	$HEAD_short_top_file
+	EOF
+test_ls_tree_format_mode_output "--object-only --abbrev" "-d" <<-EOF
+	$HEAD_short_dir
+	$HEAD_short_submodule
+	EOF
+test_ls_tree_format_mode_output "--object-only --abbrev" "-r" <<-EOF
+	$HEAD_short_gitmodules
+	$HEAD_short_dir_sub_file
+	$HEAD_short_submodule
+	$HEAD_short_top_file
+	EOF
+## opt = --full-name
+test_ls_tree_format_mode_output "--full-name" "" <<-EOF
+	100644 blob $HEAD_gitmodules	.gitmodules
+	040000 tree $HEAD_dir	dir
+	160000 commit $HEAD_submodule	submodule
+	100644 blob $HEAD_top_file	top-file.t
+	EOF
+test_ls_tree_format_mode_output "--full-name" "-d" <<-EOF
+	040000 tree $HEAD_dir	dir
+	160000 commit $HEAD_submodule	submodule
+	EOF
+test_ls_tree_format_mode_output "--full-name" "-r" <<-EOF
+	100644 blob $HEAD_gitmodules	.gitmodules
+	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
+	160000 commit $HEAD_submodule	submodule
+	100644 blob $HEAD_top_file	top-file.t
+	EOF
+test_ls_tree_format_mode_output "--full-name" "-t" <<-EOF
+	100644 blob $HEAD_gitmodules	.gitmodules
+	040000 tree $HEAD_dir	dir
+	160000 commit $HEAD_submodule	submodule
+	100644 blob $HEAD_top_file	top-file.t
+	EOF
+## opt = --full-tree
+test_ls_tree_format_mode_output "--full-tree" "" "-t" <<-EOF
+	100644 blob $HEAD_gitmodules	.gitmodules
+	040000 tree $HEAD_dir	dir
+	160000 commit $HEAD_submodule	submodule
+	100644 blob $HEAD_top_file	top-file.t
+	EOF
+test_ls_tree_format_mode_output "--full-tree" "-d" <<-EOF
+	040000 tree $HEAD_dir	dir
+	160000 commit $HEAD_submodule	submodule
+	EOF
+test_ls_tree_format_mode_output "--full-tree" "-r" <<-EOF
+	100644 blob $HEAD_gitmodules	.gitmodules
+	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
+	160000 commit $HEAD_submodule	submodule
+	100644 blob $HEAD_top_file	top-file.t
+	EOF
+
+test_done