]>
Commit | Line | Data |
---|---|---|
d70b4a8f NS |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rebase with its hook(s)' | |
4 | ||
d1c02d93 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
fc47252d | 8 | TEST_PASSES_SANITIZE_LEAK=true |
d70b4a8f NS |
9 | . ./test-lib.sh |
10 | ||
11 | test_expect_success setup ' | |
12 | echo hello >file && | |
13 | git add file && | |
14 | test_tick && | |
15 | git commit -m initial && | |
16 | echo goodbye >file && | |
17 | git add file && | |
18 | test_tick && | |
19 | git commit -m second && | |
20 | git checkout -b side HEAD^ && | |
21 | echo world >git && | |
22 | git add git && | |
23 | test_tick && | |
24 | git commit -m side && | |
d1c02d93 | 25 | git checkout main && |
d70b4a8f NS |
26 | git log --pretty=oneline --abbrev-commit --graph --all && |
27 | git branch test side | |
28 | ' | |
29 | ||
30 | test_expect_success 'rebase' ' | |
31 | git checkout test && | |
32 | git reset --hard side && | |
d1c02d93 | 33 | git rebase main && |
d70b4a8f NS |
34 | test "z$(cat git)" = zworld |
35 | ' | |
36 | ||
37 | test_expect_success 'rebase -i' ' | |
38 | git checkout test && | |
39 | git reset --hard side && | |
d1c02d93 | 40 | EDITOR=true git rebase -i main && |
d70b4a8f NS |
41 | test "z$(cat git)" = zworld |
42 | ' | |
43 | ||
44 | test_expect_success 'setup pre-rebase hook' ' | |
c36c6285 ÆAB |
45 | test_hook --setup pre-rebase <<-\EOF |
46 | echo "$1,$2" >.git/PRE-REBASE-INPUT | |
47 | EOF | |
d70b4a8f NS |
48 | ' |
49 | ||
50 | test_expect_success 'pre-rebase hook gets correct input (1)' ' | |
51 | git checkout test && | |
52 | git reset --hard side && | |
d1c02d93 | 53 | git rebase main && |
d70b4a8f | 54 | test "z$(cat git)" = zworld && |
d1c02d93 | 55 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain, |
d70b4a8f NS |
56 | |
57 | ' | |
58 | ||
59 | test_expect_success 'pre-rebase hook gets correct input (2)' ' | |
60 | git checkout test && | |
61 | git reset --hard side && | |
d1c02d93 | 62 | git rebase main test && |
d70b4a8f | 63 | test "z$(cat git)" = zworld && |
d1c02d93 | 64 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
d70b4a8f NS |
65 | ' |
66 | ||
67 | test_expect_success 'pre-rebase hook gets correct input (3)' ' | |
68 | git checkout test && | |
69 | git reset --hard side && | |
d1c02d93 JS |
70 | git checkout main && |
71 | git rebase main test && | |
d70b4a8f | 72 | test "z$(cat git)" = zworld && |
d1c02d93 | 73 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
d70b4a8f NS |
74 | ' |
75 | ||
76 | test_expect_success 'pre-rebase hook gets correct input (4)' ' | |
77 | git checkout test && | |
78 | git reset --hard side && | |
d1c02d93 | 79 | EDITOR=true git rebase -i main && |
d70b4a8f | 80 | test "z$(cat git)" = zworld && |
d1c02d93 | 81 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain, |
d70b4a8f NS |
82 | |
83 | ' | |
84 | ||
85 | test_expect_success 'pre-rebase hook gets correct input (5)' ' | |
86 | git checkout test && | |
87 | git reset --hard side && | |
d1c02d93 | 88 | EDITOR=true git rebase -i main test && |
d70b4a8f | 89 | test "z$(cat git)" = zworld && |
d1c02d93 | 90 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
d70b4a8f NS |
91 | ' |
92 | ||
93 | test_expect_success 'pre-rebase hook gets correct input (6)' ' | |
94 | git checkout test && | |
95 | git reset --hard side && | |
d1c02d93 JS |
96 | git checkout main && |
97 | EDITOR=true git rebase -i main test && | |
d70b4a8f | 98 | test "z$(cat git)" = zworld && |
d1c02d93 | 99 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
d70b4a8f NS |
100 | ' |
101 | ||
102 | test_expect_success 'setup pre-rebase hook that fails' ' | |
c36c6285 ÆAB |
103 | test_hook --setup --clobber pre-rebase <<-\EOF |
104 | false | |
105 | EOF | |
d70b4a8f NS |
106 | ' |
107 | ||
108 | test_expect_success 'pre-rebase hook stops rebase (1)' ' | |
109 | git checkout test && | |
110 | git reset --hard side && | |
d1c02d93 | 111 | test_must_fail git rebase main && |
d70b4a8f NS |
112 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/test && |
113 | test 0 = $(git rev-list HEAD...side | wc -l) | |
114 | ' | |
115 | ||
116 | test_expect_success 'pre-rebase hook stops rebase (2)' ' | |
117 | git checkout test && | |
118 | git reset --hard side && | |
d1c02d93 | 119 | test_must_fail env EDITOR=: git rebase -i main && |
d70b4a8f NS |
120 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/test && |
121 | test 0 = $(git rev-list HEAD...side | wc -l) | |
122 | ' | |
123 | ||
c4427656 NS |
124 | test_expect_success 'rebase --no-verify overrides pre-rebase (1)' ' |
125 | git checkout test && | |
126 | git reset --hard side && | |
d1c02d93 | 127 | git rebase --no-verify main && |
c4427656 NS |
128 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/test && |
129 | test "z$(cat git)" = zworld | |
130 | ' | |
131 | ||
132 | test_expect_success 'rebase --no-verify overrides pre-rebase (2)' ' | |
133 | git checkout test && | |
134 | git reset --hard side && | |
d1c02d93 | 135 | EDITOR=true git rebase --no-verify -i main && |
c4427656 NS |
136 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/test && |
137 | test "z$(cat git)" = zworld | |
138 | ' | |
139 | ||
d70b4a8f | 140 | test_done |