t7607: use test-lib functions and check MERGE_HEAD
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>
Clemens Buchacher committed
Oct 10, 2010 at 10:35 UTC
18a1d8953b9ee769761fa6a43c9bd6f76363421f
1 file changed
+15
-23
t/t7607-merge-overwrite.sh
+15
-23
@@ -7,48 +7,38 @@ Do not overwrite changes.'
7
. ./test-lib.sh
8
9
test_expect_success 'setup' '
10
- echo c0 > c0.c &&
11
- git add c0.c &&
12
- git commit -m c0 &&
13
- git tag c0 &&
14
- echo c1 > c1.c &&
15
- git add c1.c &&
16
- git commit -m c1 &&
17
- git tag c1 &&
10
+ test_commit c0 c0.c &&
11
+ test_commit c1 c1.c &&
12
+ test_commit c1a c1.c "c1 a" &&
13
git reset --hard c0 &&
19
- echo c2 > c2.c &&
20
- git add c2.c &&
21
- git commit -m c2 &&
22
- git tag c2 &&
23
- git reset --hard c1 &&
24
- echo "c1 a" > c1.c &&
25
- git add c1.c &&
26
- git commit -m "c1 a" &&
27
- git tag c1a &&
14
+ test_commit c2 c2.c &&
15
echo "VERY IMPORTANT CHANGES" > important
16
'
17
18
test_expect_success 'will not overwrite untracked file' '
19
git reset --hard c1 &&
33
- cat important > c2.c &&
20
+ cp important c2.c &&
21
test_must_fail git merge c2 &&
22
+ test_path_is_missing .git/MERGE_HEAD &&
23
test_cmp important c2.c
24
'
25
26
test_expect_success 'will not overwrite new file' '
27
git reset --hard c1 &&
40
- cat important > c2.c &&
28
+ cp important c2.c &&
29
git add c2.c &&
30
test_must_fail git merge c2 &&
31
+ test_path_is_missing .git/MERGE_HEAD &&
32
test_cmp important c2.c
33
'
34
35
test_expect_success 'will not overwrite staged changes' '
36
git reset --hard c1 &&
48
- cat important > c2.c &&
37
+ cp important c2.c &&
38
git add c2.c &&
39
rm c2.c &&
40
test_must_fail git merge c2 &&
41
+ test_path_is_missing .git/MERGE_HEAD &&
42
git checkout c2.c &&
43
test_cmp important c2.c
44
'
@@ -57,7 +47,7 @@ test_expect_success 'will not overwrite removed file' '
47
git reset --hard c1 &&
48
git rm c1.c &&
49
git commit -m "rm c1.c" &&
60
- cat important > c1.c &&
50
+ cp important c1.c &&
51
test_must_fail git merge c1a &&
52
test_cmp important c1.c
53
'
@@ -66,9 +56,10 @@ test_expect_success 'will not overwrite re-added file' '
56
git reset --hard c1 &&
57
git rm c1.c &&
58
git commit -m "rm c1.c" &&
69
- cat important > c1.c &&
59
+ cp important c1.c &&
60
git add c1.c &&
61
test_must_fail git merge c1a &&
62
+ test_path_is_missing .git/MERGE_HEAD &&
63
test_cmp important c1.c
64
'
65
@@ -76,10 +67,11 @@ test_expect_success 'will not overwrite removed file with staged changes' '
67
git reset --hard c1 &&
68
git rm c1.c &&
69
git commit -m "rm c1.c" &&
79
- cat important > c1.c &&
70
+ cp important c1.c &&
71
git add c1.c &&
72
rm c1.c &&
73
test_must_fail git merge c1a &&
74
+ test_path_is_missing .git/MERGE_HEAD &&
75
git checkout c1.c &&
76
test_cmp important c1.c
77
'