Sync with 'master'
[alt-git.git] / t / t4056-diff-order.sh
blob32c5fcb9a27c2e0156ec5db3adadc038468f2ee4
1 #!/bin/sh
3 test_description='diff order & rotate'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 create_files () {
12 echo "$1" >a.h &&
13 echo "$1" >b.c &&
14 echo "$1" >c/Makefile &&
15 echo "$1" >d.txt &&
16 git add a.h b.c c/Makefile d.txt &&
17 git commit -m"$1"
20 test_expect_success 'setup' '
21 mkdir c &&
22 create_files 1 &&
23 create_files 2 &&
25 cat >order_file_1 <<-\EOF &&
26 *Makefile
27 *.txt
28 *.h
29 EOF
31 cat >order_file_2 <<-\EOF &&
32 *Makefile
33 *.h
34 *.c
35 EOF
37 cat >expect_none <<-\EOF &&
38 a.h
39 b.c
40 c/Makefile
41 d.txt
42 EOF
44 cat >expect_1 <<-\EOF &&
45 c/Makefile
46 d.txt
47 a.h
48 b.c
49 EOF
51 cat >expect_2 <<-\EOF
52 c/Makefile
53 a.h
54 b.c
55 d.txt
56 EOF
59 test_expect_success "no order (=tree object order)" '
60 git diff --name-only HEAD^..HEAD >actual &&
61 test_cmp expect_none actual
64 test_expect_success 'missing orderfile' '
65 rm -f bogus_file &&
66 test_must_fail git diff -Obogus_file --name-only HEAD^..HEAD
69 test_expect_success POSIXPERM,SANITY 'unreadable orderfile' '
70 >unreadable_file &&
71 chmod -r unreadable_file &&
72 test_must_fail git diff -Ounreadable_file --name-only HEAD^..HEAD
75 test_expect_success "orderfile using option from subdir with --output" '
76 mkdir subdir &&
77 git -C subdir diff -O../order_file_1 --output ../actual --name-only HEAD^..HEAD &&
78 test_cmp expect_1 actual
81 for i in 1 2
83 test_expect_success "orderfile using option ($i)" '
84 git diff -Oorder_file_$i --name-only HEAD^..HEAD >actual &&
85 test_cmp expect_$i actual
88 test_expect_success PIPE "orderfile is fifo ($i)" '
89 rm -f order_fifo &&
90 mkfifo order_fifo &&
92 cat order_file_$i >order_fifo &
93 } &&
94 git diff -O order_fifo --name-only HEAD^..HEAD >actual &&
95 wait &&
96 test_cmp expect_$i actual
99 test_expect_success "orderfile using config ($i)" '
100 git -c diff.orderfile=order_file_$i diff --name-only HEAD^..HEAD >actual &&
101 test_cmp expect_$i actual
104 test_expect_success "cancelling configured orderfile ($i)" '
105 git -c diff.orderfile=order_file_$i diff -O/dev/null --name-only HEAD^..HEAD >actual &&
106 test_cmp expect_none actual
108 done
110 test_expect_success 'setup for testing combine-diff order' '
111 git checkout -b tmp HEAD~ &&
112 create_files 3 &&
113 git checkout main &&
114 git merge --no-commit -s ours tmp &&
115 create_files 5
118 test_expect_success "combine-diff: no order (=tree object order)" '
119 git diff --name-only HEAD HEAD^ HEAD^2 >actual &&
120 test_cmp expect_none actual
123 for i in 1 2
125 test_expect_success "combine-diff: orderfile using option ($i)" '
126 git diff -Oorder_file_$i --name-only HEAD HEAD^ HEAD^2 >actual &&
127 test_cmp expect_$i actual
129 done
131 ### rotate and skip
133 test_expect_success 'rotate and skip setup' '
134 >sample1.t &&
135 >sample2.t &&
136 >sample3.t &&
137 >sample4.t &&
138 git add sample[1234].t &&
139 git commit -m "added" sample[1234].t &&
140 echo modified >>sample1.t &&
141 echo modified >>sample2.t &&
142 echo modified >>sample4.t &&
143 git commit -m "updated" sample[1234].t
146 test_expect_success 'diff --rotate-to' '
147 git diff --rotate-to=sample2.t --name-only HEAD^ >actual &&
148 test_write_lines sample2.t sample4.t sample1.t >expect &&
149 test_cmp expect actual
152 test_expect_success 'diff --skip-to' '
153 git diff --skip-to=sample2.t --name-only HEAD^ >actual &&
154 test_write_lines sample2.t sample4.t >expect &&
155 test_cmp expect actual
158 test_expect_success 'diff --rotate/skip-to error condition' '
159 test_must_fail git diff --rotate-to=sample3.t HEAD^ &&
160 test_must_fail git diff --skip-to=sample3.t HEAD^
163 test_expect_success 'log --rotate-to' '
164 git log --rotate-to=sample3.t --raw HEAD~2.. >raw &&
165 # just distill the commit header and paths
166 sed -n -e "s/^commit.*/commit/p" \
167 -e "/^:/s/^.* //p" raw >actual &&
169 cat >expect <<-\EOF &&
170 commit
171 sample4.t
172 sample1.t
173 sample2.t
174 commit
175 sample3.t
176 sample4.t
177 sample1.t
178 sample2.t
181 test_cmp expect actual
184 test_expect_success 'log --skip-to' '
185 git log --skip-to=sample3.t --raw HEAD~2.. >raw &&
186 # just distill the commit header and paths
187 sed -n -e "s/^commit.*/commit/p" \
188 -e "/^:/s/^.* //p" raw >actual &&
190 cat >expect <<-\EOF &&
191 commit
192 sample4.t
193 commit
194 sample3.t
195 sample4.t
198 test_cmp expect actual
201 test_done