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