negative-refspec: fix segfault on : refspec
[git] / t / t4068-diff-symmetric.sh
1 #!/bin/sh
2
3 test_description='behavior of diff with symmetric-diff setups'
4
5 . ./test-lib.sh
6
7 # build these situations:
8 #  - normal merge with one merge base (br1...b2r);
9 #  - criss-cross merge ie 2 merge bases (br1...master);
10 #  - disjoint subgraph (orphan branch, br3...master).
11 #
12 #     B---E   <-- master
13 #    / \ /
14 #   A   X
15 #    \ / \
16 #     C---D--G   <-- br1
17 #      \    /
18 #       ---F   <-- br2
19 #
20 #  H  <-- br3
21 #
22 # We put files into a few commits so that we can verify the
23 # output as well.
24
25 test_expect_success setup '
26         git commit --allow-empty -m A &&
27         echo b >b &&
28         git add b &&
29         git commit -m B &&
30         git checkout -b br1 HEAD^ &&
31         echo c >c &&
32         git add c &&
33         git commit -m C &&
34         git tag commit-C &&
35         git merge -m D master &&
36         git tag commit-D &&
37         git checkout master &&
38         git merge -m E commit-C &&
39         git checkout -b br2 commit-C &&
40         echo f >f &&
41         git add f &&
42         git commit -m F &&
43         git checkout br1 &&
44         git merge -m G br2 &&
45         git checkout --orphan br3 &&
46         git commit -m H
47 '
48
49 test_expect_success 'diff with one merge base' '
50         git diff commit-D...br1 >tmp &&
51         tail -n 1 tmp >actual &&
52         echo +f >expect &&
53         test_cmp expect actual
54 '
55
56 # The output (in tmp) can have +b or +c depending
57 # on which merge base (commit B or C) is picked.
58 # It should have one of those two, which comes out
59 # to seven lines.
60 test_expect_success 'diff with two merge bases' '
61         git diff br1...master >tmp 2>err &&
62         test_line_count = 7 tmp &&
63         test_line_count = 1 err
64 '
65
66 test_expect_success 'diff with no merge bases' '
67         test_must_fail git diff br2...br3 >tmp 2>err &&
68         test_i18ngrep "fatal: br2...br3: no merge base" err
69 '
70
71 test_expect_success 'diff with too many symmetric differences' '
72         test_must_fail git diff br1...master br2...br3 >tmp 2>err &&
73         test_i18ngrep "usage" err
74 '
75
76 test_expect_success 'diff with symmetric difference and extraneous arg' '
77         test_must_fail git diff master br1...master >tmp 2>err &&
78         test_i18ngrep "usage" err
79 '
80
81 test_expect_success 'diff with two ranges' '
82         test_must_fail git diff master br1..master br2..br3 >tmp 2>err &&
83         test_i18ngrep "usage" err
84 '
85
86 test_expect_success 'diff with ranges and extra arg' '
87         test_must_fail git diff master br1..master commit-D >tmp 2>err &&
88         test_i18ngrep "usage" err
89 '
90
91 test_done