]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4056-diff-order.sh
Merge branch 'jc/diffcore-rotate'
[thirdparty/git.git] / t / t4056-diff-order.sh
CommitLineData
b5277730
SB
1#!/bin/sh
2
1eb4136a 3test_description='diff order & rotate'
b5277730 4
8f37854b 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
b5277730
SB
8. ./test-lib.sh
9
10create_files () {
11 echo "$1" >a.h &&
12 echo "$1" >b.c &&
13 echo "$1" >c/Makefile &&
14 echo "$1" >d.txt &&
15 git add a.h b.c c/Makefile d.txt &&
16 git commit -m"$1"
17}
18
19test_expect_success 'setup' '
20 mkdir c &&
21 create_files 1 &&
22 create_files 2 &&
23
24 cat >order_file_1 <<-\EOF &&
25 *Makefile
26 *.txt
27 *.h
28 EOF
29
30 cat >order_file_2 <<-\EOF &&
31 *Makefile
32 *.h
33 *.c
34 EOF
35
36 cat >expect_none <<-\EOF &&
37 a.h
38 b.c
39 c/Makefile
40 d.txt
41 EOF
42
43 cat >expect_1 <<-\EOF &&
44 c/Makefile
45 d.txt
46 a.h
47 b.c
48 EOF
49
50 cat >expect_2 <<-\EOF
51 c/Makefile
52 a.h
53 b.c
54 d.txt
55 EOF
56'
57
58test_expect_success "no order (=tree object order)" '
59 git diff --name-only HEAD^..HEAD >actual &&
60 test_cmp expect_none actual
61'
62
a21bae33
SB
63test_expect_success 'missing orderfile' '
64 rm -f bogus_file &&
65 test_must_fail git diff -Obogus_file --name-only HEAD^..HEAD
66'
67
68test_expect_success POSIXPERM,SANITY 'unreadable orderfile' '
69 >unreadable_file &&
70 chmod -r unreadable_file &&
71 test_must_fail git diff -Ounreadable_file --name-only HEAD^..HEAD
72'
73
a97262c6
NTND
74test_expect_success "orderfile using option from subdir with --output" '
75 mkdir subdir &&
76 git -C subdir diff -O../order_file_1 --output ../actual --name-only HEAD^..HEAD &&
77 test_cmp expect_1 actual
78'
79
b5277730
SB
80for i in 1 2
81do
82 test_expect_success "orderfile using option ($i)" '
83 git diff -Oorder_file_$i --name-only HEAD^..HEAD >actual &&
84 test_cmp expect_$i actual
85 '
a21bae33
SB
86
87 test_expect_success PIPE "orderfile is fifo ($i)" '
88 rm -f order_fifo &&
89 mkfifo order_fifo &&
90 {
91 cat order_file_$i >order_fifo &
92 } &&
93 git diff -O order_fifo --name-only HEAD^..HEAD >actual &&
94 wait &&
95 test_cmp expect_$i actual
96 '
6d8940b5
SB
97
98 test_expect_success "orderfile using config ($i)" '
99 git -c diff.orderfile=order_file_$i diff --name-only HEAD^..HEAD >actual &&
100 test_cmp expect_$i actual
101 '
102
103 test_expect_success "cancelling configured orderfile ($i)" '
104 git -c diff.orderfile=order_file_$i diff -O/dev/null --name-only HEAD^..HEAD >actual &&
105 test_cmp expect_none actual
106 '
b5277730
SB
107done
108
91921cef
KS
109test_expect_success 'setup for testing combine-diff order' '
110 git checkout -b tmp HEAD~ &&
111 create_files 3 &&
8f37854b 112 git checkout main &&
91921cef
KS
113 git merge --no-commit -s ours tmp &&
114 create_files 5
115'
116
117test_expect_success "combine-diff: no order (=tree object order)" '
118 git diff --name-only HEAD HEAD^ HEAD^2 >actual &&
119 test_cmp expect_none actual
120'
121
122for i in 1 2
123do
124 test_expect_success "combine-diff: orderfile using option ($i)" '
125 git diff -Oorder_file_$i --name-only HEAD HEAD^ HEAD^2 >actual &&
126 test_cmp expect_$i actual
127 '
128done
129
1eb4136a
JH
130### rotate and skip
131
132test_expect_success 'rotate and skip setup' '
133 >sample1.t &&
134 >sample2.t &&
135 >sample3.t &&
136 >sample4.t &&
137 git add sample[1234].t &&
138 git commit -m "added" sample[1234].t &&
139 echo modified >>sample1.t &&
140 echo modified >>sample2.t &&
141 echo modified >>sample4.t &&
142 git commit -m "updated" sample[1234].t
143'
144
145test_expect_success 'diff --rotate-to' '
146 git diff --rotate-to=sample2.t --name-only HEAD^ >actual &&
147 test_write_lines sample2.t sample4.t sample1.t >expect &&
148 test_cmp expect actual
149'
150
151test_expect_success 'diff --skip-to' '
152 git diff --skip-to=sample2.t --name-only HEAD^ >actual &&
153 test_write_lines sample2.t sample4.t >expect &&
154 test_cmp expect actual
155'
156
157test_expect_success 'diff --rotate/skip-to error condition' '
158 test_must_fail git diff --rotate-to=sample3.t HEAD^ &&
159 test_must_fail git diff --skip-to=sample3.t HEAD^
160'
161
162test_expect_success 'log --rotate-to' '
163 git log --rotate-to=sample3.t --raw HEAD~2.. >raw &&
164 # just distill the commit header and paths
165 sed -n -e "s/^commit.*/commit/p" \
166 -e "/^:/s/^.* //p" raw >actual &&
167
168 cat >expect <<-\EOF &&
169 commit
170 sample4.t
171 sample1.t
172 sample2.t
173 commit
174 sample3.t
175 sample4.t
176 sample1.t
177 sample2.t
178 EOF
179
180 test_cmp expect actual
181'
182
183test_expect_success 'log --skip-to' '
184 git log --skip-to=sample3.t --raw HEAD~2.. >raw &&
185 # just distill the commit header and paths
186 sed -n -e "s/^commit.*/commit/p" \
187 -e "/^:/s/^.* //p" raw >actual &&
188
189 cat >expect <<-\EOF &&
190 commit
191 sample4.t
192 commit
193 sample3.t
194 sample4.t
195 EOF
196
197 test_cmp expect actual
198'
199
b5277730 200test_done