Re: [PATCH 2/3] t3104: add related tests for `--oid-only` option
On 2021-11-15 19:51:52+0800, Teng Long <dyroneteng@gmail.com> wrote:
Show 37 quoted lines
> Signed-off-by: Teng Long <dyroneteng@gmail.com>
> ---
> t/t3104-ls-tree-oid.sh | 55 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
> create mode 100755 t/t3104-ls-tree-oid.sh
>
> diff --git a/t/t3104-ls-tree-oid.sh b/t/t3104-ls-tree-oid.sh
> new file mode 100755
> index 0000000000..78ab9127c7
> --- /dev/null
> +++ b/t/t3104-ls-tree-oid.sh
> @@ -0,0 +1,55 @@
> +#!/bin/sh
> +
> +test_description='git ls-tree oids handling.'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'setup' '
> + echo 111 >1.txt &&
> + echo 222 >2.txt &&
> + mkdir -p path0/a/b/c &&
> + echo 333 >path0/a/b/c/3.txt &&
> + find *.txt path* \( -type f -o -type l \) -print |
> + xargs git update-index --add &&
> + tree=$(git write-tree) &&
> + echo $tree
> +'
> +
> +
> +test_expect_success 'specify with --oid-only' '
> + git ls-tree --oid-only $tree >current &&
> + cat >expected <<\EOF &&
> +58c9bdf9d017fcd178dc8c073cbfcbb7ff240d6c
> +c200906efd24ec5e783bee7f23b5d7c941b0c12c
> +4e3849a078083863912298a25db30997cb8ca6d6
> +EOF
Failed with:
GIT_TEST_DEFAULT_HASH=sha256 ./t3104-ls-tree-oid.sh
I think we can use:
git ls-tree $tree | awk '{print $3}' >expectedShow 12 quoted lines
> + test_cmp current expected
> +'
> +
> +test_expect_success 'specify with --oid-only and -r' '
> + git ls-tree --oid-only -r $tree >current &&
> + cat >expected <<\EOF &&
> +58c9bdf9d017fcd178dc8c073cbfcbb7ff240d6c
> +c200906efd24ec5e783bee7f23b5d7c941b0c12c
> +55bd0ac4c42e46cd751eb7405e12a35e61425550
> +EOF
> + test_cmp current expected
> +'
Ditto for this test and below tests.
Show 13 quoted lines
> +
> +test_expect_success 'specify with --oid-only and --abbrev' '
> + git ls-tree --oid-only --abbrev=6 $tree >current &&
> + cat >expected <<\EOF &&
> +58c9bd
> +c20090
> +4e3849
> +EOF
> + test_cmp current expected
> +'
> +
> +test_expect_success 'cannot specify --name-only and --oid-only as the same time' '
> + test_must_fail git ls-tree --oid-only --name-only $tree >current 2>&1 >/dev/null &&
The last redirection '>/dev/null' does nothing, me think.
> + echo "fatal: cannot specify --oid-only and --name-only at the same time" > expected &&
Style nit:
use '>expected' instead of '> expected'
Show 7 quoted lines
> + test_cmp current expected
> +'
> +
> +test_done
> --
> 2.33.1.9.g5fbd2fc599.dirty
>
--
Danh