]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3104-ls-tree-format.sh
Merge branch 'tl/ls-tree-oid-only'
[thirdparty/git.git] / t / t3104-ls-tree-format.sh
1 #!/bin/sh
2
3 test_description='ls-tree --format'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'ls-tree --format usage' '
9 test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
10 test_expect_code 129 git ls-tree --format=fmt --name-only HEAD &&
11 test_expect_code 129 git ls-tree --format=fmt --name-status HEAD
12 '
13
14 test_expect_success 'setup' '
15 mkdir dir &&
16 test_commit dir/sub-file &&
17 test_commit top-file
18 '
19
20 test_ls_tree_format () {
21 format=$1 &&
22 opts=$2 &&
23 fmtopts=$3 &&
24 shift 2 &&
25
26 test_expect_success "ls-tree '--format=<$format>' is like options '$opts $fmtopts'" '
27 git ls-tree $opts -r HEAD >expect &&
28 git ls-tree --format="$format" -r $fmtopts HEAD >actual &&
29 test_cmp expect actual
30 '
31
32 test_expect_success "ls-tree '--format=<$format>' on optimized v.s. non-optimized path" '
33 git ls-tree --format="$format" -r $fmtopts HEAD >expect &&
34 git ls-tree --format="> $format" -r $fmtopts HEAD >actual.raw &&
35 sed "s/^> //" >actual <actual.raw &&
36 test_cmp expect actual
37 '
38 }
39
40 test_ls_tree_format \
41 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
42 ""
43
44 test_ls_tree_format \
45 "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
46 "--long"
47
48 test_ls_tree_format \
49 "%(path)" \
50 "--name-only"
51
52 test_ls_tree_format \
53 "%(objectname)" \
54 "--object-only"
55
56 test_ls_tree_format \
57 "%(objectname)" \
58 "--object-only --abbrev" \
59 "--abbrev"
60
61 test_ls_tree_format \
62 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
63 "-t" \
64 "-t"
65
66 test_ls_tree_format \
67 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
68 "--full-name" \
69 "--full-name"
70
71 test_ls_tree_format \
72 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
73 "--full-tree" \
74 "--full-tree"
75
76 test_done