@matheusbsbs / matheus-bagliano / commits / f8cca019b9
Fork 0

rebase: Support preserving merges in non-interactive mode

As a result of implementation details, 'git rebase' could previously only preserve merges in interactive mode. That limitation was hard for users to understand and awkward to explain. This patch works around it by running the interactive rebase helper git-rebase--interactive with GIT_EDITOR set to ':' when the user passes "-p" but not "-i" to the rebase command. The effect is that the interactive rebase helper is used but the user never sees an editor. The test-case included in this patch was originally written by Stephen Habermann <stephen@exigencecorp.com>, but has been extensively modified since its creation. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Andreas Ericsson committed Sep 29, 2008 at 22:28 UTC f8cca019b9ea9471719505ca6ccf020feb219d98
3 files changed +81 -5
Documentation/git-rebase.txt
+1 -2
@@ -250,8 +250,7 @@ OPTIONS
250
251 -p::
252 --preserve-merges::
253 - Instead of ignoring merges, try to recreate them. This option
254 - only works in interactive mode.
253 + Instead of ignoring merges, try to recreate them.
254
255 include::merge-strategies.txt[]
256
git-rebase.sh
+19 -3
@@ -138,10 +138,26 @@ finish_rb_merge () {
138 }
139
140 is_interactive () {
141 - test -f "$dotest"/interactive ||
142 - while :; do case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
141 + while test $# != 0
142 + do
143 + case "$1" in
144 + -i|--interactive)
145 + interactive_rebase=explicit
146 + break
147 + ;;
148 + -p|--preserve-merges)
149 + interactive_rebase=implied
150 + ;;
151 + esac
152 shift
144 - done && test -n "$1"
153 + done
154 +
155 + if [ "$interactive_rebase" = implied ]; then
156 + GIT_EDITOR=:
157 + export GIT_EDITOR
158 + fi
159 +
160 + test -n "$interactive_rebase" || test -f "$dotest"/interactive
161 }
162
163 test -f "$GIT_DIR"/rebase-apply/applying &&
t/t3409-rebase-preserve-merges.sh new
+61
@@ -0,0 +1,61 @@
1 +#!/bin/sh
2 +#
3 +# Copyright(C) 2008 Stephen Habermann & Andreas Ericsson
4 +#
5 +test_description='git rebase -p should preserve merges
6 +
7 +Run "git rebase -p" and check that merges are properly carried along
8 +'
9 +. ./test-lib.sh
10 +
11 +GIT_AUTHOR_EMAIL=bogus_email_address
12 +export GIT_AUTHOR_EMAIL
13 +
14 +#echo 'Setting up:
15 +#
16 +#A1--A2 <-- origin/master
17 +# \ \
18 +# B1--M <-- topic
19 +# \
20 +# B2 <-- origin/topic
21 +#
22 +#'
23 +
24 +test_expect_success 'setup for merge-preserving rebase' \
25 + 'echo First > A &&
26 + git add A &&
27 + git-commit -m "Add A1" &&
28 + git checkout -b topic &&
29 + echo Second > B &&
30 + git add B &&
31 + git-commit -m "Add B1" &&
32 + git checkout -f master &&
33 + echo Third >> A &&
34 + git-commit -a -m "Modify A2" &&
35 +
36 + git clone ./. clone1 &&
37 + cd clone1 &&
38 + git checkout -b topic origin/topic &&
39 + git merge origin/master &&
40 + cd ..
41 +
42 + git clone ./. clone2
43 + cd clone2 &&
44 + git checkout -b topic origin/topic &&
45 + git merge origin/master &&
46 + cd .. &&
47 +
48 + git checkout topic &&
49 + echo Fourth >> B &&
50 + git commit -a -m "Modify B2"
51 +'
52 +
53 +test_expect_success 'rebase -p fakes interactive rebase' '
54 + cd clone2 &&
55 + git fetch &&
56 + git rebase -p origin/topic &&
57 + test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
58 + test 1 = $(git rev-list --all --pretty=oneline | grep "Merge commit" | wc -l)
59 +'
60 +
61 +test_done