Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rebase with its hook(s)' |
| 4 | |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 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 && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 24 | git checkout main && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 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 && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 32 | git rebase main && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 33 | test "z$(cat git)" = zworld |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'rebase -i' ' |
| 37 | git checkout test && |
| 38 | git reset --hard side && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 39 | EDITOR=true git rebase -i main && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 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 && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 55 | git rebase main && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 56 | test "z$(cat git)" = zworld && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 57 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain, |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 58 | |
| 59 | ' |
| 60 | |
| 61 | test_expect_success 'pre-rebase hook gets correct input (2)' ' |
| 62 | git checkout test && |
| 63 | git reset --hard side && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 64 | git rebase main test && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 65 | test "z$(cat git)" = zworld && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 66 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 67 | ' |
| 68 | |
| 69 | test_expect_success 'pre-rebase hook gets correct input (3)' ' |
| 70 | git checkout test && |
| 71 | git reset --hard side && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 72 | git checkout main && |
| 73 | git rebase main test && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 74 | test "z$(cat git)" = zworld && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 75 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 76 | ' |
| 77 | |
| 78 | test_expect_success 'pre-rebase hook gets correct input (4)' ' |
| 79 | git checkout test && |
| 80 | git reset --hard side && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 81 | EDITOR=true git rebase -i main && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 82 | test "z$(cat git)" = zworld && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 83 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain, |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 84 | |
| 85 | ' |
| 86 | |
| 87 | test_expect_success 'pre-rebase hook gets correct input (5)' ' |
| 88 | git checkout test && |
| 89 | git reset --hard side && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 90 | EDITOR=true git rebase -i main test && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 91 | test "z$(cat git)" = zworld && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 92 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 93 | ' |
| 94 | |
| 95 | test_expect_success 'pre-rebase hook gets correct input (6)' ' |
| 96 | git checkout test && |
| 97 | git reset --hard side && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 98 | git checkout main && |
| 99 | EDITOR=true git rebase -i main test && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 100 | test "z$(cat git)" = zworld && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 101 | test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 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 && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 116 | test_must_fail git rebase main && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 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 && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 124 | test_must_fail env EDITOR=: git rebase -i main && |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 125 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/test && |
| 126 | test 0 = $(git rev-list HEAD...side | wc -l) |
| 127 | ' |
| 128 | |
Nanako Shiraishi | c442765 | 2008-10-06 14:14:29 +0900 | [diff] [blame] | 129 | test_expect_success 'rebase --no-verify overrides pre-rebase (1)' ' |
| 130 | git checkout test && |
| 131 | git reset --hard side && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 132 | git rebase --no-verify main && |
Nanako Shiraishi | c442765 | 2008-10-06 14:14:29 +0900 | [diff] [blame] | 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 && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 140 | EDITOR=true git rebase --no-verify -i main && |
Nanako Shiraishi | c442765 | 2008-10-06 14:14:29 +0900 | [diff] [blame] | 141 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/test && |
| 142 | test "z$(cat git)" = zworld |
| 143 | ' |
| 144 | |
Nanako Shiraishi | d70b4a8 | 2008-10-06 14:14:24 +0900 | [diff] [blame] | 145 | test_done |