Merge branch 'fr_next' of github.com:jnavila/git
[alt-git.git] / t / t3409-rebase-preserve-merges.sh
blobec8062a66acca778d96b050b7ad884543c6eda03
1 #!/bin/sh
3 # Copyright(C) 2008 Stephen Habermann & Andreas Ericsson
5 test_description='git rebase -p should preserve merges
7 Run "git rebase -p" and check that merges are properly carried along
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 . ./test-lib.sh
14 if ! test_have_prereq REBASE_P; then
15 skip_all='skipping git rebase -p tests, as asked for'
16 test_done
19 GIT_AUTHOR_EMAIL=bogus_email_address
20 export GIT_AUTHOR_EMAIL
22 # Clone 2 (conflicting merge):
24 # A1--A2--B3 <-- origin/main
25 # \ \
26 # B1------M <-- topic
27 # \
28 # B2 <-- origin/topic
30 # Clone 3 (no-ff merge):
32 # A1--A2--B3 <-- origin/main
33 # \
34 # B1------M <-- topic
35 # \ /
36 # \--A3 <-- topic2
37 # \
38 # B2 <-- origin/topic
40 # Clone 4 (same as Clone 3)
42 test_expect_success 'setup for merge-preserving rebase' \
43 'echo First > A &&
44 git add A &&
45 git commit -m "Add A1" &&
46 git checkout -b topic &&
47 echo Second > B &&
48 git add B &&
49 git commit -m "Add B1" &&
50 git checkout -f main &&
51 echo Third >> A &&
52 git commit -a -m "Modify A2" &&
53 echo Fifth > B &&
54 git add B &&
55 git commit -m "Add different B" &&
57 git clone ./. clone2 &&
59 cd clone2 &&
60 git checkout -b topic origin/topic &&
61 test_must_fail git merge origin/main &&
62 echo Resolved >B &&
63 git add B &&
64 git commit -m "Merge origin/main into topic"
65 ) &&
67 git clone ./. clone3 &&
69 cd clone3 &&
70 git checkout -b topic2 origin/topic &&
71 echo Sixth > A &&
72 git commit -a -m "Modify A3" &&
73 git checkout -b topic origin/topic &&
74 git merge --no-ff topic2
75 ) &&
77 git clone ./. clone4 &&
79 cd clone4 &&
80 git checkout -b topic2 origin/topic &&
81 echo Sixth > A &&
82 git commit -a -m "Modify A3" &&
83 git checkout -b topic origin/topic &&
84 git merge --no-ff topic2
85 ) &&
87 git checkout topic &&
88 echo Fourth >> B &&
89 git commit -a -m "Modify B2"
92 test_expect_success '--continue works after a conflict' '
94 cd clone2 &&
95 git fetch &&
96 test_must_fail git rebase -p origin/topic &&
97 test 2 = $(git ls-files B | wc -l) &&
98 echo Resolved again > B &&
99 test_must_fail git rebase --continue &&
100 grep "^@@@ " .git/rebase-merge/patch &&
101 git add B &&
102 git rebase --continue &&
103 test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
104 test 1 = $(git rev-list --all --pretty=oneline | grep "Add different" | wc -l) &&
105 test 1 = $(git rev-list --all --pretty=oneline | grep "Merge origin" | wc -l)
109 test_expect_success 'rebase -p preserves no-ff merges' '
111 cd clone3 &&
112 git fetch &&
113 git rebase -p origin/topic &&
114 test 3 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
115 test 1 = $(git rev-list --all --pretty=oneline | grep "Merge branch" | wc -l)
119 test_expect_success 'rebase -p ignores merge.log config' '
121 cd clone4 &&
122 git fetch &&
123 git -c merge.log=1 rebase -p origin/topic &&
124 echo >expected &&
125 git log --format="%b" -1 >current &&
126 test_cmp expected current
130 test_done