46b8dcf6da2ac6e15bdbceb8bd80a7091541ec05
[git-central.git] / tests / t2301b-broken-rebase.sh
1 #!/bin/sh
2
3 test_description='rebase interactive does not rebase'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8         echo "setup" >a &&
9         git add a &&
10         git commit -m "setup" &&
11         git clone ./. server &&
12         rm -fr server/.git/hooks &&
13         git remote add origin ./server &&
14         git config --add branch.master.remote origin &&
15         git config --add branch.master.merge refs/heads/master &&
16         git fetch &&
17
18         git checkout -b stable master &&
19         echo "setup.stable" >a &&
20         git commit -a -m "stable" &&
21         git push origin stable
22 '
23 #
24 # A --C------            <-- origin/stable
25 #  \  |      \
26 #   B -- D -- E -- F     <-- origin/topic2
27 #    \|             \
28 #     g -- h ------- i   <-- topic2
29 #
30 # Trying to push F..i
31 #
32 # merge-base(F, h) has two options: B and C
33 #
34 test_expect_success 'merging in stable with tricky double baserev does not fool the script' '
35         # B: start our topic2 branch, and share it
36         git checkout -b topic2 origin/stable &&
37         git config --add branch.topic2.merge refs/heads/topic2 &&
38         echo "commit B" >a.topic2 &&
39         git add a.topic2 &&
40         git commit -m "commit B created topic2" &&
41         git push origin topic2 &&
42
43         # C: now, separately, move ahead stable, and share it
44         git checkout stable
45         echo "commit C" >a &&
46         git commit -a -m "commit C moved stable" &&
47         git push origin stable &&
48
49         # D: have another client commit (in this case, it is the server, but close enough) moves topic2
50         cd server &&
51         git checkout topic2 &&
52         echo "commit D continuing topic2" >a.client2 &&
53         git add a.client2 &&
54         git commit -m "commit D by client2" &&
55
56         # E: the same other client merges the moved stable
57         git merge stable &&
58
59         # F: the same other client moves topic2 again
60         echo "commit F" >a.client2 &&
61         git commit -a -m "commit F by client2" &&
62         F_hash=$(git rev-parse HEAD) &&
63         cd .. &&
64
65         # g: now locally merge in the moved stable (even though our topic2 is out of date)
66         git checkout topic2 &&
67         git merge stable &&
68         g_hash=$(git rev-parse HEAD) &&
69
70         # h: advance local topic2
71         echo "commit H" >a.topic2 &&
72         git commit -a -m "commit H continues local fork" &&
73         h_hash=$(git rev-parse HEAD) &&
74
75         # i: make a new merge commit
76         git pull --no-rebase &&
77         i_hash=$(git rev-parse HEAD) &&
78
79         # Watch merge rejected as something that should get rebased
80         # ! git push origin topic2
81         test "$i_hash $h_hash $F_hash" = "$(git rev-list --parents --no-walk HEAD)"
82
83         # Now fix it the merge by rebasing it
84         git reset --hard ORIG_HEAD &&
85         GIT_EDITOR=: git rebase -i -p origin/topic2 &&
86         h2_hash=$(git rev-parse HEAD) &&
87
88         # Should be:
89         # test "$h2_hash $F_hash" = "$(git rev-list --parents --no-walk HEAD)"
90         # But is just:
91         test "$h_hash $g_hash" = "$(git rev-list --parents --no-walk HEAD)"
92         # Where did $F_hash go?
93 '
94
95 test_done
96