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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
#!/bin/sh
#
# Copyright (C) 2013-2014 Felipe Contreras
# Copyright (C) 2013 John Keeping
#
# This file may be used under the terms of the GNU GPL version 2.
#
test_description="Test git reintegrate"
. ./test-lib.sh
test_expect_success 'setup branches' '
git init -q &&
commit_file base base &&
git checkout -b branch1 master &&
commit_file branch1 branch1 &&
git checkout -b branch2 master &&
commit_file branch2 branch2
'
test_expect_success 'create integration branch' '
git checkout master &&
git reintegrate --create pu &&
git reintegrate --cat > actual &&
echo "base master" > expect &&
test_cmp expect actual &&
git symbolic-ref HEAD > actual &&
echo refs/heads/pu > expect &&
test_cmp expect actual
'
write_script .git/EDITOR <<\EOF
#!/bin/sh
cat >> "$1" <<EOM
merge branch1
This merges branch 1.
merge branch2
This merges branch 2.
. branch3
"branch3" is ignored for now.
EOM
EOF
check_int() {
(
local int=$1 IFS=':'
while read branch msg
do
echo "* Merge branch '$branch' into $int$LF"
test "$msg" && echo "$msg$LF" || true
done > expected
) &&
git log --merges --format="* %B" > actual &&
test_cmp expected actual
}
test_expect_success 'add branches to integration branch' '
GIT_EDITOR=".git/EDITOR" git reintegrate --edit &&
git reintegrate --rebuild &&
git merge-base --is-ancestor branch1 HEAD &&
git merge-base --is-ancestor branch2 HEAD &&
test_must_fail git merge-base --is-ancestor branch3 HEAD &&
check_int pu <<-EOF
branch2:This merges branch 2.
branch1:This merges branch 1.
EOF
'
write_script .git/EDITOR <<\EOF
#!/bin/sh
cat >> "$1" <<EOM
merge branch3
This merges branch 3.
EOM
EOF
test_expect_success 'add another branch and rebuild' '
git checkout -b branch3 master &&
commit_file branch3 branch3 &&
GIT_EDITOR=.git/EDITOR git reintegrate --edit pu &&
git reintegrate --rebuild pu &&
git merge-base --is-ancestor branch1 HEAD &&
git merge-base --is-ancestor branch2 HEAD &&
git merge-base --is-ancestor branch3 HEAD &&
check_int pu <<-EOF
branch3:This merges branch 3.
branch2:This merges branch 2.
branch1:This merges branch 1.
EOF
'
test_expect_success 'do not create empty commits' '
git rev-parse --verify refs/int/pu > expect &&
GIT_EDITOR=true git reintegrate --edit &&
git rev-parse --verify refs/int/pu > actual &&
test_cmp expect actual
'
test_expect_success 'generate instructions' '
git init -q tmp &&
test_when_finished "rm -rf tmp" &&
(
cd tmp &&
commit_file base base &&
git checkout -b branch1 master &&
commit_file branch1 branch1 &&
git checkout -b branch2 master &&
commit_file branch2 branch2 &&
git checkout -b branch3 master &&
commit_file branch3 branch3 &&
git checkout -b pu master &&
git merge --no-ff branch1 &&
git merge --no-ff branch2 &&
git merge --no-ff branch3 &&
git checkout branch1 &&
commit_file branch1 branch1-update &&
git reintegrate --generate pu master &&
git reintegrate --cat pu > ../actual
) &&
cat > expected <<-EOF &&
base master
merge branch1~1
merge branch2
merge branch3
EOF
test_cmp expected actual
'
write_script .git/EDITOR <<\EOF
#!/bin/sh
cat >> "$1" <<EOM
commit
Empty commit.
EOM
EOF
test_expect_success 'empty commit' '
GIT_EDITOR=.git/EDITOR git reintegrate --edit pu &&
git reintegrate --rebuild pu &&
git log --format="%B" -1 > actual &&
cat > expected <<-EOF &&
Empty commit.
EOF
test_cmp expected actual
'
write_script .git/EDITOR <<\EOF
#!/bin/sh
cat > "$1" <<EOM
base master
merge branch1
merge branch2
pause
merge branch3
EOM
EOF
test_expect_success 'pause command' '
GIT_EDITOR=.git/EDITOR git reintegrate --edit pu &&
test_must_fail git reintegrate --rebuild pu &&
check_int pu <<-EOF &&
branch2:
branch1:
EOF
git reintegrate --continue &&
check_int pu <<-EOF
branch3:
branch2:
branch1:
EOF
'
test_done
|