blob: dd919100d6848d82833a52fdb9456dcde1c44fbb (
plain)
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
|
#!/bin/sh
test_description='git rebase --root
Tests if git rebase --root --onto <newparent> can rebase the root commit.
'
. ./test-lib.sh
test_expect_success 'prepare repository' '
echo 1 > A &&
git add A &&
git commit -m 1 &&
echo 2 > A &&
git add A &&
git commit -m 2 &&
git symbolic-ref HEAD refs/heads/other &&
rm .git/index &&
echo 3 > B &&
git add B &&
git commit -m 3 &&
echo 1 > A &&
git add A &&
git commit -m 1b &&
echo 4 > B &&
git add B &&
git commit -m 4
'
test_expect_success 'rebase --root expects --onto' '
test_must_fail git rebase --root
'
test_expect_success 'setup pre-rebase hook' '
mkdir -p .git/hooks &&
cat >.git/hooks/pre-rebase <<EOF &&
#!$SHELL_PATH
echo "\$1,\$2" >.git/PRE-REBASE-INPUT
EOF
chmod +x .git/hooks/pre-rebase
'
cat > expect <<EOF
4
3
2
1
EOF
test_expect_success 'rebase --root --onto <newbase>' '
git checkout -b work &&
git rebase --root --onto master &&
git log --pretty=tformat:"%s" > rebased &&
test_cmp expect rebased
'
test_expect_success 'pre-rebase got correct input (1)' '
test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
'
test_expect_success 'rebase --root --onto <newbase> <branch>' '
git branch work2 other &&
git rebase --root --onto master work2 &&
git log --pretty=tformat:"%s" > rebased2 &&
test_cmp expect rebased2
'
test_expect_success 'pre-rebase got correct input (2)' '
test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
'
test_expect_success 'setup pre-rebase hook that fails' '
mkdir -p .git/hooks &&
cat >.git/hooks/pre-rebase <<EOF &&
#!$SHELL_PATH
false
EOF
chmod +x .git/hooks/pre-rebase
'
test_expect_success 'pre-rebase hook stops rebase' '
git checkout -b stops1 other &&
GIT_EDITOR=: test_must_fail git rebase --root --onto master &&
test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
test 0 = $(git rev-list other...stops1 | wc -l)
'
test_done
|