Fourth batch
[git/raj.git] / t / t4211-line-log.sh
blobe186c8325043920cd4bfb79ab4fa2ce021dc7ac4
1 #!/bin/sh
3 test_description='test log -L'
4 . ./test-lib.sh
6 test_expect_success 'setup (import history)' '
7 test_oid_init &&
8 git fast-import < "$TEST_DIRECTORY"/t4211/history.export &&
9 git reset --hard
12 canned_test_1 () {
13 test_expect_$1 "$2" "
14 git log $2 >actual &&
15 test_cmp \"\$TEST_DIRECTORY\"/t4211/$(test_oid algo)/expect.$3 actual
19 canned_test () {
20 canned_test_1 success "$@"
22 canned_test_failure () {
23 canned_test_1 failure "$@"
26 test_bad_opts () {
27 test_expect_success "invalid args: $1" "
28 test_must_fail git log $1 2>errors &&
29 test_i18ngrep '$2' errors
33 canned_test "-L 4,12:a.c simple" simple-f
34 canned_test "-L 4,+9:a.c simple" simple-f
35 canned_test "-L '/long f/,/^}/:a.c' simple" simple-f
36 canned_test "-L :f:a.c simple" simple-f-to-main
38 canned_test "-L '/main/,/^}/:a.c' simple" simple-main
39 canned_test "-L :main:a.c simple" simple-main-to-end
41 canned_test "-L 1,+4:a.c simple" beginning-of-file
43 canned_test "-L 20:a.c simple" end-of-file
45 canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges
46 canned_test "-L 24,+1:a.c simple" vanishes-early
48 canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f
49 canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
51 canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
52 canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping
53 canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
54 canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
55 canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
57 test_bad_opts "-L" "switch.*requires a value"
58 test_bad_opts "-L b.c" "argument not .start,end:file"
59 test_bad_opts "-L 1:" "argument not .start,end:file"
60 test_bad_opts "-L 1:nonexistent" "There is no path"
61 test_bad_opts "-L 1:simple" "There is no path"
62 test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file"
63 test_bad_opts "-L 1000:b.c" "has only.*lines"
64 test_bad_opts "-L :b.c" "argument not .start,end:file"
65 test_bad_opts "-L :foo:b.c" "no match"
67 test_expect_success '-L X (X == nlines)' '
68 n=$(wc -l <b.c) &&
69 git log -L $n:b.c
72 test_expect_success '-L X (X == nlines + 1)' '
73 n=$(expr $(wc -l <b.c) + 1) &&
74 test_must_fail git log -L $n:b.c
77 test_expect_success '-L X (X == nlines + 2)' '
78 n=$(expr $(wc -l <b.c) + 2) &&
79 test_must_fail git log -L $n:b.c
82 test_expect_success '-L ,Y (Y == nlines)' '
83 n=$(printf "%d" $(wc -l <b.c)) &&
84 git log -L ,$n:b.c
87 test_expect_success '-L ,Y (Y == nlines + 1)' '
88 n=$(expr $(wc -l <b.c) + 1) &&
89 git log -L ,$n:b.c
92 test_expect_success '-L ,Y (Y == nlines + 2)' '
93 n=$(expr $(wc -l <b.c) + 2) &&
94 git log -L ,$n:b.c
97 test_expect_success '-L with --first-parent and a merge' '
98 git checkout parallel-change &&
99 git log --first-parent -L 1,1:b.c
102 test_expect_success '-L with --output' '
103 git checkout parallel-change &&
104 git log --output=log -L :main:b.c >output &&
105 test_must_be_empty output &&
106 test_line_count = 70 log
109 test_expect_success 'range_set_union' '
110 test_seq 500 > c.c &&
111 git add c.c &&
112 git commit -m "many lines" &&
113 test_seq 1000 > c.c &&
114 git add c.c &&
115 git commit -m "modify many lines" &&
116 git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done)
119 test_expect_success '-s shows only line-log commits' '
120 git log --format="commit %s" -L1,24:b.c >expect.raw &&
121 grep ^commit expect.raw >expect &&
122 git log --format="commit %s" -L1,24:b.c -s >actual &&
123 test_cmp expect actual
126 test_expect_success '-p shows the default patch output' '
127 git log -L1,24:b.c >expect &&
128 git log -L1,24:b.c -p >actual &&
129 test_cmp expect actual
132 test_expect_success '--raw is forbidden' '
133 test_must_fail git log -L1,24:b.c --raw
136 test_expect_success 'setup for checking fancy rename following' '
137 git checkout --orphan moves-start &&
138 git reset --hard &&
140 printf "%s\n" 12 13 14 15 b c d e >file-1 &&
141 printf "%s\n" 22 23 24 25 B C D E >file-2 &&
142 git add file-1 file-2 &&
143 test_tick &&
144 git commit -m "Add file-1 and file-2" &&
145 oid_add_f1_f2=$(git rev-parse --short HEAD) &&
147 git checkout -b moves-main &&
148 printf "%s\n" 11 12 13 14 15 b c d e >file-1 &&
149 git commit -a -m "Modify file-1 on main" &&
150 oid_mod_f1_main=$(git rev-parse --short HEAD) &&
152 printf "%s\n" 21 22 23 24 25 B C D E >file-2 &&
153 git commit -a -m "Modify file-2 on main #1" &&
154 oid_mod_f2_main_1=$(git rev-parse --short HEAD) &&
156 git mv file-1 renamed-1 &&
157 git commit -m "Rename file-1 to renamed-1 on main" &&
159 printf "%s\n" 11 12 13 14 15 b c d e f >renamed-1 &&
160 git commit -a -m "Modify renamed-1 on main" &&
161 oid_mod_r1_main=$(git rev-parse --short HEAD) &&
163 printf "%s\n" 21 22 23 24 25 B C D E F >file-2 &&
164 git commit -a -m "Modify file-2 on main #2" &&
165 oid_mod_f2_main_2=$(git rev-parse --short HEAD) &&
167 git checkout -b moves-side moves-start &&
168 printf "%s\n" 12 13 14 15 16 b c d e >file-1 &&
169 git commit -a -m "Modify file-1 on side #1" &&
170 oid_mod_f1_side_1=$(git rev-parse --short HEAD) &&
172 printf "%s\n" 22 23 24 25 26 B C D E >file-2 &&
173 git commit -a -m "Modify file-2 on side" &&
174 oid_mod_f2_side=$(git rev-parse --short HEAD) &&
176 git mv file-2 renamed-2 &&
177 git commit -m "Rename file-2 to renamed-2 on side" &&
179 printf "%s\n" 12 13 14 15 16 a b c d e >file-1 &&
180 git commit -a -m "Modify file-1 on side #2" &&
181 oid_mod_f1_side_2=$(git rev-parse --short HEAD) &&
183 printf "%s\n" 22 23 24 25 26 A B C D E >renamed-2 &&
184 git commit -a -m "Modify renamed-2 on side" &&
185 oid_mod_r2_side=$(git rev-parse --short HEAD) &&
187 git checkout moves-main &&
188 git merge moves-side &&
189 oid_merge=$(git rev-parse --short HEAD)
192 test_expect_success 'fancy rename following #1' '
193 cat >expect <<-EOF &&
194 $oid_merge Merge branch '\''moves-side'\'' into moves-main
195 $oid_mod_f1_side_2 Modify file-1 on side #2
196 $oid_mod_f1_side_1 Modify file-1 on side #1
197 $oid_mod_r1_main Modify renamed-1 on main
198 $oid_mod_f1_main Modify file-1 on main
199 $oid_add_f1_f2 Add file-1 and file-2
201 git log -L1:renamed-1 --oneline --no-patch >actual &&
202 test_cmp expect actual
205 test_expect_success 'fancy rename following #2' '
206 cat >expect <<-EOF &&
207 $oid_merge Merge branch '\''moves-side'\'' into moves-main
208 $oid_mod_r2_side Modify renamed-2 on side
209 $oid_mod_f2_side Modify file-2 on side
210 $oid_mod_f2_main_2 Modify file-2 on main #2
211 $oid_mod_f2_main_1 Modify file-2 on main #1
212 $oid_add_f1_f2 Add file-1 and file-2
214 git log -L1:renamed-2 --oneline --no-patch >actual &&
215 test_cmp expect actual
218 # Create the following linear history, where each commit does what its
219 # subject line promises:
221 # * 66c6410 Modify func2() in file.c
222 # * 50834e5 Modify other-file
223 # * fe5851c Modify func1() in file.c
224 # * 8c7c7dd Add other-file
225 # * d5f4417 Add func1() and func2() in file.c
226 test_expect_success 'setup for checking line-log and parent oids' '
227 git checkout --orphan parent-oids &&
228 git reset --hard &&
230 cat >file.c <<-\EOF &&
231 int func1()
233 return F1;
236 int func2()
238 return F2;
241 git add file.c &&
242 test_tick &&
243 first_tick=$test_tick &&
244 git commit -m "Add func1() and func2() in file.c" &&
246 echo 1 >other-file &&
247 git add other-file &&
248 test_tick &&
249 git commit -m "Add other-file" &&
251 sed -e "s/F1/F1 + 1/" file.c >tmp &&
252 mv tmp file.c &&
253 git commit -a -m "Modify func1() in file.c" &&
255 echo 2 >other-file &&
256 git commit -a -m "Modify other-file" &&
258 sed -e "s/F2/F2 + 2/" file.c >tmp &&
259 mv tmp file.c &&
260 git commit -a -m "Modify func2() in file.c" &&
262 head_oid=$(git rev-parse --short HEAD) &&
263 prev_oid=$(git rev-parse --short HEAD^) &&
264 root_oid=$(git rev-parse --short HEAD~4)
267 # Parent oid should be from immediate parent.
268 test_expect_success 'parent oids without parent rewriting' '
269 cat >expect <<-EOF &&
270 $head_oid $prev_oid Modify func2() in file.c
271 $root_oid Add func1() and func2() in file.c
273 git log --format="%h %p %s" --no-patch -L:func2:file.c >actual &&
274 test_cmp expect actual
277 # Parent oid should be from the most recent ancestor touching func2(),
278 # i.e. in this case from the root commit.
279 test_expect_success 'parent oids with parent rewriting' '
280 cat >expect <<-EOF &&
281 $head_oid $root_oid Modify func2() in file.c
282 $root_oid Add func1() and func2() in file.c
284 git log --format="%h %p %s" --no-patch -L:func2:file.c --parents >actual &&
285 test_cmp expect actual
288 test_expect_success 'line-log with --before' '
289 echo $root_oid >expect &&
290 git log --format=%h --no-patch -L:func2:file.c --before=$first_tick >actual &&
291 test_cmp expect actual
294 test_done