]>
Commit | Line | Data |
---|---|---|
ce74de93 ZH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git ls-files --format test' | |
4 | ||
5 | TEST_PASSES_SANITIZE_LEAK=true | |
6 | . ./test-lib.sh | |
7 | ||
8 | for flag in -s -o -k -t --resolve-undo --deduplicate --eol | |
9 | do | |
10 | test_expect_success "usage: --format is incompatible with $flag" ' | |
11 | test_expect_code 129 git ls-files --format="%(objectname)" $flag | |
12 | ' | |
13 | done | |
14 | ||
15 | test_expect_success 'setup' ' | |
16 | printf "LINEONE\nLINETWO\nLINETHREE\n" >o1.txt && | |
17 | printf "LINEONE\r\nLINETWO\r\nLINETHREE\r\n" >o2.txt && | |
18 | printf "LINEONE\r\nLINETWO\nLINETHREE\n" >o3.txt && | |
19 | git add o?.txt && | |
20 | oid=$(git hash-object o1.txt) && | |
21 | git update-index --add --cacheinfo 120000 $oid o4.txt && | |
22 | git update-index --add --cacheinfo 160000 $oid o5.txt && | |
23 | git update-index --add --cacheinfo 100755 $oid o6.txt && | |
24 | git commit -m base | |
25 | ' | |
26 | ||
27 | test_expect_success 'git ls-files --format objectmode v.s. -s' ' | |
28 | git ls-files -s >files && | |
29 | cut -d" " -f1 files >expect && | |
30 | git ls-files --format="%(objectmode)" >actual && | |
31 | test_cmp expect actual | |
32 | ' | |
33 | ||
34 | test_expect_success 'git ls-files --format objectname v.s. -s' ' | |
35 | git ls-files -s >files && | |
36 | cut -d" " -f2 files >expect && | |
37 | git ls-files --format="%(objectname)" >actual && | |
38 | test_cmp expect actual | |
39 | ' | |
40 | ||
4d28c4f7 ZH |
41 | test_expect_success 'git ls-files --format objecttype' ' |
42 | git ls-files --format="%(objectname)" o1.txt o4.txt o6.txt >objectname && | |
43 | git cat-file --batch-check="%(objecttype)" >expect <objectname && | |
44 | git ls-files --format="%(objecttype)" o1.txt o4.txt o6.txt >actual && | |
45 | test_cmp expect actual | |
46 | ' | |
47 | ||
48 | test_expect_success 'git ls-files --format objectsize' ' | |
49 | cat>expect <<-\EOF && | |
50 | 26 | |
51 | 29 | |
52 | 27 | |
53 | 26 | |
54 | - | |
55 | 26 | |
56 | EOF | |
57 | git ls-files --format="%(objectsize)" >actual && | |
58 | ||
59 | test_cmp expect actual | |
60 | ' | |
61 | ||
62 | test_expect_success 'git ls-files --format objectsize:padded' ' | |
63 | cat>expect <<-\EOF && | |
64 | 26 | |
65 | 29 | |
66 | 27 | |
67 | 26 | |
68 | - | |
69 | 26 | |
70 | EOF | |
71 | git ls-files --format="%(objectsize:padded)" >actual && | |
72 | ||
73 | test_cmp expect actual | |
74 | ' | |
75 | ||
ce74de93 ZH |
76 | test_expect_success 'git ls-files --format v.s. --eol' ' |
77 | git ls-files --eol >tmp && | |
78 | sed -e "s/ / /g" -e "s/ */ /g" tmp >expect 2>err && | |
79 | test_must_be_empty err && | |
80 | git ls-files --format="i/%(eolinfo:index) w/%(eolinfo:worktree) attr/%(eolattr) %(path)" >actual 2>err && | |
81 | test_must_be_empty err && | |
82 | test_cmp expect actual | |
83 | ' | |
84 | ||
85 | test_expect_success 'git ls-files --format path v.s. -s' ' | |
86 | git ls-files -s >files && | |
87 | cut -f2 files >expect && | |
88 | git ls-files --format="%(path)" >actual && | |
89 | test_cmp expect actual | |
90 | ' | |
91 | ||
cfb62dd0 AJ |
92 | test_expect_success 'git ls-files --format with relative path' ' |
93 | cat >expect <<-\EOF && | |
94 | ../o1.txt | |
95 | ../o2.txt | |
96 | ../o3.txt | |
97 | ../o4.txt | |
98 | ../o5.txt | |
99 | ../o6.txt | |
100 | EOF | |
101 | mkdir sub && | |
102 | cd sub && | |
103 | git ls-files --format="%(path)" ":/" >../actual && | |
104 | cd .. && | |
105 | test_cmp expect actual | |
106 | ' | |
107 | ||
ce74de93 ZH |
108 | test_expect_success 'git ls-files --format with -m' ' |
109 | echo change >o1.txt && | |
110 | cat >expect <<-\EOF && | |
111 | o1.txt | |
112 | o4.txt | |
113 | o5.txt | |
114 | o6.txt | |
115 | EOF | |
116 | git ls-files --format="%(path)" -m >actual && | |
117 | test_cmp expect actual | |
118 | ' | |
119 | ||
120 | test_expect_success 'git ls-files --format with -d' ' | |
121 | echo o7 >o7.txt && | |
122 | git add o7.txt && | |
123 | rm o7.txt && | |
124 | cat >expect <<-\EOF && | |
125 | o4.txt | |
126 | o5.txt | |
127 | o6.txt | |
128 | o7.txt | |
129 | EOF | |
130 | git ls-files --format="%(path)" -d >actual && | |
131 | test_cmp expect actual | |
132 | ' | |
133 | ||
134 | test_expect_success 'git ls-files --format v.s -s' ' | |
135 | git ls-files --stage >expect && | |
136 | git ls-files --format="%(objectmode) %(objectname) %(stage)%x09%(path)" >actual && | |
137 | test_cmp expect actual | |
138 | ' | |
139 | ||
140 | test_expect_success 'git ls-files --format with --debug' ' | |
141 | git ls-files --debug >expect && | |
142 | git ls-files --format="%(path)" --debug >actual && | |
143 | test_cmp expect actual | |
144 | ' | |
145 | ||
146 | test_done |