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
11 test_expect_success setup
'
15 git commit -m initial &&
19 git commit -m second &&
20 git checkout -b side HEAD^ &&
26 git log --pretty=oneline --abbrev-commit --graph --all &&
30 test_expect_success
'rebase' '
32 git reset --hard side &&
34 test "z$(cat git)" = zworld
37 test_expect_success
'rebase -i' '
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
50 test_expect_success
'pre-rebase hook gets correct input (1)' '
52 git reset --hard side &&
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)' '
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)' '
69 git reset --hard side &&
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)' '
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)' '
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)' '
95 git reset --hard side &&
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
108 test_expect_success
'pre-rebase hook stops rebase (1)' '
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)' '
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)' '
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)' '
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