Git fork
1#!/bin/sh
2
3test_description='ls-tree --format'
4
5. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-t3100.sh
7
8test_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
14test_expect_success 'setup' '
15 setup_basic_ls_tree_data
16'
17
18test_ls_tree_format () {
19 format=$1 &&
20 opts=$2 &&
21 fmtopts=$3 &&
22
23 test_expect_success "ls-tree '--format=<$format>' is like options '$opts $fmtopts'" '
24 git ls-tree $opts -r HEAD >expect &&
25 git ls-tree --format="$format" -r $fmtopts HEAD >actual &&
26 test_cmp expect actual
27 '
28
29 test_expect_success "ls-tree '--format=<$format>' on optimized v.s. non-optimized path" '
30 git ls-tree --format="$format" -r $fmtopts HEAD >expect &&
31 git ls-tree --format="> $format" -r $fmtopts HEAD >actual.raw &&
32 sed "s/^> //" >actual <actual.raw &&
33 test_cmp expect actual
34 '
35}
36
37test_expect_success "ls-tree --format='%(path) %(path) %(path)' HEAD top-file" '
38 git ls-tree --format="%(path) %(path) %(path)" HEAD top-file.t >actual &&
39 echo top-file.t top-file.t top-file.t >expect &&
40 test_cmp expect actual
41'
42
43test_ls_tree_format \
44 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
45 ""
46
47test_ls_tree_format \
48 "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
49 "--long"
50
51test_ls_tree_format \
52 "%(path)" \
53 "--name-only"
54
55test_ls_tree_format \
56 "%(objectname)" \
57 "--object-only"
58
59test_ls_tree_format \
60 "%(objectname)" \
61 "--object-only --abbrev" \
62 "--abbrev"
63
64test_ls_tree_format \
65 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
66 "-t" \
67 "-t"
68
69test_ls_tree_format \
70 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
71 "--full-name" \
72 "--full-name"
73
74test_ls_tree_format \
75 "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
76 "--full-tree" \
77 "--full-tree"
78
79test_done