reflog: fix expire --single-worktree
[git/gitster.git] / t / t3013-ls-files-format.sh
blob6e6ea0b6f3ca256eb3903b08ca7025e3508ecb0b
1 #!/bin/sh
3 test_description='git ls-files --format test'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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
13 done
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
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
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
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
48 test_expect_success 'git ls-files --format objectsize' '
49 cat>expect <<-\EOF &&
56 EOF
57 git ls-files --format="%(objectsize)" >actual &&
59 test_cmp expect actual
62 test_expect_success 'git ls-files --format objectsize:padded' '
63 cat>expect <<-\EOF &&
70 EOF
71 git ls-files --format="%(objectsize:padded)" >actual &&
73 test_cmp expect actual
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
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
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
101 mkdir sub &&
102 cd sub &&
103 git ls-files --format="%(path)" ":/" >../actual &&
104 cd .. &&
105 test_cmp expect actual
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
116 git ls-files --format="%(path)" -m >actual &&
117 test_cmp expect actual
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
130 git ls-files --format="%(path)" -d >actual &&
131 test_cmp expect actual
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
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
146 test_done