]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3414-rebase-preserve-onto.sh
t4039: abstract away SHA-1-specific constants
[thirdparty/git.git] / t / t3414-rebase-preserve-onto.sh
CommitLineData
1830d9cb
GP
1#!/bin/sh
2#
3# Copyright (c) 2009 Greg Price
4#
5
6test_description='git rebase -p should respect --onto
7
8In a rebase with --onto, we should rewrite all the commits that
9aren'"'"'t on top of $ONTO, even if they are on top of $UPSTREAM.
10'
11. ./test-lib.sh
12
11aad464
JS
13if ! test_have_prereq REBASE_P; then
14 skip_all='skipping git rebase -p tests, as asked for'
15 test_done
16fi
17
eaf0551d 18. "$TEST_DIRECTORY"/lib-rebase.sh
1830d9cb
GP
19
20# Set up branches like this:
21# A1---B1---E1---F1---G1
22# \ \ /
23# \ \--C1---D1--/
24# H1
25
26test_expect_success 'setup' '
27 test_commit A1 &&
28 test_commit B1 &&
29 test_commit C1 &&
30 test_commit D1 &&
31 git reset --hard B1 &&
32 test_commit E1 &&
33 test_commit F1 &&
34 test_merge G1 D1 &&
35 git reset --hard A1 &&
36 test_commit H1
37'
38
39# Now rebase merge G1 from both branches' base B1, both should move:
40# A1---B1---E1---F1---G1
41# \ \ /
42# \ \--C1---D1--/
43# \
44# H1---E2---F2---G2
45# \ /
46# \--C2---D2--/
47
48test_expect_success 'rebase from B1 onto H1' '
49 git checkout G1 &&
50 git rebase -p --onto H1 B1 &&
51 test "$(git rev-parse HEAD^1^1^1)" = "$(git rev-parse H1)" &&
52 test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse H1)"
53'
54
55# On the other hand if rebase from E1 which is within one branch,
56# then the other branch stays:
57# A1---B1---E1---F1---G1
58# \ \ /
59# \ \--C1---D1--/
60# \ \
61# H1-----F3-----G3
62
63test_expect_success 'rebase from E1 onto H1' '
64 git checkout G1 &&
65 git rebase -p --onto H1 E1 &&
66 test "$(git rev-parse HEAD^1^1)" = "$(git rev-parse H1)" &&
67 test "$(git rev-parse HEAD^2)" = "$(git rev-parse D1)"
68'
69
70# And the same if we rebase from a commit in the second-parent branch.
71# A1---B1---E1---F1----G1
72# \ \ \ /
73# \ \--C1---D1-\-/
74# \ \
75# H1------D3------G4
76
77test_expect_success 'rebase from C1 onto H1' '
78 git checkout G1 &&
79 git rev-list --first-parent --pretty=oneline C1..G1 &&
80 git rebase -p --onto H1 C1 &&
81 test "$(git rev-parse HEAD^2^1)" = "$(git rev-parse H1)" &&
82 test "$(git rev-parse HEAD^1)" = "$(git rev-parse F1)"
83'
84
85test_done