Skip to content

Commit a6c7a27

Browse files
committed
rebase -i: correctly remember --root flag across --continue
d911d14 (rebase -i: learn to rebase root commit, 2009-01-02) tried to remember the --root flag across a merge conflict in a broken way. Introduce a flag file $DOTEST/rebase-root to fix and clarify. While at it, also make sure $UPSTREAM is always initialized to guard against existing values in the environment. [tr: added tests] Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7d9d04 commit a6c7a27

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

git-rebase--interactive.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ get_saved_options () {
456456
test -d "$REWRITTEN" && PRESERVE_MERGES=t
457457
test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
458458
test -f "$DOTEST"/verbose && VERBOSE=t
459-
test ! -s "$DOTEST"/upstream && REBASE_ROOT=t
459+
test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
460460
}
461461

462462
while test $# != 0
@@ -586,6 +586,7 @@ first and then run 'git rebase --continue' again."
586586
test -z "$ONTO" && ONTO=$UPSTREAM
587587
shift
588588
else
589+
UPSTREAM=
589590
UPSTREAM_ARG=--root
590591
test -z "$ONTO" &&
591592
die "You must specify --onto when using --root"
@@ -612,7 +613,12 @@ first and then run 'git rebase --continue' again."
612613
echo "detached HEAD" > "$DOTEST"/head-name
613614

614615
echo $HEAD > "$DOTEST"/head
615-
echo $UPSTREAM > "$DOTEST"/upstream
616+
case "$REBASE_ROOT" in
617+
'')
618+
rm -f "$DOTEST"/rebase-root ;;
619+
*)
620+
: >"$DOTEST"/rebase-root ;;
621+
esac
616622
echo $ONTO > "$DOTEST"/onto
617623
test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
618624
test t = "$VERBOSE" && : > "$DOTEST"/verbose

t/t3412-rebase-root.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,98 @@ test_expect_success 'pre-rebase hook stops rebase -i' '
184184
test 0 = $(git rev-list other...stops2 | wc -l)
185185
'
186186

187+
test_expect_success 'remove pre-rebase hook' '
188+
rm -f .git/hooks/pre-rebase
189+
'
190+
191+
test_expect_success 'set up a conflict' '
192+
git checkout master &&
193+
echo conflict > B &&
194+
git add B &&
195+
git commit -m conflict
196+
'
197+
198+
test_expect_success 'rebase --root with conflict (first part)' '
199+
git checkout -b conflict1 other &&
200+
test_must_fail git rebase --root --onto master &&
201+
git ls-files -u | grep "B$"
202+
'
203+
204+
test_expect_success 'fix the conflict' '
205+
echo 3 > B &&
206+
git add B
207+
'
208+
209+
cat > expect-conflict <<EOF
210+
6
211+
5
212+
4
213+
3
214+
conflict
215+
2
216+
1
217+
EOF
218+
219+
test_expect_success 'rebase --root with conflict (second part)' '
220+
git rebase --continue &&
221+
git log --pretty=tformat:"%s" > conflict1 &&
222+
test_cmp expect-conflict conflict1
223+
'
224+
225+
test_expect_success 'rebase -i --root with conflict (first part)' '
226+
git checkout -b conflict2 other &&
227+
GIT_EDITOR=: test_must_fail git rebase -i --root --onto master &&
228+
git ls-files -u | grep "B$"
229+
'
230+
231+
test_expect_success 'fix the conflict' '
232+
echo 3 > B &&
233+
git add B
234+
'
235+
236+
test_expect_success 'rebase -i --root with conflict (second part)' '
237+
git rebase --continue &&
238+
git log --pretty=tformat:"%s" > conflict2 &&
239+
test_cmp expect-conflict conflict2
240+
'
241+
242+
cat >expect-conflict-p <<\EOF
243+
commit conflict3 conflict3~1 conflict3^2
244+
Merge branch 'third' into other
245+
commit conflict3^2 conflict3~4
246+
6
247+
commit conflict3~1 conflict3~2 conflict3~1^2
248+
Merge branch 'side' into other
249+
commit conflict3~1^2 conflict3~3
250+
5
251+
commit conflict3~2 conflict3~3
252+
4
253+
commit conflict3~3 conflict3~4
254+
3
255+
commit conflict3~4 conflict3~5
256+
conflict
257+
commit conflict3~5 conflict3~6
258+
2
259+
commit conflict3~6
260+
1
261+
EOF
262+
263+
test_expect_success 'rebase -i -p --root with conflict (first part)' '
264+
git checkout -b conflict3 other &&
265+
GIT_EDITOR=: test_must_fail git rebase -i -p --root --onto master &&
266+
git ls-files -u | grep "B$"
267+
'
268+
269+
test_expect_success 'fix the conflict' '
270+
echo 3 > B &&
271+
git add B
272+
'
273+
274+
test_expect_success 'rebase -i -p --root with conflict (second part)' '
275+
git rebase --continue &&
276+
git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
277+
git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
278+
test_cmp expect-conflict-p out
279+
'
280+
187281
test_done

0 commit comments

Comments
 (0)