The eleventh batch
[git/gitster.git] / t / t3413-rebase-hook.sh
blob426ff098e1dc738a57299a6499bf89174979db37
1 #!/bin/sh
3 test_description='git rebase with its hook(s)'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
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 &&
25 git checkout main &&
26 git log --pretty=oneline --abbrev-commit --graph --all &&
27 git branch test side
30 test_expect_success 'rebase' '
31 git checkout test &&
32 git reset --hard side &&
33 git rebase main &&
34 test "z$(cat git)" = zworld
37 test_expect_success 'rebase -i' '
38 git checkout test &&
39 git reset --hard side &&
40 EDITOR=true git rebase -i main &&
41 test "z$(cat git)" = zworld
44 test_expect_success 'setup pre-rebase hook' '
45 test_hook --setup pre-rebase <<-\EOF
46 echo "$1,$2" >.git/PRE-REBASE-INPUT
47 EOF
50 test_expect_success 'pre-rebase hook gets correct input (1)' '
51 git checkout test &&
52 git reset --hard side &&
53 git rebase main &&
54 test "z$(cat git)" = zworld &&
55 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
59 test_expect_success 'pre-rebase hook gets correct input (2)' '
60 git checkout test &&
61 git reset --hard side &&
62 git rebase main test &&
63 test "z$(cat git)" = zworld &&
64 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
67 test_expect_success 'pre-rebase hook gets correct input (3)' '
68 git checkout test &&
69 git reset --hard side &&
70 git checkout main &&
71 git rebase main test &&
72 test "z$(cat git)" = zworld &&
73 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
76 test_expect_success 'pre-rebase hook gets correct input (4)' '
77 git checkout test &&
78 git reset --hard side &&
79 EDITOR=true git rebase -i main &&
80 test "z$(cat git)" = zworld &&
81 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
85 test_expect_success 'pre-rebase hook gets correct input (5)' '
86 git checkout test &&
87 git reset --hard side &&
88 EDITOR=true git rebase -i main test &&
89 test "z$(cat git)" = zworld &&
90 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
93 test_expect_success 'pre-rebase hook gets correct input (6)' '
94 git checkout test &&
95 git reset --hard side &&
96 git checkout main &&
97 EDITOR=true git rebase -i main test &&
98 test "z$(cat git)" = zworld &&
99 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
102 test_expect_success 'setup pre-rebase hook that fails' '
103 test_hook --setup --clobber pre-rebase <<-\EOF
104 false
108 test_expect_success 'pre-rebase hook stops rebase (1)' '
109 git checkout test &&
110 git reset --hard side &&
111 test_must_fail git rebase main &&
112 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
113 test 0 = $(git rev-list HEAD...side | wc -l) &&
114 test_must_fail git rebase --quit 2>err &&
115 test_grep "no rebase in progress" err
118 test_expect_success 'pre-rebase hook stops rebase (2)' '
119 git checkout test &&
120 git reset --hard side &&
121 test_must_fail env EDITOR=: git rebase -i main &&
122 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
123 test 0 = $(git rev-list HEAD...side | wc -l)
126 test_expect_success 'rebase --no-verify overrides pre-rebase (1)' '
127 git checkout test &&
128 git reset --hard side &&
129 git rebase --no-verify main &&
130 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
131 test "z$(cat git)" = zworld
134 test_expect_success 'rebase --no-verify overrides pre-rebase (2)' '
135 git checkout test &&
136 git reset --hard side &&
137 EDITOR=true git rebase --no-verify -i main &&
138 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
139 test "z$(cat git)" = zworld
142 test_done