|
1 | 1 | #! /bin/sh |
2 | 2 |
|
3 | | -# This should be executed in a clean working copy of the test repo. |
4 | | - |
5 | | -set -e |
6 | | -set -x |
| 3 | +set -ex |
7 | 4 |
|
8 | 5 | BASE="$(dirname "$(cd $(dirname "$0") && pwd)")" |
9 | | -TMP="$BASE/t/tmp/main" |
| 6 | +. "$BASE/t/test-lib.sh" |
| 7 | + |
10 | 8 | GIT_IMERGE="git-imerge" |
11 | 9 |
|
12 | | -cd "$TMP" |
13 | | - |
14 | | -# Clean up detritus from possible previous runs of this test: |
15 | | -git checkout master |
16 | | -"$GIT_IMERGE" remove --name=c-d || true |
17 | | -for b in c-d-merge \ |
18 | | - c-d-rebase c-d-rebase-with-history \ |
19 | | - c-d-border c-d-border-with-history c-d-border-with-history2 \ |
20 | | - c-d-full |
21 | | -do |
22 | | - git branch -D $b || true |
23 | | -done |
24 | | - |
25 | | -git checkout c |
26 | | -"$GIT_IMERGE" init --name=c-d d |
27 | | -"$GIT_IMERGE" list |
28 | | -"$GIT_IMERGE" diagram --commits --frontier --html=imerge0.html |
29 | | -"$GIT_IMERGE" autofill 2>&1 | tee autofill.out |
30 | | -if grep -q Traceback autofill.out |
31 | | -then |
32 | | - exit 1 |
33 | | -fi |
34 | | -"$GIT_IMERGE" diagram --commits --frontier --html=imerge1.html |
35 | | -"$GIT_IMERGE" continue --edit |
36 | | -echo 'cd version' >conflict.txt |
37 | | -git add conflict.txt |
38 | | -"$GIT_IMERGE" continue --no-edit |
39 | | -"$GIT_IMERGE" diagram --commits --frontier --html=imerge2.html |
40 | | -GIT_EDITOR=cat "$GIT_IMERGE" simplify --goal=merge --branch=c-d-merge |
41 | | -"$GIT_IMERGE" simplify --goal=rebase --branch=c-d-rebase |
42 | | -"$GIT_IMERGE" simplify --goal=rebase-with-history --branch=c-d-rebase-with-history |
43 | | -"$GIT_IMERGE" simplify --goal=border --branch=c-d-border |
44 | | -"$GIT_IMERGE" simplify --goal=border-with-history --branch=c-d-border-with-history |
45 | | -"$GIT_IMERGE" simplify --goal=border-with-history2 --branch=c-d-border-with-history2 |
46 | | -"$GIT_IMERGE" remove |
47 | | - |
48 | | -git checkout c |
49 | | -"$GIT_IMERGE" start --goal=full --first-parent --name=c-d d 2>&1 | tee start.out |
50 | | -if grep -q Traceback start.out |
51 | | -then |
52 | | - exit 1 |
53 | | -fi |
54 | | -"$GIT_IMERGE" diagram --commits --frontier --html=imerge3.html |
55 | | -echo 'cd version' >conflict.txt |
56 | | -git add conflict.txt |
57 | | -GIT_EDITOR=cat git commit |
58 | | -"$GIT_IMERGE" continue --edit |
59 | | -"$GIT_IMERGE" diagram --commits --frontier --html=imerge4.html |
60 | | -"$GIT_IMERGE" finish --branch=c-d-full |
| 10 | +EXPECTED_TREE=ffa191c987a8d3f597376744a95439fa1b4a55c5 |
| 11 | + |
| 12 | +test_conflict () { |
| 13 | + local conflict=$1 |
| 14 | + |
| 15 | + TMP="$BASE/t/tmp/conflicted-$conflict" |
| 16 | + DESCRIPTION="git-imerge test repository with conflict at $conflict" |
| 17 | + |
| 18 | + # Set up a test repo with two branches, `c` and `d`, that each have a |
| 19 | + # commit making incompatible changes to the same file `conflict.txt`: |
| 20 | + init_test_repo "$TMP" "$DESCRIPTION" |
| 21 | + cd "$TMP" |
| 22 | + |
| 23 | + modify c.txt 0 |
| 24 | + modify d.txt 0 |
| 25 | + modify conflict.txt "original version" |
| 26 | + commit -m 'm⇒0' |
| 27 | + |
| 28 | + git checkout -b c master -- |
| 29 | + |
| 30 | + for i in $(seq 9) |
| 31 | + do |
| 32 | + modify c.txt $i |
| 33 | + |
| 34 | + # Is this the commit that should conflict? |
| 35 | + case $conflict in |
| 36 | + $i-*) modify conflict.txt "c version" ;; |
| 37 | + esac |
| 38 | + |
| 39 | + commit -m "c⇒$i" |
| 40 | + done |
| 41 | + |
| 42 | + git checkout -b d master -- |
| 43 | + |
| 44 | + for i in $(seq 6) |
| 45 | + do |
| 46 | + modify d.txt $i |
| 47 | + |
| 48 | + # Is this the commit that should conflict? |
| 49 | + case $conflict in |
| 50 | + *-$i) modify conflict.txt "d version" ;; |
| 51 | + esac |
| 52 | + |
| 53 | + commit -m "d⇒$i" |
| 54 | + done |
| 55 | + |
| 56 | + git checkout c |
| 57 | + "$GIT_IMERGE" init --name=c-d d |
| 58 | + "$GIT_IMERGE" list |
| 59 | + "$GIT_IMERGE" diagram --commits --frontier --html=imerge0.html |
| 60 | + "$GIT_IMERGE" autofill 2>&1 | tee autofill.out |
| 61 | + if grep -q Traceback autofill.out |
| 62 | + then |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + if ! grep -q "suggest manual merge of $conflict" autofill.out |
| 67 | + then |
| 68 | + echo "conflict not detected" |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + |
| 72 | + "$GIT_IMERGE" diagram --commits --frontier --html=imerge1.html |
| 73 | + "$GIT_IMERGE" continue --edit |
| 74 | + echo 'merged version' >conflict.txt |
| 75 | + git add conflict.txt |
| 76 | + "$GIT_IMERGE" continue --no-edit |
| 77 | + "$GIT_IMERGE" diagram --commits --frontier --html=imerge2.html |
| 78 | + GIT_EDITOR=cat "$GIT_IMERGE" simplify --goal=merge --branch=c-d-merge |
| 79 | + check_tree c-d-merge $EXPECTED_TREE |
| 80 | + "$GIT_IMERGE" simplify --goal=rebase --branch=c-d-rebase |
| 81 | + check_tree c-d-rebase $EXPECTED_TREE |
| 82 | + "$GIT_IMERGE" simplify --goal=rebase-with-history --branch=c-d-rebase-with-history |
| 83 | + check_tree c-d-rebase-with-history $EXPECTED_TREE |
| 84 | + "$GIT_IMERGE" simplify --goal=border --branch=c-d-border |
| 85 | + check_tree c-d-border $EXPECTED_TREE |
| 86 | + "$GIT_IMERGE" simplify --goal=border-with-history --branch=c-d-border-with-history |
| 87 | + check_tree c-d-border-with-history $EXPECTED_TREE |
| 88 | + "$GIT_IMERGE" simplify --goal=border-with-history2 --branch=c-d-border-with-history2 |
| 89 | + check_tree c-d-border-with-history2 $EXPECTED_TREE |
| 90 | + "$GIT_IMERGE" remove |
| 91 | + |
| 92 | + git checkout c |
| 93 | + "$GIT_IMERGE" start --goal=full --first-parent --name=c-d d 2>&1 | tee start.out |
| 94 | + if grep -q Traceback start.out |
| 95 | + then |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + |
| 99 | + if ! grep -q "suggest manual merge of $conflict" autofill.out |
| 100 | + then |
| 101 | + echo "conflict not detected" |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + |
| 105 | + "$GIT_IMERGE" diagram --commits --frontier --html=imerge3.html |
| 106 | + echo 'merged version' >conflict.txt |
| 107 | + git add conflict.txt |
| 108 | + GIT_EDITOR=cat git commit |
| 109 | + "$GIT_IMERGE" continue --edit |
| 110 | + "$GIT_IMERGE" diagram --commits --frontier --html=imerge4.html |
| 111 | + "$GIT_IMERGE" finish --branch=c-d-full |
| 112 | + check_tree c-d-full $EXPECTED_TREE |
| 113 | +} |
| 114 | + |
| 115 | +# Run tests with conflicts at various locations... |
| 116 | + |
| 117 | +# A generic location: |
| 118 | +test_conflict 4-3 |
| 119 | + |
| 120 | +# The four corners: |
| 121 | +test_conflict 1-1 |
| 122 | +test_conflict 9-1 |
| 123 | +test_conflict 1-6 |
| 124 | +test_conflict 9-6 |
61 | 125 |
|
| 126 | +# Along each of the edges: |
| 127 | +test_conflict 1-2 |
| 128 | +test_conflict 9-5 |
| 129 | +test_conflict 5-1 |
| 130 | +test_conflict 6-6 |
0 commit comments