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