]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3104-ls-tree-format.sh
fsck: check even zero-entry index files
[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 . "$TEST_DIRECTORY"/lib-t3100.sh
8
9 test_expect_success 'ls-tree --format usage' '
10 test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
11 test_expect_code 129 git ls-tree --format=fmt --name-only HEAD &&
12 test_expect_code 129 git ls-tree --format=fmt --name-status HEAD
13 '
14
15 test_expect_success 'setup' '
16 setup_basic_ls_tree_data
17 '
18
19 test_ls_tree_format () {
20 format=$1 &&
21 opts=$2 &&
22 fmtopts=$3 &&
23 shift 2 &&
24
25 test_expect_success "ls-tree '--format=<$format>' is like options '$opts $fmtopts'" '
26 git ls-tree $opts -r HEAD >expect &&
27 git ls-tree --format="$format" -r $fmtopts HEAD >actual &&
28 test_cmp expect actual
29 '
30
31 test_expect_success "ls-tree '--format=<$format>' on optimized v.s. non-optimized path" '
32 git ls-tree --format="$format" -r $fmtopts HEAD >expect &&
33 git ls-tree --format="> $format" -r $fmtopts HEAD >actual.raw &&
34 sed "s/^> //" >actual <actual.raw &&
35 test_cmp expect actual
36 '
37 }
38
39 test_expect_success "ls-tree --format='%(path) %(path) %(path)' HEAD top-file" '
40 git ls-tree --format="%(path) %(path) %(path)" HEAD top-file.t >actual &&
41 echo top-file.t top-file.t top-file.t >expect &&
42 test_cmp expect actual
43 '
44
45 test_ls_tree_format \
46 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
47 ""
48
49 test_ls_tree_format \
50 "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
51 "--long"
52
53 test_ls_tree_format \
54 "%(path)" \
55 "--name-only"
56
57 test_ls_tree_format \
58 "%(objectname)" \
59 "--object-only"
60
61 test_ls_tree_format \
62 "%(objectname)" \
63 "--object-only --abbrev" \
64 "--abbrev"
65
66 test_ls_tree_format \
67 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
68 "-t" \
69 "-t"
70
71 test_ls_tree_format \
72 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
73 "--full-name" \
74 "--full-name"
75
76 test_ls_tree_format \
77 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
78 "--full-tree" \
79 "--full-tree"
80
81 test_done