Skip to content

Commit 4554378

Browse files
authored
Merge pull request #167 from mhagger/tests-plus-plus
Add some more tests, and improve the existing ones
2 parents a4fc49a + 7a2e5c3 commit 4554378

12 files changed

Lines changed: 628 additions & 208 deletions

MANIFEST.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
include completions/git-imerge
22
include COPYING
3-
include t/create-test-repo
43
include t/test-conflicted
54
include t/test-drop
5+
include t/test-duplicated
6+
include t/test-flip-flop
7+
include t/test-lib.sh
8+
include t/test-really-conflicted
69
include t/test-unconflicted
710
include tox.ini

gitimerge.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,12 @@ def auto_outline_frontier(self, merge_frontier=None):
22602260
# One of the merges that we expected to succeed in
22612261
# fact failed.
22622262
merge_frontier.remove_failure(e.i1, e.i2)
2263+
2264+
if (e.i1, e.i2) == (1, 1):
2265+
# The failed merge was the first micromerge that we'd
2266+
# need for `best_block`, so record it as a blocker:
2267+
best_block[e.i1, e.i2].record_blocked(True)
2268+
22632269
return self.auto_outline_frontier(merge_frontier)
22642270
else:
22652271
f1, f2 = merge_frontier.partition(best_block)

t/create-test-repo

Lines changed: 0 additions & 91 deletions
This file was deleted.

t/reset-test-repo

Lines changed: 0 additions & 22 deletions
This file was deleted.

t/test-conflicted

Lines changed: 123 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,130 @@
11
#! /bin/sh
22

3-
# This should be executed in a clean working copy of the test repo.
4-
5-
set -e
6-
set -x
3+
set -ex
74

85
BASE="$(dirname "$(cd $(dirname "$0") && pwd)")"
9-
TMP="$BASE/t/tmp/main"
6+
. "$BASE/t/test-lib.sh"
7+
108
GIT_IMERGE="git-imerge"
119

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
61125

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

t/test-drop

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
11
#! /bin/sh
22

3-
# This should be executed in a clean working copy of the test repo.
4-
5-
set -e
6-
7-
DESCRIPTION="git-imerge drop test repository"
8-
9-
modify() {
10-
filename="$1"
11-
text="$2"
12-
echo "$text" >"$filename" &&
13-
git add "$filename"
14-
}
3+
set -ex
154

165
BASE="$(dirname "$(cd $(dirname "$0") && pwd)")"
17-
TMP="$BASE/t/tmp/drop"
6+
. "$BASE/t/test-lib.sh"
7+
188
GIT_IMERGE="git-imerge"
9+
TMP="$BASE/t/tmp/drop"
10+
DESCRIPTION="git-imerge drop test repository"
1911

20-
rm -rf "$TMP"
21-
mkdir -p "$TMP"
12+
# Set up a test repo with a linear string of commits, all modifying
13+
# different files:
14+
init_test_repo "$TMP" "$DESCRIPTION"
2215
cd "$TMP"
2316

24-
git init
25-
echo "$DESCRIPTION" >.git/description
26-
git config user.name 'Loú User'
27-
git config user.email 'luser@example.com'
28-
2917
modify a.txt 0
30-
git commit -m 'm⇒0'
18+
commit -m 'm⇒0'
3119

3220
for i in $(seq 6)
3321
do
3422
modify a$i.txt $i
35-
git commit -m "a$i$i"
23+
commit -m "a$i$i"
3624
done
3725

38-
ln -s "$BASE/imerge.css" .
39-
4026
git checkout -b dropped master
4127
"$GIT_IMERGE" drop HEAD~5..HEAD~3
4228
"$GIT_IMERGE" diagram --commits --frontier --html=imerge-drop.html
4329
"$GIT_IMERGE" finish
30+
check_tree dropped 3b92d9e80adb5b542a651863e6853ff5de9e496b
4431

4532
git checkout -b reverted master
4633
"$GIT_IMERGE" revert HEAD~5..HEAD~3
4734
"$GIT_IMERGE" diagram --commits --frontier --html=imerge-revert.html
4835
"$GIT_IMERGE" finish
49-
50-
git --no-pager diff dropped reverted
36+
check_tree reverted 3b92d9e80adb5b542a651863e6853ff5de9e496b
5137

0 commit comments

Comments
 (0)