summaryrefslogtreecommitdiff
path: root/t/t3104-ls-tree-format.sh
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2022-04-04 10:56:21 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2022-04-04 10:56:21 -0700
commit1041d58b4d9c587b2b6c76c3dfb14fbe78ccf196 (patch)
treef6203832102655e0e5de47976186bb4a250b75dd /t/t3104-ls-tree-format.sh
parentMerge branch 'ab/reflog-parse-options' (diff)
parentls-tree: split up "fast path" callbacks (diff)
downloadtgif-1041d58b4d9c587b2b6c76c3dfb14fbe78ccf196.tar.xz
Merge branch 'tl/ls-tree-oid-only'
"git ls-tree" learns "--oid-only" option, similar to "--name-only", and more generalized "--format" option. * tl/ls-tree-oid-only: ls-tree: split up "fast path" callbacks ls-tree: detect and error on --name-only --name-status ls-tree: support --object-only option for "git-ls-tree" ls-tree: introduce "--format" option cocci: allow padding with `strbuf_addf()` ls-tree: introduce struct "show_tree_data" ls-tree: slightly refactor `show_tree()` ls-tree: fix "--name-only" and "--long" combined use bug ls-tree: simplify nesting if/else logic in "show_tree()" ls-tree: rename "retval" to "recurse" in "show_tree()" ls-tree: use "size_t", not "int" for "struct strbuf"'s "len" ls-tree: use "enum object_type", not {blob,tree,commit}_type ls-tree: add missing braces to "else" arms ls-tree: remove commented-out code ls-tree tests: add tests for --name-status
Diffstat (limited to 't/t3104-ls-tree-format.sh')
-rwxr-xr-xt/t3104-ls-tree-format.sh76
1 files changed, 76 insertions, 0 deletions
diff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh
new file mode 100755
index 0000000000..0769a933d6
--- /dev/null
+++ b/t/t3104-ls-tree-format.sh
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+test_description='ls-tree --format'
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.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' '
+ mkdir dir &&
+ test_commit dir/sub-file &&
+ test_commit top-file
+'
+
+test_ls_tree_format () {
+ format=$1 &&
+ opts=$2 &&
+ fmtopts=$3 &&
+ shift 2 &&
+
+ 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 &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "ls-tree '--format=<$format>' on optimized v.s. non-optimized path" '
+ git ls-tree --format="$format" -r $fmtopts HEAD >expect &&
+ git ls-tree --format="> $format" -r $fmtopts HEAD >actual.raw &&
+ sed "s/^> //" >actual <actual.raw &&
+ test_cmp expect actual
+ '
+}
+
+test_ls_tree_format \
+ "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
+ ""
+
+test_ls_tree_format \
+ "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
+ "--long"
+
+test_ls_tree_format \
+ "%(path)" \
+ "--name-only"
+
+test_ls_tree_format \
+ "%(objectname)" \
+ "--object-only"
+
+test_ls_tree_format \
+ "%(objectname)" \
+ "--object-only --abbrev" \
+ "--abbrev"
+
+test_ls_tree_format \
+ "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
+ "-t" \
+ "-t"
+
+test_ls_tree_format \
+ "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
+ "--full-name" \
+ "--full-name"
+
+test_ls_tree_format \
+ "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
+ "--full-tree" \
+ "--full-tree"
+
+test_done