Skip to content

Commit

Permalink
t7607: use test-lib functions and check MERGE_HEAD
Browse files Browse the repository at this point in the history
Use the test_commit and test_path_is_missing
functions from the test library.

Also make sure that a merge which fails due to
pre-merge checks aborts properly and does not
leave MERGE_HEAD behind.

The "will not overwrite removed file" test is an
exception to this. It notices the untracked file
at a stage where the merge is already well under
way. Therefore we cannot abort the merge without
major restructuring. See the following thread for
more details.

http://mid.gmane.org/7vskopwxej.fsf@gitster.siamese.dyndns.org

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Clemens Buchacher authored and Junio C Hamano committed Dec 14, 2010
1 parent 40d675f commit 18a1d89
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions t/t7607-merge-overwrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,38 @@ Do not overwrite changes.'
. ./test-lib.sh

test_expect_success 'setup' '
echo c0 > c0.c &&
git add c0.c &&
git commit -m c0 &&
git tag c0 &&
echo c1 > c1.c &&
git add c1.c &&
git commit -m c1 &&
git tag c1 &&
test_commit c0 c0.c &&
test_commit c1 c1.c &&
test_commit c1a c1.c "c1 a" &&
git reset --hard c0 &&
echo c2 > c2.c &&
git add c2.c &&
git commit -m c2 &&
git tag c2 &&
git reset --hard c1 &&
echo "c1 a" > c1.c &&
git add c1.c &&
git commit -m "c1 a" &&
git tag c1a &&
test_commit c2 c2.c &&
echo "VERY IMPORTANT CHANGES" > important
'

test_expect_success 'will not overwrite untracked file' '
git reset --hard c1 &&
cat important > c2.c &&
cp important c2.c &&
test_must_fail git merge c2 &&
test_path_is_missing .git/MERGE_HEAD &&
test_cmp important c2.c
'

test_expect_success 'will not overwrite new file' '
git reset --hard c1 &&
cat important > c2.c &&
cp important c2.c &&
git add c2.c &&
test_must_fail git merge c2 &&
test_path_is_missing .git/MERGE_HEAD &&
test_cmp important c2.c
'

test_expect_success 'will not overwrite staged changes' '
git reset --hard c1 &&
cat important > c2.c &&
cp important c2.c &&
git add c2.c &&
rm c2.c &&
test_must_fail git merge c2 &&
test_path_is_missing .git/MERGE_HEAD &&
git checkout c2.c &&
test_cmp important c2.c
'
Expand All @@ -57,7 +47,7 @@ test_expect_success 'will not overwrite removed file' '
git reset --hard c1 &&
git rm c1.c &&
git commit -m "rm c1.c" &&
cat important > c1.c &&
cp important c1.c &&
test_must_fail git merge c1a &&
test_cmp important c1.c
'
Expand All @@ -66,20 +56,22 @@ test_expect_success 'will not overwrite re-added file' '
git reset --hard c1 &&
git rm c1.c &&
git commit -m "rm c1.c" &&
cat important > c1.c &&
cp important c1.c &&
git add c1.c &&
test_must_fail git merge c1a &&
test_path_is_missing .git/MERGE_HEAD &&
test_cmp important c1.c
'

test_expect_success 'will not overwrite removed file with staged changes' '
git reset --hard c1 &&
git rm c1.c &&
git commit -m "rm c1.c" &&
cat important > c1.c &&
cp important c1.c &&
git add c1.c &&
rm c1.c &&
test_must_fail git merge c1a &&
test_path_is_missing .git/MERGE_HEAD &&
git checkout c1.c &&
test_cmp important c1.c
'
Expand Down

0 comments on commit 18a1d89

Please sign in to comment.