]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-tree: test for the regression in 9c4d58ff2c3
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 3 Jun 2022 10:23:10 +0000 (12:23 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Jun 2022 16:47:11 +0000 (09:47 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/lib-t3100.sh [new file with mode: 0644]
t/t3104-ls-tree-format.sh
t/t3105-ls-tree-output.sh [new file with mode: 0755]

diff --git a/t/lib-t3100.sh b/t/lib-t3100.sh
new file mode 100644 (file)
index 0000000..eabb5fd
--- /dev/null
@@ -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"
+}
index 0769a933d695e5525b08a4e39b8cc0f8370eb08b..383896667b6dc9e446c157370dedd3a3aa8051d1 100755 (executable)
@@ -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 (executable)
index 0000000..ce2391e
--- /dev/null
@@ -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