summaryrefslogtreecommitdiffstats
path: root/t/t3013-ls-files-format.sh
blob: 6e6ea0b6f3ca256eb3903b08ca7025e3508ecb0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh

test_description='git ls-files --format test'

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

for flag in -s -o -k -t --resolve-undo --deduplicate --eol
do
	test_expect_success "usage: --format is incompatible with $flag" '
		test_expect_code 129 git ls-files --format="%(objectname)" $flag
	'
done

test_expect_success 'setup' '
	printf "LINEONE\nLINETWO\nLINETHREE\n" >o1.txt &&
	printf "LINEONE\r\nLINETWO\r\nLINETHREE\r\n" >o2.txt &&
	printf "LINEONE\r\nLINETWO\nLINETHREE\n" >o3.txt &&
	git add o?.txt &&
	oid=$(git hash-object o1.txt) &&
	git update-index --add --cacheinfo 120000 $oid o4.txt &&
	git update-index --add --cacheinfo 160000 $oid o5.txt &&
	git update-index --add --cacheinfo 100755 $oid o6.txt &&
	git commit -m base
'

test_expect_success 'git ls-files --format objectmode v.s. -s' '
	git ls-files -s >files &&
	cut -d" " -f1 files >expect &&
	git ls-files --format="%(objectmode)" >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format objectname v.s. -s' '
	git ls-files -s >files &&
	cut -d" " -f2 files >expect &&
	git ls-files --format="%(objectname)" >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format objecttype' '
	git ls-files --format="%(objectname)" o1.txt o4.txt o6.txt >objectname &&
	git cat-file --batch-check="%(objecttype)" >expect <objectname &&
	git ls-files --format="%(objecttype)" o1.txt o4.txt o6.txt >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format objectsize' '
	cat>expect <<-\EOF &&
26
29
27
26
-
26
	EOF
	git ls-files --format="%(objectsize)" >actual &&

	test_cmp expect actual
'

test_expect_success 'git ls-files --format objectsize:padded' '
	cat>expect <<-\EOF &&
     26
     29
     27
     26
      -
     26
	EOF
	git ls-files --format="%(objectsize:padded)" >actual &&

	test_cmp expect actual
'

test_expect_success 'git ls-files --format v.s. --eol' '
	git ls-files --eol >tmp &&
	sed -e "s/	/ /g" -e "s/  */ /g" tmp >expect 2>err &&
	test_must_be_empty err &&
	git ls-files --format="i/%(eolinfo:index) w/%(eolinfo:worktree) attr/%(eolattr) %(path)" >actual 2>err &&
	test_must_be_empty err &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format path v.s. -s' '
	git ls-files -s >files &&
	cut -f2 files >expect &&
	git ls-files --format="%(path)" >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format with relative path' '
	cat >expect <<-\EOF &&
	../o1.txt
	../o2.txt
	../o3.txt
	../o4.txt
	../o5.txt
	../o6.txt
	EOF
	mkdir sub &&
	cd sub &&
	git ls-files --format="%(path)" ":/" >../actual &&
	cd .. &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format with -m' '
	echo change >o1.txt &&
	cat >expect <<-\EOF &&
	o1.txt
	o4.txt
	o5.txt
	o6.txt
	EOF
	git ls-files --format="%(path)" -m >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format with -d' '
	echo o7 >o7.txt &&
	git add o7.txt &&
	rm o7.txt &&
	cat >expect <<-\EOF &&
	o4.txt
	o5.txt
	o6.txt
	o7.txt
	EOF
	git ls-files --format="%(path)" -d >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format v.s -s' '
	git ls-files --stage >expect &&
	git ls-files --format="%(objectmode) %(objectname) %(stage)%x09%(path)" >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files --format with --debug' '
	git ls-files --debug >expect &&
	git ls-files --format="%(path)" --debug >actual &&
	test_cmp expect actual
'

test_done