#!/bin/sh # # Copyright(C) 2008 Stephen Habermann & Andreas Ericsson # global test_description := ''git rebase -p should preserve merges Run "git rebase -p" and check that merges are properly carried along '' source ./test-lib.sh global GIT_AUTHOR_EMAIL := 'bogus_email_address' export GIT_AUTHOR_EMAIL # Clone 2 (conflicting merge): # # A1--A2--B3 <-- origin/master # \ \ # B1------M <-- topic # \ # B2 <-- origin/topic # # Clone 3 (no-ff merge): # # A1--A2--B3 <-- origin/master # \ # B1------M <-- topic # \ / # \--A3 <-- topic2 # \ # B2 <-- origin/topic # # Clone 4 (same as Clone 3) test_expect_success 'setup for merge-preserving rebase' \ 'echo First > A && git add A && git commit -m "Add A1" && git checkout -b topic && echo Second > B && git add B && git commit -m "Add B1" && git checkout -f master && echo Third >> A && git commit -a -m "Modify A2" && echo Fifth > B && git add B && git commit -m "Add different B" && git clone ./. clone2 && ( cd clone2 && git checkout -b topic origin/topic && test_must_fail git merge origin/master && echo Resolved >B && git add B && git commit -m "Merge origin/master into topic" ) && git clone ./. clone3 && ( cd clone3 && git checkout -b topic2 origin/topic && echo Sixth > A && git commit -a -m "Modify A3" && git checkout -b topic origin/topic && git merge --no-ff topic2 ) && git clone ./. clone4 && ( cd clone4 && git checkout -b topic2 origin/topic && echo Sixth > A && git commit -a -m "Modify A3" && git checkout -b topic origin/topic && git merge --no-ff topic2 ) && git checkout topic && echo Fourth >> B && git commit -a -m "Modify B2" ' test_expect_success '--continue works after a conflict' ' ( cd clone2 && git fetch && test_must_fail git rebase -p origin/topic && test 2 = $(git ls-files B | wc -l) && echo Resolved again > B && test_must_fail git rebase --continue && grep "^@@@ " .git/rebase-merge/patch && git add B && git rebase --continue && test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && test 1 = $(git rev-list --all --pretty=oneline | grep "Add different" | wc -l) && test 1 = $(git rev-list --all --pretty=oneline | grep "Merge origin" | wc -l) ) ' test_expect_success 'rebase -p preserves no-ff merges' ' ( cd clone3 && git fetch && git rebase -p origin/topic && test 3 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && test 1 = $(git rev-list --all --pretty=oneline | grep "Merge branch" | wc -l) ) ' test_expect_success 'rebase -p ignores merge.log config' ' ( cd clone4 && git fetch && git -c merge.log=1 rebase -p origin/topic && echo >expected && git log --format="%b" -1 >current && test_cmp expected current ) ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"git rebase -p should preserve merges\n"> <"\n"> <"Run \"git rebase -p\" and check that merges are properly carried along\n"> ) } spids: [12] ) ] spids: [12] ) (C {(.)} {(./test-lib.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_AUTHOR_EMAIL) op: Equal rhs: {(bogus_email_address)} spids: [24] ) ] spids: [24] ) (C {(export)} {(GIT_AUTHOR_EMAIL)}) (C {(test_expect_success)} {(SQ <"setup for merge-preserving rebase">)} { (SQ <"echo First > A &&\n"> <"\tgit add A &&\n"> <"\tgit commit -m \"Add A1\" &&\n"> <"\tgit checkout -b topic &&\n"> <"\techo Second > B &&\n"> <"\tgit add B &&\n"> <"\tgit commit -m \"Add B1\" &&\n"> <"\tgit checkout -f master &&\n"> <"\techo Third >> A &&\n"> <"\tgit commit -a -m \"Modify A2\" &&\n"> <"\techo Fifth > B &&\n"> <"\tgit add B &&\n"> <"\tgit commit -m \"Add different B\" &&\n"> <"\n"> <"\tgit clone ./. clone2 &&\n"> <"\t(\n"> <"\t\tcd clone2 &&\n"> <"\t\tgit checkout -b topic origin/topic &&\n"> <"\t\ttest_must_fail git merge origin/master &&\n"> <"\t\techo Resolved >B &&\n"> <"\t\tgit add B &&\n"> <"\t\tgit commit -m \"Merge origin/master into topic\"\n"> <"\t) &&\n"> <"\n"> <"\tgit clone ./. clone3 &&\n"> <"\t(\n"> <"\t\tcd clone3 &&\n"> <"\t\tgit checkout -b topic2 origin/topic &&\n"> <"\t\techo Sixth > A &&\n"> <"\t\tgit commit -a -m \"Modify A3\" &&\n"> <"\t\tgit checkout -b topic origin/topic &&\n"> <"\t\tgit merge --no-ff topic2\n"> <"\t) &&\n"> <"\n"> <"\tgit clone ./. clone4 &&\n"> <"\t(\n"> <"\t\tcd clone4 &&\n"> <"\t\tgit checkout -b topic2 origin/topic &&\n"> <"\t\techo Sixth > A &&\n"> <"\t\tgit commit -a -m \"Modify A3\" &&\n"> <"\t\tgit checkout -b topic origin/topic &&\n"> <"\t\tgit merge --no-ff topic2\n"> <"\t) &&\n"> <"\n"> <"\tgit checkout topic &&\n"> <"\techo Fourth >> B &&\n"> <"\tgit commit -a -m \"Modify B2\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"--continue works after a conflict">)} { (SQ <"\n"> <"\t(\n"> <"\tcd clone2 &&\n"> <"\tgit fetch &&\n"> <"\ttest_must_fail git rebase -p origin/topic &&\n"> <"\ttest 2 = $(git ls-files B | wc -l) &&\n"> <"\techo Resolved again > B &&\n"> <"\ttest_must_fail git rebase --continue &&\n"> <"\tgrep \"^@@@ \" .git/rebase-merge/patch &&\n"> <"\tgit add B &&\n"> <"\tgit rebase --continue &&\n"> <"\ttest 1 = $(git rev-list --all --pretty=oneline | grep \"Modify A\" | wc -l) &&\n"> <"\ttest 1 = $(git rev-list --all --pretty=oneline | grep \"Add different\" | wc -l) &&\n"> <"\ttest 1 = $(git rev-list --all --pretty=oneline | grep \"Merge origin\" | wc -l)\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"rebase -p preserves no-ff merges">)} { (SQ <"\n"> <"\t(\n"> <"\tcd clone3 &&\n"> <"\tgit fetch &&\n"> <"\tgit rebase -p origin/topic &&\n"> <"\ttest 3 = $(git rev-list --all --pretty=oneline | grep \"Modify A\" | wc -l) &&\n"> <"\ttest 1 = $(git rev-list --all --pretty=oneline | grep \"Merge branch\" | wc -l)\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"rebase -p ignores merge.log config">)} { (SQ <"\n"> <"\t(\n"> <"\tcd clone4 &&\n"> <"\tgit fetch &&\n"> <"\tgit -c merge.log=1 rebase -p origin/topic &&\n"> <"\techo >expected &&\n"> <"\tgit log --format=\"%b\" -1 >current &&\n"> <"\ttest_cmp expected current\n"> <"\t)\n"> ) } ) (C {(test_done)}) ] )