Skip to content

Commit

Permalink
t3507: introduce pristine-detach helper
Browse files Browse the repository at this point in the history
All the tests in t3507 (cherry-pick with conflicts) begin with the
same checkout + read-tree + clean incantation to ensure a predictable
starting point.  Factor out a function for that so the interesting
part of the tests is easier to read.

The "update-index --refresh" and "diff-index --exit-code HEAD" are not
necessary as the point of this testsuite is not about testing
"read-tree --reset".

Improved-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Feb 22, 2011
1 parent 7ed863a commit 2161da1
Showing 1 changed file with 22 additions and 54 deletions.
76 changes: 22 additions & 54 deletions t/t3507-cherry-pick-conflict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ test_description='test cherry-pick and revert with conflicts

. ./test-lib.sh

test_cmp_rev () {
git rev-parse --verify "$1" >expect.rev &&
git rev-parse --verify "$2" >actual.rev &&
test_cmp expect.rev actual.rev
}

pristine_detach () {
git checkout -f "$1^0" &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x
}

test_expect_success setup '
echo unrelated >unrelated &&
Expand All @@ -23,13 +35,7 @@ test_expect_success setup '
'

test_expect_success 'failed cherry-pick does not advance HEAD' '
git checkout -f initial^0 &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
git update-index --refresh &&
git diff-index --exit-code HEAD &&
pristine_detach initial &&
head=$(git rev-parse HEAD) &&
test_must_fail git cherry-pick picked &&
Expand All @@ -39,12 +45,7 @@ test_expect_success 'failed cherry-pick does not advance HEAD' '
'

test_expect_success 'advice from failed cherry-pick' "
git checkout -f initial^0 &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
git update-index --refresh &&
git diff-index --exit-code HEAD &&
pristine_detach initial &&
picked=\$(git rev-parse --short picked) &&
cat <<-EOF >expected &&
Expand All @@ -59,13 +60,7 @@ test_expect_success 'advice from failed cherry-pick' "
"

test_expect_success 'failed cherry-pick produces dirty index' '
git checkout -f initial^0 &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
git update-index --refresh &&
git diff-index --exit-code HEAD &&
pristine_detach initial &&
test_must_fail git cherry-pick picked &&
Expand All @@ -74,9 +69,7 @@ test_expect_success 'failed cherry-pick produces dirty index' '
'

test_expect_success 'failed cherry-pick registers participants in index' '
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
pristine_detach initial &&
{
git checkout base -- foo &&
git ls-files --stage foo &&
Expand All @@ -90,10 +83,7 @@ test_expect_success 'failed cherry-pick registers participants in index' '
2 s/ 0 / 2 /
3 s/ 0 / 3 /
" < stages > expected &&
git checkout -f initial^0 &&
git update-index --refresh &&
git diff-index --exit-code HEAD &&
git read-tree -u --reset HEAD &&
test_must_fail git cherry-pick picked &&
git ls-files --stage --unmerged > actual &&
Expand All @@ -102,10 +92,7 @@ test_expect_success 'failed cherry-pick registers participants in index' '
'

test_expect_success 'failed cherry-pick describes conflict in work tree' '
git checkout -f initial^0 &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
pristine_detach initial &&
cat <<-EOF > expected &&
<<<<<<< HEAD
a
Expand All @@ -114,21 +101,15 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' '
>>>>>>> objid picked
EOF
git update-index --refresh &&
git diff-index --exit-code HEAD &&
test_must_fail git cherry-pick picked &&
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
test_cmp expected actual
'

test_expect_success 'diff3 -m style' '
pristine_detach initial &&
git config merge.conflictstyle diff3 &&
git checkout -f initial^0 &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
cat <<-EOF > expected &&
<<<<<<< HEAD
a
Expand All @@ -139,20 +120,15 @@ test_expect_success 'diff3 -m style' '
>>>>>>> objid picked
EOF
git update-index --refresh &&
git diff-index --exit-code HEAD &&
test_must_fail git cherry-pick picked &&
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
test_cmp expected actual
'

test_expect_success 'revert also handles conflicts sanely' '
git config --unset merge.conflictstyle &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
pristine_detach initial &&
cat <<-EOF > expected &&
<<<<<<< HEAD
a
Expand All @@ -173,10 +149,7 @@ test_expect_success 'revert also handles conflicts sanely' '
2 s/ 0 / 2 /
3 s/ 0 / 3 /
" < stages > expected-stages &&
git checkout -f initial^0 &&
git update-index --refresh &&
git diff-index --exit-code HEAD &&
git read-tree -u --reset HEAD &&
head=$(git rev-parse HEAD) &&
test_must_fail git revert picked &&
Expand All @@ -192,10 +165,8 @@ test_expect_success 'revert also handles conflicts sanely' '
'

test_expect_success 'revert conflict, diff3 -m style' '
pristine_detach initial &&
git config merge.conflictstyle diff3 &&
git checkout -f initial^0 &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
cat <<-EOF > expected &&
<<<<<<< HEAD
a
Expand All @@ -206,9 +177,6 @@ test_expect_success 'revert conflict, diff3 -m style' '
>>>>>>> parent of objid picked
EOF
git update-index --refresh &&
git diff-index --exit-code HEAD &&
test_must_fail git revert picked &&
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
Expand Down

0 comments on commit 2161da1

Please sign in to comment.