builtin/show: do not prune by pathspec
[git/mjg.git] / t / t3413-rebase-hook.sh
blobe8456831e8ba1a3ff2009ff6339459f6c00055da
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)
116 test_expect_success 'pre-rebase hook stops rebase (2)' '
117 git checkout test &&
118 git reset --hard side &&
119 test_must_fail env EDITOR=: git rebase -i main &&
120 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
121 test 0 = $(git rev-list HEAD...side | wc -l)
124 test_expect_success 'rebase --no-verify overrides pre-rebase (1)' '
125 git checkout test &&
126 git reset --hard side &&
127 git rebase --no-verify main &&
128 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
129 test "z$(cat git)" = zworld
132 test_expect_success 'rebase --no-verify overrides pre-rebase (2)' '
133 git checkout test &&
134 git reset --hard side &&
135 EDITOR=true git rebase --no-verify -i main &&
136 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
137 test "z$(cat git)" = zworld
140 test_done