@matheusbsbs / matheus-bagliano / commits / 1308c17b3e
Fork 0

Allow rebase to run if upstream is completely merged

Consider this history: o--o-...-B <- origin \ \ x--x--M--x--x <- master In this situation, rebase considers master fully up-to-date and would not do anything. However, if there were additional commits on origin, the rebase would run and move the commits x on top of origin. Here we change rebase to short-circuit out only if the history since origin is strictly linear. Consequently, the above as well as a history like this would be linearized: o--o <- origin \ x--x \ \ x--M--x--x <- master Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jul 4, 2007 at 22:09 UTC 1308c17b3e6bd3f5636f5b9bcadb2fbdf559009d
2 files changed +43 -4
git-rebase.sh
+5 -3
@@ -305,10 +305,12 @@ branch=$(git rev-parse --verify "${branch_name}^0") || exit
305
306 # Now we are rebasing commits $upstream..$branch on top of $onto
307
308 -# Check if we are already based on $onto, but this should be
309 -# done only when upstream and onto are the same.
308 +# Check if we are already based on $onto with linear history,
309 +# but this should be done only when upstream and onto are the same.
310 mb=$(git merge-base "$onto" "$branch")
311 -if test "$upstream" = "$onto" && test "$mb" = "$onto"
311 +if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
312 + # linear history?
313 + ! git rev-list --parents "$onto".."$branch" | grep " .* " > /dev/null
314 then
315 echo >&2 "Current branch $branch_name is up to date."
316 exit 0
t/t3400-rebase.sh
+38 -1
@@ -12,7 +12,7 @@ This test runs git rebase and checks that the author information is not lost.
12 export GIT_AUTHOR_EMAIL=bogus_email_address
13
14 test_expect_success \
15 - 'prepare repository with topic branch, then rebase against master' \
15 + 'prepare repository with topic branches' \
16 'echo First > A &&
17 git update-index --add A &&
18 git-commit -m "Add A." &&
@@ -24,11 +24,48 @@ test_expect_success \
24 echo Third >> A &&
25 git update-index A &&
26 git-commit -m "Modify A." &&
27 + git checkout -b side my-topic-branch &&
28 + echo Side >> C &&
29 + git add C &&
30 + git commit -m "Add C" &&
31 + git checkout -b nonlinear my-topic-branch &&
32 + echo Edit >> B &&
33 + git add B &&
34 + git commit -m "Modify B" &&
35 + git merge side &&
36 + git checkout -b upstream-merged-nonlinear &&
37 + git merge master &&
38 git checkout -f my-topic-branch &&
39 + git tag topic
40 +'
41 +
42 +test_expect_success 'rebase against master' '
43 git rebase master'
44
45 test_expect_failure \
46 'the rebase operation should not have destroyed author information' \
47 'git log | grep "Author:" | grep "<>"'
48
49 +test_expect_success 'rebase after merge master' '
50 + git reset --hard topic &&
51 + git merge master &&
52 + git rebase master &&
53 + ! git show | grep "^Merge:"
54 +'
55 +
56 +test_expect_success 'rebase of history with merges is linearized' '
57 + git checkout nonlinear &&
58 + test 4 = $(git rev-list master.. | wc -l) &&
59 + git rebase master &&
60 + test 3 = $(git rev-list master.. | wc -l)
61 +'
62 +
63 +test_expect_success \
64 + 'rebase of history with merges after upstream merge is linearized' '
65 + git checkout upstream-merged-nonlinear &&
66 + test 5 = $(git rev-list master.. | wc -l) &&
67 + git rebase master &&
68 + test 3 = $(git rev-list master.. | wc -l)
69 +'
70 +
71 test_done