Skip to content

Commit 768c728

Browse files
committed
Merge branch 'js/rebase-i-p'
* js/rebase-i-p: rebase -i -p: leave a --cc patch when a merge could not be redone rebase -i -p: Fix --continue after a merge could not be redone Show a failure of rebase -p if the merge had a conflict
2 parents c66c0cb + 4fb1a19 commit 768c728

File tree

2 files changed

+58
-16
lines changed

2 files changed

+58
-16
lines changed

git-rebase--interactive.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,18 @@ mark_action_done () {
115115
}
116116

117117
make_patch () {
118-
parent_sha1=$(git rev-parse --verify "$1"^) ||
119-
die "Cannot get patch for $1^"
120-
git diff-tree -p "$parent_sha1".."$1" > "$DOTEST"/patch
118+
sha1_and_parents="$(git rev-list --parents -1 "$1")"
119+
case "$sha1_and_parents" in
120+
?*' '?*' '?*)
121+
git diff --cc $sha1_and_parents
122+
;;
123+
?*' '?*)
124+
git diff-tree -p "$1^!"
125+
;;
126+
*)
127+
echo "Root commit"
128+
;;
129+
esac > "$DOTEST"/patch
121130
test -f "$DOTEST"/message ||
122131
git cat-file commit "$1" | sed "1,/^$/d" > "$DOTEST"/message
123132
test -f "$DOTEST"/author-script ||
@@ -256,9 +265,8 @@ pick_one_preserving_merges () {
256265
output git merge $STRATEGY -m "$msg" \
257266
$new_parents
258267
then
259-
git rerere
260268
printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
261-
die Error redoing merge $sha1
269+
die_with_patch $sha1 "Error redoing merge $sha1"
262270
fi
263271
;;
264272
*)

t/t3409-rebase-preserve-merges.sh

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ Run "git rebase -p" and check that merges are properly carried along
1111
GIT_AUTHOR_EMAIL=bogus_email_address
1212
export GIT_AUTHOR_EMAIL
1313

14-
#echo 'Setting up:
14+
# Clone 1 (trivial merge):
1515
#
16-
#A1--A2 <-- origin/master
17-
# \ \
18-
# B1--M <-- topic
19-
# \
20-
# B2 <-- origin/topic
16+
# A1--A2 <-- origin/master
17+
# \ \
18+
# B1--M <-- topic
19+
# \
20+
# B2 <-- origin/topic
2121
#
22-
#'
22+
# Clone 2 (conflicting merge):
23+
#
24+
# A1--A2--B3 <-- origin/master
25+
# \ \
26+
# B1------M <-- topic
27+
# \
28+
# B2 <-- origin/topic
29+
#
30+
# In both cases, 'topic' is rebased onto 'origin/topic'.
2331

2432
test_expect_success 'setup for merge-preserving rebase' \
2533
'echo First > A &&
@@ -37,12 +45,19 @@ test_expect_success 'setup for merge-preserving rebase' \
3745
cd clone1 &&
3846
git checkout -b topic origin/topic &&
3947
git merge origin/master &&
40-
cd ..
48+
cd .. &&
49+
50+
echo Fifth > B &&
51+
git add B &&
52+
git commit -m "Add different B" &&
4153

42-
git clone ./. clone2
54+
git clone ./. clone2 &&
4355
cd clone2 &&
4456
git checkout -b topic origin/topic &&
45-
git merge origin/master &&
57+
test_must_fail git merge origin/master &&
58+
echo Resolved > B &&
59+
git add B &&
60+
git commit -m "Merge origin/master into topic" &&
4661
cd .. &&
4762

4863
git checkout topic &&
@@ -51,11 +66,30 @@ test_expect_success 'setup for merge-preserving rebase' \
5166
'
5267

5368
test_expect_success 'rebase -p fakes interactive rebase' '
54-
cd clone2 &&
69+
(
70+
cd clone1 &&
5571
git fetch &&
5672
git rebase -p origin/topic &&
5773
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
5874
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge commit" | wc -l)
75+
)
76+
'
77+
78+
test_expect_success '--continue works after a conflict' '
79+
(
80+
cd clone2 &&
81+
git fetch &&
82+
test_must_fail git rebase -p origin/topic &&
83+
test 2 = $(git ls-files B | wc -l) &&
84+
echo Resolved again > B &&
85+
test_must_fail git rebase --continue &&
86+
grep "^@@@ " .git/rebase-merge/patch &&
87+
git add B &&
88+
git rebase --continue &&
89+
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
90+
test 1 = $(git rev-list --all --pretty=oneline | grep "Add different" | wc -l) &&
91+
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge origin" | wc -l)
92+
)
5993
'
6094

6195
test_done

0 commit comments

Comments
 (0)