Merge branch 'om/rerere-careful'
* om/rerere-careful: builtin-rerere: more carefully find conflict markers
This commit is contained in:
@ -112,11 +112,17 @@ static int handle_file(const char *path,
|
|||||||
strbuf_init(&one, 0);
|
strbuf_init(&one, 0);
|
||||||
strbuf_init(&two, 0);
|
strbuf_init(&two, 0);
|
||||||
while (fgets(buf, sizeof(buf), f)) {
|
while (fgets(buf, sizeof(buf), f)) {
|
||||||
if (!prefixcmp(buf, "<<<<<<< "))
|
if (!prefixcmp(buf, "<<<<<<< ")) {
|
||||||
|
if (hunk)
|
||||||
|
goto bad;
|
||||||
hunk = 1;
|
hunk = 1;
|
||||||
else if (!prefixcmp(buf, "======="))
|
} else if (!prefixcmp(buf, "=======") && isspace(buf[7])) {
|
||||||
|
if (hunk != 1)
|
||||||
|
goto bad;
|
||||||
hunk = 2;
|
hunk = 2;
|
||||||
else if (!prefixcmp(buf, ">>>>>>> ")) {
|
} else if (!prefixcmp(buf, ">>>>>>> ")) {
|
||||||
|
if (hunk != 2)
|
||||||
|
goto bad;
|
||||||
if (strbuf_cmp(&one, &two) > 0)
|
if (strbuf_cmp(&one, &two) > 0)
|
||||||
strbuf_swap(&one, &two);
|
strbuf_swap(&one, &two);
|
||||||
hunk_no++;
|
hunk_no++;
|
||||||
@ -142,6 +148,10 @@ static int handle_file(const char *path,
|
|||||||
strbuf_addstr(&two, buf);
|
strbuf_addstr(&two, buf);
|
||||||
else if (out)
|
else if (out)
|
||||||
fputs(buf, out);
|
fputs(buf, out);
|
||||||
|
continue;
|
||||||
|
bad:
|
||||||
|
hunk = 99; /* force error exit */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
strbuf_release(&one);
|
strbuf_release(&one);
|
||||||
strbuf_release(&two);
|
strbuf_release(&two);
|
||||||
|
@ -9,6 +9,8 @@ test_description='git rerere
|
|||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
cat > a1 << EOF
|
cat > a1 << EOF
|
||||||
|
Some title
|
||||||
|
==========
|
||||||
Whether 'tis nobler in the mind to suffer
|
Whether 'tis nobler in the mind to suffer
|
||||||
The slings and arrows of outrageous fortune,
|
The slings and arrows of outrageous fortune,
|
||||||
Or to take arms against a sea of troubles,
|
Or to take arms against a sea of troubles,
|
||||||
@ -24,6 +26,8 @@ git commit -q -a -m initial
|
|||||||
|
|
||||||
git checkout -b first
|
git checkout -b first
|
||||||
cat >> a1 << EOF
|
cat >> a1 << EOF
|
||||||
|
Some title
|
||||||
|
==========
|
||||||
To die, to sleep;
|
To die, to sleep;
|
||||||
To sleep: perchance to dream: ay, there's the rub;
|
To sleep: perchance to dream: ay, there's the rub;
|
||||||
For in that sleep of death what dreams may come
|
For in that sleep of death what dreams may come
|
||||||
@ -35,7 +39,7 @@ git commit -q -a -m first
|
|||||||
|
|
||||||
git checkout -b second master
|
git checkout -b second master
|
||||||
git show first:a1 |
|
git show first:a1 |
|
||||||
sed -e 's/To die, t/To die! T/' > a1
|
sed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1
|
||||||
echo "* END *" >>a1
|
echo "* END *" >>a1
|
||||||
git commit -q -a -m second
|
git commit -q -a -m second
|
||||||
|
|
||||||
@ -55,14 +59,14 @@ test_expect_success 'conflicting merge' '
|
|||||||
|
|
||||||
sha1=$(sed -e 's/ .*//' .git/rr-cache/MERGE_RR)
|
sha1=$(sed -e 's/ .*//' .git/rr-cache/MERGE_RR)
|
||||||
rr=.git/rr-cache/$sha1
|
rr=.git/rr-cache/$sha1
|
||||||
test_expect_success 'recorded preimage' "grep ======= $rr/preimage"
|
test_expect_success 'recorded preimage' "grep ^=======$ $rr/preimage"
|
||||||
|
|
||||||
test_expect_success 'rerere.enabled works, too' '
|
test_expect_success 'rerere.enabled works, too' '
|
||||||
rm -rf .git/rr-cache &&
|
rm -rf .git/rr-cache &&
|
||||||
git config rerere.enabled true &&
|
git config rerere.enabled true &&
|
||||||
git reset --hard &&
|
git reset --hard &&
|
||||||
! git merge first &&
|
! git merge first &&
|
||||||
grep ======= $rr/preimage
|
grep ^=======$ $rr/preimage
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'no postimage or thisimage yet' \
|
test_expect_success 'no postimage or thisimage yet' \
|
||||||
@ -71,7 +75,7 @@ test_expect_success 'no postimage or thisimage yet' \
|
|||||||
test_expect_success 'preimage has right number of lines' '
|
test_expect_success 'preimage has right number of lines' '
|
||||||
|
|
||||||
cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
|
cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
|
||||||
test $cnt = 9
|
test $cnt = 13
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -80,13 +84,23 @@ git show first:a1 > a1
|
|||||||
cat > expect << EOF
|
cat > expect << EOF
|
||||||
--- a/a1
|
--- a/a1
|
||||||
+++ b/a1
|
+++ b/a1
|
||||||
@@ -6,17 +6,9 @@
|
@@ -1,4 +1,4 @@
|
||||||
|
-Some Title
|
||||||
|
+Some title
|
||||||
|
==========
|
||||||
|
Whether 'tis nobler in the mind to suffer
|
||||||
|
The slings and arrows of outrageous fortune,
|
||||||
|
@@ -8,21 +8,11 @@
|
||||||
The heart-ache and the thousand natural shocks
|
The heart-ache and the thousand natural shocks
|
||||||
That flesh is heir to, 'tis a consummation
|
That flesh is heir to, 'tis a consummation
|
||||||
Devoutly to be wish'd.
|
Devoutly to be wish'd.
|
||||||
-<<<<<<<
|
-<<<<<<<
|
||||||
|
-Some Title
|
||||||
|
-==========
|
||||||
-To die! To sleep;
|
-To die! To sleep;
|
||||||
-=======
|
-=======
|
||||||
|
Some title
|
||||||
|
==========
|
||||||
To die, to sleep;
|
To die, to sleep;
|
||||||
->>>>>>>
|
->>>>>>>
|
||||||
To sleep: perchance to dream: ay, there's the rub;
|
To sleep: perchance to dream: ay, there's the rub;
|
||||||
@ -124,7 +138,7 @@ test_expect_success 'another conflicting merge' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
git show first:a1 | sed 's/To die: t/To die! T/' > expect
|
git show first:a1 | sed 's/To die: t/To die! T/' > expect
|
||||||
test_expect_success 'rerere kicked in' "! grep ======= a1"
|
test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
|
||||||
|
|
||||||
test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
|
test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user