Sync with maint
[git] / t / t3409-rebase-preserve-merges.sh
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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
12 . ./test-lib.sh
13
14 if ! test_have_prereq REBASE_P; then
15         skip_all='skipping git rebase -p tests, as asked for'
16         test_done
17 fi
18
19 GIT_AUTHOR_EMAIL=bogus_email_address
20 export GIT_AUTHOR_EMAIL
21
22 # Clone 2 (conflicting merge):
23 #
24 # A1--A2--B3   <-- origin/main
25 #  \       \
26 #   B1------M  <-- topic
27 #    \
28 #     B2       <-- origin/topic
29 #
30 # Clone 3 (no-ff merge):
31 #
32 # A1--A2--B3   <-- origin/main
33 #  \
34 #   B1------M  <-- topic
35 #    \     /
36 #     \--A3    <-- topic2
37 #      \
38 #       B2     <-- origin/topic
39 #
40 # Clone 4 (same as Clone 3)
41
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" &&
56
57         git clone ./. clone2 &&
58         (
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         ) &&
66
67         git clone ./. clone3 &&
68         (
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         ) &&
76
77         git clone ./. clone4 &&
78         (
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         ) &&
86
87         git checkout topic &&
88         echo Fourth >> B &&
89         git commit -a -m "Modify B2"
90 '
91
92 test_expect_success '--continue works after a conflict' '
93         (
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)
106         )
107 '
108
109 test_expect_success 'rebase -p preserves no-ff merges' '
110         (
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)
116         )
117 '
118
119 test_expect_success 'rebase -p ignores merge.log config' '
120         (
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
127         )
128 '
129
130 test_done