View Javadoc
1   /*
2    * Copyright (C) 2011, Christian Halstrick <christian.halstrick@sap.com>
3    * Copyright (C) 2011, Philipp Thun <philipp.thun@sap.com>
4    * and other copyright owners as documented in the project's IP log.
5    *
6    * This program and the accompanying materials are made available
7    * under the terms of the Eclipse Distribution License v1.0 which
8    * accompanies this distribution, is reproduced below, and is
9    * available at http://www.eclipse.org/org/documents/edl-v10.php
10   *
11   * All rights reserved.
12   *
13   * Redistribution and use in source and binary forms, with or
14   * without modification, are permitted provided that the following
15   * conditions are met:
16   *
17   * - Redistributions of source code must retain the above copyright
18   *   notice, this list of conditions and the following disclaimer.
19   *
20   * - Redistributions in binary form must reproduce the above
21   *   copyright notice, this list of conditions and the following
22   *   disclaimer in the documentation and/or other materials provided
23   *   with the distribution.
24   *
25   * - Neither the name of the Eclipse Foundation, Inc. nor the
26   *   names of its contributors may be used to endorse or promote
27   *   products derived from this software without specific prior
28   *   written permission.
29   *
30   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
31   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
32   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
39   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
42   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43   */
44  package org.eclipse.jgit.api;
45  
46  import static java.nio.charset.StandardCharsets.UTF_8;
47  import static org.junit.Assert.assertEquals;
48  import static org.junit.Assert.assertNotNull;
49  import static org.junit.Assert.assertTrue;
50  
51  import java.io.File;
52  import java.io.IOException;
53  
54  import org.eclipse.jgit.api.errors.JGitInternalException;
55  import org.eclipse.jgit.junit.RepositoryTestCase;
56  import org.eclipse.jgit.lib.Constants;
57  import org.eclipse.jgit.lib.ObjectId;
58  import org.eclipse.jgit.lib.Repository;
59  import org.eclipse.jgit.revwalk.RevWalk;
60  import org.eclipse.jgit.treewalk.TreeWalk;
61  import org.junit.Test;
62  
63  /**
64   * Testing the 'commit only' option:
65   *
66   * I. A single file (f1.txt) specified as part of the --only/ -o option can have
67   * one of the following (14) states:
68   *
69   * <pre>
70   *        |                          | expected result
71   * ---------------------------------------------------------------------
72   *        | HEAD  DirCache  Worktree | HEAD  DirCache
73   * ---------------------------------------------------------------------
74   *  f1_1  |  -       -       c       |                =&gt; e: path unknown
75   *  f1_2  |  -       c       -       |                =&gt; no changes
76   *  f1_3  |  c       -       -       |  -       -
77   *  f1_4  |  -       c       c       |  c       c
78   *  f1_5  |  c       c       -       |  -       -
79   *  f1_6  |  c       -       c       |                =&gt; no changes
80   *  f1_7  |  c       c       c       |                =&gt; no changes
81   * ---------------------------------------------------------------------
82   *  f1_8  |  -       c       c'      |  c'      c'
83   *  f1_9  |  c       -       c'      |  c'      c'
84   * f1_10  |  c       c'      -       |  -       -
85   * f1_11  |  c       c       c'      |  c'      c'
86   * f1_12  |  c       c'      c       |                =&gt; no changes
87   * f1_13  |  c       c'      c'      |  c'      c'
88   * ---------------------------------------------------------------------
89   * f1_14  |  c       c'      c''     |  c''     c''
90   * </pre>
91   *
92   * II. Scenarios that do not end with a successful commit (1, 2, 6, 7, 12) have
93   * to be tested with a second file (f2.txt) specified that would lead to a
94   * successful commit, if it were executed separately (e.g. scenario 14).
95   *
96   * <pre>
97   *              |                          | expected result
98   * ---------------------------------------------------------------------------
99   *              | HEAD  DirCache  Worktree | HEAD  DirCache
100  * ---------------------------------------------------------------------------
101  *  f1_1_f2_14  |  -       -       c       |                =&gt; e: path unknown
102  *  f1_2_f2_14  |  -       c       -       |  -       -
103  *  f1_6_f2_14  |  c       -       c       |  c       c
104  *  f1_7_f2_14  |  c       c       c       |  c       c
105  * ---------------------------------------------------------------------------
106  * f1_12_f2_14  |  c       c'      c       |  c       c
107  * </pre>
108  *
109  * III. All scenarios (1-14, I-II) have to be tested with different repository
110  * states, to check that the --only/ -o option does not change existing content
111  * (HEAD and DirCache). The following states for a file (f3.txt) not specified
112  * shall be tested:
113  *
114  * <pre>
115  *       | HEAD  DirCache
116  * --------------------
117  *  *_a  |  -       -
118  *  *_b  |  -       c
119  *  *_c  |  c       c
120  *  *_d  |  c       -
121  * --------------------
122  *  *_e  |  c       c'
123  * </pre>
124  **/
125 public class CommitOnlyTest extends RepositoryTestCase {
126 	private static final String F1 = "f1.txt";
127 
128 	private static final String F2 = "f2.txt";
129 
130 	private static final String F3 = "f3.txt";
131 
132 	private static final String MSG = "commit";
133 
134 	private static int A = 0;
135 
136 	private static int B = 1;
137 
138 	private static int C = 2;
139 
140 	private static int D = 3;
141 
142 	private static int E = 4;
143 
144 	@Test
145 	public void testOnlyOption_f1_1_a() throws Exception {
146 		final Git git = new Git(db);
147 		prepare_f3(git, A);
148 		prepare_f1_1(git);
149 		executeAndCheck_f1_1(git, A);
150 	}
151 
152 	@Test
153 	public void testOnlyOption_f1_1_b() throws Exception {
154 		final Git git = new Git(db);
155 		prepare_f3(git, B);
156 		prepare_f1_1(git);
157 		executeAndCheck_f1_1(git, B);
158 	}
159 
160 	@Test
161 	public void testOnlyOption_f1_1_c() throws Exception {
162 		final Git git = new Git(db);
163 		prepare_f3(git, C);
164 		prepare_f1_1(git);
165 		executeAndCheck_f1_1(git, C);
166 	}
167 
168 	@Test
169 	public void testOnlyOption_f1_1_d() throws Exception {
170 		final Git git = new Git(db);
171 		prepare_f3(git, D);
172 		prepare_f1_1(git);
173 		executeAndCheck_f1_1(git, D);
174 	}
175 
176 	@Test
177 	public void testOnlyOption_f1_1_e() throws Exception {
178 		final Git git = new Git(db);
179 		prepare_f3(git, E);
180 		prepare_f1_1(git);
181 		executeAndCheck_f1_1(git, E);
182 	}
183 
184 	@Test
185 	public void testOnlyOption_f1_1_f2_14_a() throws Exception {
186 		final Git git = new Git(db);
187 		prepare_f3_f2_14(git, A);
188 		prepare_f1_1(git);
189 		executeAndCheck_f1_1_f2_f14(git, A);
190 	}
191 
192 	@Test
193 	public void testOnlyOption_f1_1_f2_14_b() throws Exception {
194 		final Git git = new Git(db);
195 		prepare_f3_f2_14(git, B);
196 		prepare_f1_1(git);
197 		executeAndCheck_f1_1_f2_f14(git, B);
198 	}
199 
200 	@Test
201 	public void testOnlyOption_f1_1_f2_14_c() throws Exception {
202 		final Git git = new Git(db);
203 		prepare_f3_f2_14(git, C);
204 		prepare_f1_1(git);
205 		executeAndCheck_f1_1_f2_f14(git, C);
206 	}
207 
208 	@Test
209 	public void testOnlyOption_f1_1_f2_14_d() throws Exception {
210 		final Git git = new Git(db);
211 		prepare_f3_f2_14(git, D);
212 		prepare_f1_1(git);
213 		executeAndCheck_f1_1_f2_f14(git, D);
214 	}
215 
216 	@Test
217 	public void testOnlyOption_f1_1_f2_14_e() throws Exception {
218 		final Git git = new Git(db);
219 		prepare_f3_f2_14(git, E);
220 		prepare_f1_1(git);
221 		executeAndCheck_f1_1_f2_f14(git, E);
222 	}
223 
224 	@Test
225 	public void testOnlyOption_f1_2_a() throws Exception {
226 		final Git git = new Git(db);
227 		prepare_f3(git, A);
228 		prepare_f1_2(git);
229 		executeAndCheck_f1_2(git, A);
230 	}
231 
232 	@Test
233 	public void testOnlyOption_f1_2_b() throws Exception {
234 		final Git git = new Git(db);
235 		prepare_f3(git, B);
236 		prepare_f1_2(git);
237 		executeAndCheck_f1_2(git, B);
238 	}
239 
240 	@Test
241 	public void testOnlyOption_f1_2_c() throws Exception {
242 		final Git git = new Git(db);
243 		prepare_f3(git, C);
244 		prepare_f1_2(git);
245 		executeAndCheck_f1_2(git, C);
246 	}
247 
248 	@Test
249 	public void testOnlyOption_f1_2_d() throws Exception {
250 		final Git git = new Git(db);
251 		prepare_f3(git, D);
252 		prepare_f1_2(git);
253 		executeAndCheck_f1_2(git, D);
254 	}
255 
256 	@Test
257 	public void testOnlyOption_f1_2_e() throws Exception {
258 		final Git git = new Git(db);
259 		prepare_f3(git, E);
260 		prepare_f1_2(git);
261 		executeAndCheck_f1_2(git, E);
262 	}
263 
264 	@Test
265 	public void testOnlyOption_f1_2_f2_14_a() throws Exception {
266 		final Git git = new Git(db);
267 		prepare_f3_f2_14(git, A);
268 		prepare_f1_2(git);
269 		executeAndCheck_f1_2_f2_f14(git, A);
270 	}
271 
272 	@Test
273 	public void testOnlyOption_f1_2_f2_14_b() throws Exception {
274 		final Git git = new Git(db);
275 		prepare_f3_f2_14(git, B);
276 		prepare_f1_2(git);
277 		executeAndCheck_f1_2_f2_f14(git, B);
278 	}
279 
280 	@Test
281 	public void testOnlyOption_f1_2_f2_14_c() throws Exception {
282 		final Git git = new Git(db);
283 		prepare_f3_f2_14(git, C);
284 		prepare_f1_2(git);
285 		executeAndCheck_f1_2_f2_f14(git, C);
286 	}
287 
288 	@Test
289 	public void testOnlyOption_f1_2_f2_14_d() throws Exception {
290 		final Git git = new Git(db);
291 		prepare_f3_f2_14(git, D);
292 		prepare_f1_2(git);
293 		executeAndCheck_f1_2_f2_f14(git, D);
294 	}
295 
296 	@Test
297 	public void testOnlyOption_f1_2_f2_14_e() throws Exception {
298 		final Git git = new Git(db);
299 		prepare_f3_f2_14(git, E);
300 		prepare_f1_2(git);
301 		executeAndCheck_f1_2_f2_f14(git, E);
302 	}
303 
304 	@Test
305 	public void testOnlyOption_f1_3_a() throws Exception {
306 		final Git git = new Git(db);
307 		prepare_f3(git, A);
308 		prepare_f1_3(git);
309 		executeAndCheck_f1_3(git, A);
310 	}
311 
312 	@Test
313 	public void testOnlyOption_f1_3_b() throws Exception {
314 		final Git git = new Git(db);
315 		prepare_f3(git, B);
316 		prepare_f1_3(git);
317 		executeAndCheck_f1_3(git, B);
318 	}
319 
320 	@Test
321 	public void testOnlyOption_f1_3_c() throws Exception {
322 		final Git git = new Git(db);
323 		prepare_f3(git, C);
324 		prepare_f1_3(git);
325 		executeAndCheck_f1_3(git, C);
326 	}
327 
328 	@Test
329 	public void testOnlyOption_f1_3_d() throws Exception {
330 		final Git git = new Git(db);
331 		prepare_f3(git, D);
332 		prepare_f1_3(git);
333 		executeAndCheck_f1_3(git, D);
334 	}
335 
336 	@Test
337 	public void testOnlyOption_f1_3_e() throws Exception {
338 		final Git git = new Git(db);
339 		prepare_f3(git, E);
340 		prepare_f1_3(git);
341 		executeAndCheck_f1_3(git, E);
342 	}
343 
344 	@Test
345 	public void testOnlyOption_f1_4_a() throws Exception {
346 		final Git git = new Git(db);
347 		prepare_f3(git, A);
348 		prepare_f1_4(git);
349 		executeAndCheck_f1_4(git, A);
350 	}
351 
352 	@Test
353 	public void testOnlyOption_f1_4_b() throws Exception {
354 		final Git git = new Git(db);
355 		prepare_f3(git, B);
356 		prepare_f1_4(git);
357 		executeAndCheck_f1_4(git, B);
358 	}
359 
360 	@Test
361 	public void testOnlyOption_f1_4_c() throws Exception {
362 		final Git git = new Git(db);
363 		prepare_f3(git, C);
364 		prepare_f1_4(git);
365 		executeAndCheck_f1_4(git, C);
366 	}
367 
368 	@Test
369 	public void testOnlyOption_f1_4_d() throws Exception {
370 		final Git git = new Git(db);
371 		prepare_f3(git, D);
372 		prepare_f1_4(git);
373 		executeAndCheck_f1_4(git, D);
374 	}
375 
376 	@Test
377 	public void testOnlyOption_f1_4_e() throws Exception {
378 		final Git git = new Git(db);
379 		prepare_f3(git, E);
380 		prepare_f1_4(git);
381 		executeAndCheck_f1_4(git, E);
382 	}
383 
384 	@Test
385 	public void testOnlyOption_f1_5_a() throws Exception {
386 		final Git git = new Git(db);
387 		prepare_f3(git, A);
388 		prepare_f1_5(git);
389 		executeAndCheck_f1_5(git, A);
390 	}
391 
392 	@Test
393 	public void testOnlyOption_f1_5_b() throws Exception {
394 		final Git git = new Git(db);
395 		prepare_f3(git, B);
396 		prepare_f1_5(git);
397 		executeAndCheck_f1_5(git, B);
398 	}
399 
400 	@Test
401 	public void testOnlyOption_f1_5_c() throws Exception {
402 		final Git git = new Git(db);
403 		prepare_f3(git, C);
404 		prepare_f1_5(git);
405 		executeAndCheck_f1_5(git, C);
406 	}
407 
408 	@Test
409 	public void testOnlyOption_f1_5_d() throws Exception {
410 		final Git git = new Git(db);
411 		prepare_f3(git, D);
412 		prepare_f1_5(git);
413 		executeAndCheck_f1_5(git, D);
414 	}
415 
416 	@Test
417 	public void testOnlyOption_f1_5_e() throws Exception {
418 		final Git git = new Git(db);
419 		prepare_f3(git, E);
420 		prepare_f1_5(git);
421 		executeAndCheck_f1_5(git, E);
422 	}
423 
424 	@Test
425 	public void testOnlyOption_f1_6_a() throws Exception {
426 		final Git git = new Git(db);
427 		prepare_f3(git, A);
428 		prepare_f1_6(git);
429 		executeAndCheck_f1_6(git, A);
430 	}
431 
432 	@Test
433 	public void testOnlyOption_f1_6_b() throws Exception {
434 		final Git git = new Git(db);
435 		prepare_f3(git, B);
436 		prepare_f1_6(git);
437 		executeAndCheck_f1_6(git, B);
438 	}
439 
440 	@Test
441 	public void testOnlyOption_f1_6_c() throws Exception {
442 		final Git git = new Git(db);
443 		prepare_f3(git, C);
444 		prepare_f1_6(git);
445 		executeAndCheck_f1_6(git, C);
446 	}
447 
448 	@Test
449 	public void testOnlyOption_f1_6_d() throws Exception {
450 		final Git git = new Git(db);
451 		prepare_f3(git, D);
452 		prepare_f1_6(git);
453 		executeAndCheck_f1_6(git, D);
454 	}
455 
456 	@Test
457 	public void testOnlyOption_f1_6_e() throws Exception {
458 		final Git git = new Git(db);
459 		prepare_f3(git, E);
460 		prepare_f1_6(git);
461 		executeAndCheck_f1_6(git, E);
462 	}
463 
464 	@Test
465 	public void testOnlyOption_f1_6_f2_14_a() throws Exception {
466 		final Git git = new Git(db);
467 		prepare_f3_f2_14(git, A);
468 		prepare_f1_6(git);
469 		executeAndCheck_f1_6_f2_14(git, A);
470 	}
471 
472 	@Test
473 	public void testOnlyOption_f1_6_f2_14_b() throws Exception {
474 		final Git git = new Git(db);
475 		prepare_f3_f2_14(git, B);
476 		prepare_f1_6(git);
477 		executeAndCheck_f1_6_f2_14(git, B);
478 	}
479 
480 	@Test
481 	public void testOnlyOption_f1_6_f2_14_c() throws Exception {
482 		final Git git = new Git(db);
483 		prepare_f3_f2_14(git, C);
484 		prepare_f1_6(git);
485 		executeAndCheck_f1_6_f2_14(git, C);
486 	}
487 
488 	@Test
489 	public void testOnlyOption_f1_6_f2_14_d() throws Exception {
490 		final Git git = new Git(db);
491 		prepare_f3_f2_14(git, D);
492 		prepare_f1_6(git);
493 		executeAndCheck_f1_6_f2_14(git, D);
494 	}
495 
496 	@Test
497 	public void testOnlyOption_f1_6_f2_14_e() throws Exception {
498 		final Git git = new Git(db);
499 		prepare_f3_f2_14(git, E);
500 		prepare_f1_6(git);
501 		executeAndCheck_f1_6_f2_14(git, E);
502 	}
503 
504 	@Test
505 	public void testOnlyOption_f1_7_a() throws Exception {
506 		final Git git = new Git(db);
507 		prepare_f3(git, A);
508 		prepare_f1_7(git);
509 		executeAndCheck_f1_7(git, A);
510 	}
511 
512 	@Test
513 	public void testOnlyOption_f1_7_b() throws Exception {
514 		final Git git = new Git(db);
515 		prepare_f3(git, B);
516 		prepare_f1_7(git);
517 		executeAndCheck_f1_7(git, B);
518 	}
519 
520 	@Test
521 	public void testOnlyOption_f1_7_c() throws Exception {
522 		final Git git = new Git(db);
523 		prepare_f3(git, C);
524 		prepare_f1_7(git);
525 		executeAndCheck_f1_7(git, C);
526 	}
527 
528 	@Test
529 	public void testOnlyOption_f1_7_d() throws Exception {
530 		final Git git = new Git(db);
531 		prepare_f3(git, D);
532 		prepare_f1_7(git);
533 		executeAndCheck_f1_7(git, D);
534 	}
535 
536 	@Test
537 	public void testOnlyOption_f1_7_e() throws Exception {
538 		final Git git = new Git(db);
539 		prepare_f3(git, E);
540 		prepare_f1_7(git);
541 		executeAndCheck_f1_7(git, E);
542 	}
543 
544 	@Test
545 	public void testOnlyOption_f1_7_f2_14_a() throws Exception {
546 		final Git git = new Git(db);
547 		prepare_f3_f2_14(git, A);
548 		prepare_f1_7(git);
549 		executeAndCheck_f1_7_f2_14(git, A);
550 	}
551 
552 	@Test
553 	public void testOnlyOption_f1_7_f2_14_b() throws Exception {
554 		final Git git = new Git(db);
555 		prepare_f3_f2_14(git, B);
556 		prepare_f1_7(git);
557 		executeAndCheck_f1_7_f2_14(git, B);
558 	}
559 
560 	@Test
561 	public void testOnlyOption_f1_7_f2_14_c() throws Exception {
562 		final Git git = new Git(db);
563 		prepare_f3_f2_14(git, C);
564 		prepare_f1_7(git);
565 		executeAndCheck_f1_7_f2_14(git, C);
566 	}
567 
568 	@Test
569 	public void testOnlyOption_f1_7_f2_14_d() throws Exception {
570 		final Git git = new Git(db);
571 		prepare_f3_f2_14(git, D);
572 		prepare_f1_7(git);
573 		executeAndCheck_f1_7_f2_14(git, D);
574 	}
575 
576 	@Test
577 	public void testOnlyOption_f1_7_f2_14_e() throws Exception {
578 		final Git git = new Git(db);
579 		prepare_f3_f2_14(git, E);
580 		prepare_f1_7(git);
581 		executeAndCheck_f1_7_f2_14(git, E);
582 	}
583 
584 	@Test
585 	public void testOnlyOption_f1_8_a() throws Exception {
586 		final Git git = new Git(db);
587 		prepare_f3(git, A);
588 		prepare_f1_8(git);
589 		executeAndCheck_f1_8(git, A);
590 	}
591 
592 	@Test
593 	public void testOnlyOption_f1_8_b() throws Exception {
594 		final Git git = new Git(db);
595 		prepare_f3(git, B);
596 		prepare_f1_8(git);
597 		executeAndCheck_f1_8(git, B);
598 	}
599 
600 	@Test
601 	public void testOnlyOption_f1_8_c() throws Exception {
602 		final Git git = new Git(db);
603 		prepare_f3(git, C);
604 		prepare_f1_8(git);
605 		executeAndCheck_f1_8(git, C);
606 	}
607 
608 	@Test
609 	public void testOnlyOption_f1_8_d() throws Exception {
610 		final Git git = new Git(db);
611 		prepare_f3(git, D);
612 		prepare_f1_8(git);
613 		executeAndCheck_f1_8(git, D);
614 	}
615 
616 	@Test
617 	public void testOnlyOption_f1_8_e() throws Exception {
618 		final Git git = new Git(db);
619 		prepare_f3(git, E);
620 		prepare_f1_8(git);
621 		executeAndCheck_f1_8(git, E);
622 	}
623 
624 	@Test
625 	public void testOnlyOption_f1_9_a() throws Exception {
626 		final Git git = new Git(db);
627 		prepare_f3(git, A);
628 		prepare_f1_9(git);
629 		executeAndCheck_f1_9(git, A);
630 	}
631 
632 	@Test
633 	public void testOnlyOption_f1_9_b() throws Exception {
634 		final Git git = new Git(db);
635 		prepare_f3(git, B);
636 		prepare_f1_9(git);
637 		executeAndCheck_f1_9(git, B);
638 	}
639 
640 	@Test
641 	public void testOnlyOption_f1_9_c() throws Exception {
642 		final Git git = new Git(db);
643 		prepare_f3(git, C);
644 		prepare_f1_9(git);
645 		executeAndCheck_f1_9(git, C);
646 	}
647 
648 	@Test
649 	public void testOnlyOption_f1_9_d() throws Exception {
650 		final Git git = new Git(db);
651 		prepare_f3(git, D);
652 		prepare_f1_9(git);
653 		executeAndCheck_f1_9(git, D);
654 	}
655 
656 	@Test
657 	public void testOnlyOption_f1_9_e() throws Exception {
658 		final Git git = new Git(db);
659 		prepare_f3(git, E);
660 		prepare_f1_9(git);
661 		executeAndCheck_f1_9(git, E);
662 	}
663 
664 	@Test
665 	public void testOnlyOption_f1_10_a() throws Exception {
666 		final Git git = new Git(db);
667 		prepare_f3(git, A);
668 		prepare_f1_10(git);
669 		executeAndCheck_f1_10(git, A);
670 	}
671 
672 	@Test
673 	public void testOnlyOption_f1_10_b() throws Exception {
674 		final Git git = new Git(db);
675 		prepare_f3(git, B);
676 		prepare_f1_10(git);
677 		executeAndCheck_f1_10(git, B);
678 	}
679 
680 	@Test
681 	public void testOnlyOption_f1_10_c() throws Exception {
682 		final Git git = new Git(db);
683 		prepare_f3(git, C);
684 		prepare_f1_10(git);
685 		executeAndCheck_f1_10(git, C);
686 	}
687 
688 	@Test
689 	public void testOnlyOption_f1_10_d() throws Exception {
690 		final Git git = new Git(db);
691 		prepare_f3(git, D);
692 		prepare_f1_10(git);
693 		executeAndCheck_f1_10(git, D);
694 	}
695 
696 	@Test
697 	public void testOnlyOption_f1_10_e() throws Exception {
698 		final Git git = new Git(db);
699 		prepare_f3(git, E);
700 		prepare_f1_10(git);
701 		executeAndCheck_f1_10(git, E);
702 	}
703 
704 	@Test
705 	public void testOnlyOption_f1_11_a() throws Exception {
706 		final Git git = new Git(db);
707 		prepare_f3(git, A);
708 		prepare_f1_11(git);
709 		executeAndCheck_f1_11(git, A);
710 	}
711 
712 	@Test
713 	public void testOnlyOption_f1_11_b() throws Exception {
714 		final Git git = new Git(db);
715 		prepare_f3(git, B);
716 		prepare_f1_11(git);
717 		executeAndCheck_f1_11(git, B);
718 	}
719 
720 	@Test
721 	public void testOnlyOption_f1_11_c() throws Exception {
722 		final Git git = new Git(db);
723 		prepare_f3(git, C);
724 		prepare_f1_11(git);
725 		executeAndCheck_f1_11(git, C);
726 	}
727 
728 	@Test
729 	public void testOnlyOption_f1_11_d() throws Exception {
730 		final Git git = new Git(db);
731 		prepare_f3(git, D);
732 		prepare_f1_11(git);
733 		executeAndCheck_f1_11(git, D);
734 	}
735 
736 	@Test
737 	public void testOnlyOption_f1_11_e() throws Exception {
738 		final Git git = new Git(db);
739 		prepare_f3(git, E);
740 		prepare_f1_11(git);
741 		executeAndCheck_f1_11(git, E);
742 	}
743 
744 	@Test
745 	public void testOnlyOption_f1_12_a() throws Exception {
746 		final Git git = new Git(db);
747 		prepare_f3(git, A);
748 		prepare_f1_12(git);
749 		executeAndCheck_f1_12(git, A);
750 	}
751 
752 	@Test
753 	public void testOnlyOption_f1_12_b() throws Exception {
754 		final Git git = new Git(db);
755 		prepare_f3(git, B);
756 		prepare_f1_12(git);
757 		executeAndCheck_f1_12(git, B);
758 	}
759 
760 	@Test
761 	public void testOnlyOption_f1_12_c() throws Exception {
762 		final Git git = new Git(db);
763 		prepare_f3(git, C);
764 		prepare_f1_12(git);
765 		executeAndCheck_f1_12(git, C);
766 	}
767 
768 	@Test
769 	public void testOnlyOption_f1_12_d() throws Exception {
770 		final Git git = new Git(db);
771 		prepare_f3(git, D);
772 		prepare_f1_12(git);
773 		executeAndCheck_f1_12(git, D);
774 	}
775 
776 	@Test
777 	public void testOnlyOption_f1_12_e() throws Exception {
778 		final Git git = new Git(db);
779 		prepare_f3(git, E);
780 		prepare_f1_12(git);
781 		executeAndCheck_f1_12(git, E);
782 	}
783 
784 	@Test
785 	public void testOnlyOption_f1_12_f2_14_a() throws Exception {
786 		final Git git = new Git(db);
787 		prepare_f3_f2_14(git, A);
788 		prepare_f1_12(git);
789 		executeAndCheck_f1_12_f2_14(git, A);
790 	}
791 
792 	@Test
793 	public void testOnlyOption_f1_12_f2_14_b() throws Exception {
794 		final Git git = new Git(db);
795 		prepare_f3_f2_14(git, B);
796 		prepare_f1_12(git);
797 		executeAndCheck_f1_12_f2_14(git, B);
798 	}
799 
800 	@Test
801 	public void testOnlyOption_f1_12_f2_14_c() throws Exception {
802 		final Git git = new Git(db);
803 		prepare_f3_f2_14(git, C);
804 		prepare_f1_12(git);
805 		executeAndCheck_f1_12_f2_14(git, C);
806 	}
807 
808 	@Test
809 	public void testOnlyOption_f1_12_f2_14_d() throws Exception {
810 		final Git git = new Git(db);
811 		prepare_f3_f2_14(git, D);
812 		prepare_f1_12(git);
813 		executeAndCheck_f1_12_f2_14(git, D);
814 	}
815 
816 	@Test
817 	public void testOnlyOption_f1_12_f2_14_e() throws Exception {
818 		final Git git = new Git(db);
819 		prepare_f3_f2_14(git, E);
820 		prepare_f1_12(git);
821 		executeAndCheck_f1_12_f2_14(git, E);
822 	}
823 
824 	@Test
825 	public void testOnlyOption_f1_13_a() throws Exception {
826 		final Git git = new Git(db);
827 		prepare_f3(git, A);
828 		prepare_f1_13(git);
829 		executeAndCheck_f1_13(git, A);
830 	}
831 
832 	@Test
833 	public void testOnlyOption_f1_13_b() throws Exception {
834 		final Git git = new Git(db);
835 		prepare_f3(git, B);
836 		prepare_f1_13(git);
837 		executeAndCheck_f1_13(git, B);
838 	}
839 
840 	@Test
841 	public void testOnlyOption_f1_13_c() throws Exception {
842 		final Git git = new Git(db);
843 		prepare_f3(git, C);
844 		prepare_f1_13(git);
845 		executeAndCheck_f1_13(git, C);
846 	}
847 
848 	@Test
849 	public void testOnlyOption_f1_13_d() throws Exception {
850 		final Git git = new Git(db);
851 		prepare_f3(git, D);
852 		prepare_f1_13(git);
853 		executeAndCheck_f1_13(git, D);
854 	}
855 
856 	@Test
857 	public void testOnlyOption_f1_13_e() throws Exception {
858 		final Git git = new Git(db);
859 		prepare_f3(git, E);
860 		prepare_f1_13(git);
861 		executeAndCheck_f1_13(git, E);
862 	}
863 
864 	@Test
865 	public void testOnlyOption_f1_14_a() throws Exception {
866 		final Git git = new Git(db);
867 		prepare_f3(git, A);
868 		prepare_f1_14(git);
869 		executeAndCheck_f1_14(git, A);
870 	}
871 
872 	@Test
873 	public void testOnlyOption_f1_14_b() throws Exception {
874 		final Git git = new Git(db);
875 		prepare_f3(git, B);
876 		prepare_f1_14(git);
877 		executeAndCheck_f1_14(git, B);
878 	}
879 
880 	@Test
881 	public void testOnlyOption_f1_14_c() throws Exception {
882 		final Git git = new Git(db);
883 		prepare_f3(git, C);
884 		prepare_f1_14(git);
885 		executeAndCheck_f1_14(git, C);
886 	}
887 
888 	@Test
889 	public void testOnlyOption_f1_14_d() throws Exception {
890 		final Git git = new Git(db);
891 		prepare_f3(git, D);
892 		prepare_f1_14(git);
893 		executeAndCheck_f1_14(git, D);
894 	}
895 
896 	@Test
897 	public void testOnlyOption_f1_14_e() throws Exception {
898 		final Git git = new Git(db);
899 		prepare_f3(git, E);
900 		prepare_f1_14(git);
901 		executeAndCheck_f1_14(git, E);
902 	}
903 
904 	@Test
905 	public void testOnlyOptionWithDirectory() throws Exception {
906 		final Git git = new Git(db);
907 
908 		// write files
909 		final File f1 = writeTrashFile("d1/d2/f1.txt", "c1");
910 		writeTrashFile("d1/d2/f2.txt", "c2");
911 		final File f3 = writeTrashFile("d1/f3.txt", "c3");
912 		writeTrashFile("d1/f4.txt", "c4");
913 		final File f5 = writeTrashFile("d3/d4/f5.txt", "c5");
914 		writeTrashFile("d3/d4/f6.txt", "c6");
915 		final File f7 = writeTrashFile("d3/f7.txt", "c7");
916 		writeTrashFile("d3/f8.txt", "c8");
917 		final File f9 = writeTrashFile("d5/f9.txt", "c9");
918 		writeTrashFile("d5/f10.txt", "c10");
919 		final File f11 = writeTrashFile("d6/f11.txt", "c11");
920 		writeTrashFile("d6/f12.txt", "c12");
921 
922 		// add files
923 		git.add().addFilepattern(".").call();
924 
925 		// modify files, but do not stage changes
926 		write(f1, "c1'");
927 		write(f3, "c3'");
928 		write(f5, "c5'");
929 		write(f7, "c7'");
930 		write(f9, "c9'");
931 		write(f11, "c11'");
932 
933 		// commit selected files only
934 		git.commit().setOnly("d1").setOnly("d3/d4/").setOnly("d5")
935 				.setOnly("d6/f11.txt").setMessage(MSG).call();
936 
937 		assertEquals("c1'", getHead(git, "d1/d2/f1.txt"));
938 		assertEquals("c2", getHead(git, "d1/d2/f2.txt"));
939 		assertEquals("c3'", getHead(git, "d1/f3.txt"));
940 		assertEquals("c4", getHead(git, "d1/f4.txt"));
941 		assertEquals("c5'", getHead(git, "d3/d4/f5.txt"));
942 		assertEquals("c6", getHead(git, "d3/d4/f6.txt"));
943 		assertEquals("", getHead(git, "d3/f7.txt"));
944 		assertEquals("", getHead(git, "d3/f8.txt"));
945 		assertEquals("c9'", getHead(git, "d5/f9.txt"));
946 		assertEquals("c10", getHead(git, "d5/f10.txt"));
947 		assertEquals("c11'", getHead(git, "d6/f11.txt"));
948 		assertEquals("", getHead(git, "d6/f12.txt"));
949 		assertEquals("[d1/d2/f1.txt, mode:100644, content:c1']"
950 				+ "[d1/d2/f2.txt, mode:100644, content:c2]"
951 				+ "[d1/f3.txt, mode:100644, content:c3']"
952 				+ "[d1/f4.txt, mode:100644, content:c4]"
953 				+ "[d3/d4/f5.txt, mode:100644, content:c5']"
954 				+ "[d3/d4/f6.txt, mode:100644, content:c6]"
955 				+ "[d3/f7.txt, mode:100644, content:c7]"
956 				+ "[d3/f8.txt, mode:100644, content:c8]"
957 				+ "[d5/f10.txt, mode:100644, content:c10]"
958 				+ "[d5/f9.txt, mode:100644, content:c9']"
959 				+ "[d6/f11.txt, mode:100644, content:c11']"
960 				+ "[d6/f12.txt, mode:100644, content:c12]", indexState(CONTENT));
961 	}
962 
963 	@SuppressWarnings("unused")
964 	private File prepare_f1_1(final Git git) throws IOException {
965 		return writeTrashFile(F1, "c1");
966 	}
967 
968 	private File prepare_f1_2(final Git git) throws Exception {
969 		final File f1 = prepare_f1_4(git);
970 		f1.delete();
971 		return f1;
972 	}
973 
974 	private File prepare_f1_3(final Git git) throws Exception {
975 		final File f1 = prepare_f1_7(git);
976 		git.rm().addFilepattern(F1).call();
977 		return f1;
978 	}
979 
980 	private File prepare_f1_4(final Git git) throws Exception {
981 		final File f1 = prepare_f1_1(git);
982 		git.add().addFilepattern(F1).call();
983 		return f1;
984 	}
985 
986 	private File prepare_f1_5(final Git git) throws Exception {
987 		final File f1 = prepare_f1_7(git);
988 		f1.delete();
989 		return f1;
990 	}
991 
992 	private File prepare_f1_6(final Git git) throws Exception {
993 		final File f1 = prepare_f1_3(git);
994 		write(f1, "c1");
995 		return f1;
996 	}
997 
998 	private File prepare_f1_7(final Git git) throws Exception {
999 		final File f1 = prepare_f1_4(git);
1000 		git.commit().setOnly(F1).setMessage(MSG).call();
1001 		return f1;
1002 	}
1003 
1004 	private File prepare_f1_8(final Git git) throws Exception {
1005 		final File f1 = prepare_f1_4(git);
1006 		write(f1, "c1'");
1007 		return f1;
1008 	}
1009 
1010 	private File prepare_f1_9(final Git git) throws Exception {
1011 		final File f1 = prepare_f1_3(git);
1012 		write(f1, "c1'");
1013 		return f1;
1014 	}
1015 
1016 	private File prepare_f1_10(final Git git) throws Exception {
1017 		final File f1 = prepare_f1_9(git);
1018 		git.add().addFilepattern(F1).call();
1019 		f1.delete();
1020 		return f1;
1021 	}
1022 
1023 	private File prepare_f1_11(final Git git) throws Exception {
1024 		final File f1 = prepare_f1_7(git);
1025 		write(f1, "c1'");
1026 		return f1;
1027 	}
1028 
1029 	private File prepare_f1_12(final Git git) throws Exception {
1030 		final File f1 = prepare_f1_13(git);
1031 		write(f1, "c1");
1032 		return f1;
1033 	}
1034 
1035 	private File prepare_f1_13(final Git git) throws Exception {
1036 		final File f1 = prepare_f1_11(git);
1037 		git.add().addFilepattern(F1).call();
1038 		return f1;
1039 	}
1040 
1041 	private File prepare_f1_14(final Git git) throws Exception {
1042 		final File f1 = prepare_f1_13(git);
1043 		write(f1, "c1''");
1044 		return f1;
1045 	}
1046 
1047 	private void executeAndCheck_f1_1(final Git git, final int state)
1048 			throws Exception {
1049 		JGitInternalException exception = null;
1050 		try {
1051 			git.commit().setOnly(F1).setMessage(MSG).call();
1052 		} catch (JGitInternalException e) {
1053 			exception = e;
1054 		}
1055 		assertNotNull(exception);
1056 		assertTrue(exception.getMessage().contains(F1));
1057 
1058 		assertEquals(expected_f3_head(state), getHead(git, F3));
1059 		assertEquals(expected_f3_idx(state), indexState(CONTENT));
1060 	}
1061 
1062 	private void executeAndCheck_f1_1_f2_f14(final Git git, final int state)
1063 			throws Exception {
1064 		JGitInternalException exception = null;
1065 		try {
1066 			git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
1067 		} catch (JGitInternalException e) {
1068 			exception = e;
1069 		}
1070 		assertNotNull(exception);
1071 		assertTrue(exception.getMessage().contains(F1));
1072 
1073 		assertEquals("c2", getHead(git, F2));
1074 		assertEquals(expected_f3_head(state), getHead(git, F3));
1075 		assertEquals("[f2.txt, mode:100644, content:c2']"
1076 				+ expected_f3_idx(state), indexState(CONTENT));
1077 	}
1078 
1079 	private void executeAndCheck_f1_2(final Git git, final int state)
1080 			throws Exception {
1081 		JGitInternalException exception = null;
1082 		try {
1083 			git.commit().setOnly(F1).setMessage(MSG).call();
1084 		} catch (JGitInternalException e) {
1085 			exception = e;
1086 		}
1087 		assertNotNull(exception);
1088 		assertTrue(exception.getMessage().contains("No changes"));
1089 
1090 		assertEquals(expected_f3_head(state), getHead(git, F3));
1091 		assertEquals("[f1.txt, mode:100644, content:c1]"
1092 				+ expected_f3_idx(state), indexState(CONTENT));
1093 	}
1094 
1095 	private void executeAndCheck_f1_2_f2_f14(final Git git, final int state)
1096 			throws Exception {
1097 		git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
1098 
1099 		assertEquals("", getHead(git, F1));
1100 		assertEquals("c2''", getHead(git, F2));
1101 		assertEquals(expected_f3_head(state), getHead(git, F3));
1102 		assertEquals("[f2.txt, mode:100644, content:c2'']"
1103 				+ expected_f3_idx(state), indexState(CONTENT));
1104 	}
1105 
1106 	private void executeAndCheck_f1_3(final Git git, final int state)
1107 			throws Exception {
1108 		git.commit().setOnly(F1).setMessage(MSG).call();
1109 
1110 		assertEquals("", getHead(git, F1));
1111 		assertEquals(expected_f3_head(state), getHead(git, F3));
1112 		assertEquals(expected_f3_idx(state), indexState(CONTENT));
1113 	}
1114 
1115 	private void executeAndCheck_f1_4(final Git git, final int state)
1116 			throws Exception {
1117 		git.commit().setOnly(F1).setMessage(MSG).call();
1118 
1119 		assertEquals("c1", getHead(git, F1));
1120 		assertEquals(expected_f3_head(state), getHead(git, F3));
1121 		assertEquals("[f1.txt, mode:100644, content:c1]"
1122 				+ expected_f3_idx(state), indexState(CONTENT));
1123 	}
1124 
1125 	private void executeAndCheck_f1_5(final Git git, final int state)
1126 			throws Exception {
1127 		executeAndCheck_f1_3(git, state);
1128 	}
1129 
1130 	private void executeAndCheck_f1_6(final Git git, final int state)
1131 			throws Exception {
1132 		JGitInternalException exception = null;
1133 		try {
1134 			git.commit().setOnly(F1).setMessage(MSG).call();
1135 		} catch (JGitInternalException e) {
1136 			exception = e;
1137 		}
1138 		assertNotNull(exception);
1139 		assertTrue(exception.getMessage().contains("No changes"));
1140 
1141 		assertEquals(expected_f3_head(state), getHead(git, F3));
1142 		assertEquals(expected_f3_idx(state), indexState(CONTENT));
1143 	}
1144 
1145 	private void executeAndCheck_f1_6_f2_14(final Git git, final int state)
1146 			throws Exception {
1147 		git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
1148 
1149 		assertEquals("c1", getHead(git, F1));
1150 		assertEquals("c2''", getHead(git, F2));
1151 		assertEquals(expected_f3_head(state), getHead(git, F3));
1152 		assertEquals("[f1.txt, mode:100644, content:c1]"
1153 				+ "[f2.txt, mode:100644, content:c2'']"
1154 				+ expected_f3_idx(state), indexState(CONTENT));
1155 	}
1156 
1157 	private void executeAndCheck_f1_7(final Git git, final int state)
1158 			throws Exception {
1159 		executeAndCheck_f1_2(git, state);
1160 	}
1161 
1162 	private void executeAndCheck_f1_7_f2_14(final Git git, final int state)
1163 			throws Exception {
1164 		executeAndCheck_f1_6_f2_14(git, state);
1165 	}
1166 
1167 	private void executeAndCheck_f1_8(final Git git, final int state)
1168 			throws Exception {
1169 		git.commit().setOnly(F1).setMessage(MSG).call();
1170 
1171 		assertEquals("c1'", getHead(git, F1));
1172 		assertEquals(expected_f3_head(state), getHead(git, F3));
1173 		assertEquals("[f1.txt, mode:100644, content:c1']"
1174 				+ expected_f3_idx(state), indexState(CONTENT));
1175 	}
1176 
1177 	private void executeAndCheck_f1_9(final Git git, final int state)
1178 			throws Exception {
1179 		executeAndCheck_f1_8(git, state);
1180 	}
1181 
1182 	private void executeAndCheck_f1_10(final Git git, final int state)
1183 			throws Exception {
1184 		executeAndCheck_f1_3(git, state);
1185 	}
1186 
1187 	private void executeAndCheck_f1_11(final Git git, final int state)
1188 			throws Exception {
1189 		executeAndCheck_f1_8(git, state);
1190 	}
1191 
1192 	private void executeAndCheck_f1_12(final Git git, final int state)
1193 			throws Exception {
1194 		JGitInternalException exception = null;
1195 		try {
1196 			git.commit().setOnly(F1).setMessage(MSG).call();
1197 		} catch (JGitInternalException e) {
1198 			exception = e;
1199 		}
1200 		assertNotNull(exception);
1201 		assertTrue(exception.getMessage().contains("No changes"));
1202 
1203 		assertEquals(expected_f3_head(state), getHead(git, F3));
1204 		assertEquals("[f1.txt, mode:100644, content:c1']"
1205 				+ expected_f3_idx(state), indexState(CONTENT));
1206 	}
1207 
1208 	private void executeAndCheck_f1_12_f2_14(final Git git, final int state)
1209 			throws Exception {
1210 		executeAndCheck_f1_6_f2_14(git, state);
1211 	}
1212 
1213 	private void executeAndCheck_f1_13(final Git git, final int state)
1214 			throws Exception {
1215 		executeAndCheck_f1_8(git, state);
1216 	}
1217 
1218 	private void executeAndCheck_f1_14(final Git git, final int state)
1219 			throws Exception {
1220 		git.commit().setOnly(F1).setMessage(MSG).call();
1221 
1222 		assertEquals("c1''", getHead(git, F1));
1223 		assertEquals(expected_f3_head(state), getHead(git, F3));
1224 		assertEquals("[f1.txt, mode:100644, content:c1'']"
1225 				+ expected_f3_idx(state), indexState(CONTENT));
1226 	}
1227 
1228 	private void prepare_f3(final Git git, final int state) throws Exception {
1229 		prepare_f3_f2_14(git, state, false);
1230 	}
1231 
1232 	private void prepare_f3_f2_14(final Git git, final int state)
1233 			throws Exception {
1234 		prepare_f3_f2_14(git, state, true);
1235 	}
1236 
1237 	private void prepare_f3_f2_14(final Git git, final int state,
1238 			final boolean include_f2) throws Exception {
1239 		File f2 = null;
1240 		if (include_f2) {
1241 			f2 = writeTrashFile(F2, "c2");
1242 			git.add().addFilepattern(F2).call();
1243 			git.commit().setMessage(MSG).call();
1244 		}
1245 
1246 		if (state >= 1) {
1247 			writeTrashFile(F3, "c3");
1248 			git.add().addFilepattern(F3).call();
1249 		}
1250 		if (state >= 2)
1251 			git.commit().setMessage(MSG).call();
1252 		if (state >= 3)
1253 			git.rm().addFilepattern(F3).call();
1254 		if (state == 4) {
1255 			writeTrashFile(F3, "c3'");
1256 			git.add().addFilepattern(F3).call();
1257 		}
1258 
1259 		if (include_f2) {
1260 			write(f2, "c2'");
1261 			git.add().addFilepattern(F2).call();
1262 			write(f2, "c2''");
1263 		}
1264 	}
1265 
1266 	private static String expected_f3_head(final int state) {
1267 		switch (state) {
1268 		case 0:
1269 		case 1:
1270 			return "";
1271 		case 2:
1272 		case 3:
1273 		case 4:
1274 			return "c3";
1275 		}
1276 		return null;
1277 	}
1278 
1279 	private static String expected_f3_idx(final int state) {
1280 		switch (state) {
1281 		case 0:
1282 		case 3:
1283 			return "";
1284 		case 1:
1285 		case 2:
1286 			return "[f3.txt, mode:100644, content:c3]";
1287 		case 4:
1288 			return "[f3.txt, mode:100644, content:c3']";
1289 		}
1290 		return null;
1291 	}
1292 
1293 	static private String getHead(Git git, String path)
1294 			throws Exception {
1295 		try {
1296 			final Repository repo = git.getRepository();
1297 			final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
1298 			if (headId == null) {
1299 				return "";
1300 			}
1301 			try (RevWalk rw = new RevWalk(repo)) {
1302 				final TreeWalk tw = TreeWalk.forPath(repo, path,
1303 						rw.parseTree(headId));
1304 				if (tw == null) {
1305 					return "";
1306 				}
1307 				return new String(tw.getObjectReader().open(tw.getObjectId(0))
1308 						.getBytes(), UTF_8);
1309 			}
1310 		} catch (Exception e) {
1311 			return "";
1312 		}
1313 	}
1314 }