3 test_description
='git-merge
5 Do not overwrite changes.'
9 test_expect_success
'setup' '
18 git reset --hard c0 &&
23 git reset --hard c1 &&
26 git commit -m "c1 a" &&
28 echo "VERY IMPORTANT CHANGES" > important
31 test_expect_success
'will not overwrite untracked file' '
32 git reset --hard c1 &&
33 cat important > c2.c &&
34 test_must_fail git merge c2 &&
35 test_cmp important c2.c
38 test_expect_success
'will not overwrite new file' '
39 git reset --hard c1 &&
40 cat important > c2.c &&
42 test_must_fail git merge c2 &&
43 test_cmp important c2.c
46 test_expect_success
'will not overwrite staged changes' '
47 git reset --hard c1 &&
48 cat important > c2.c &&
51 test_must_fail git merge c2 &&
53 test_cmp important c2.c
56 test_expect_success
'will not overwrite removed file' '
57 git reset --hard c1 &&
59 git commit -m "rm c1.c" &&
60 cat important > c1.c &&
61 test_must_fail git merge c1a &&
62 test_cmp important c1.c
65 test_expect_success
'will not overwrite re-added file' '
66 git reset --hard c1 &&
68 git commit -m "rm c1.c" &&
69 cat important > c1.c &&
71 test_must_fail git merge c1a &&
72 test_cmp important c1.c
75 test_expect_success
'will not overwrite removed file with staged changes' '
76 git reset --hard c1 &&
78 git commit -m "rm c1.c" &&
79 cat important > c1.c &&
82 test_must_fail git merge c1a &&
84 test_cmp important c1.c
88 error
: Untracked working tree
file 'c0.c' would be overwritten by merge.
89 fatal
: read-tree failed
92 test_expect_success
'will not overwrite untracked file on unborn branch' '
93 git reset --hard c0 &&
95 git checkout --orphan new &&
97 test_must_fail git merge c0 2>out &&
98 test_cmp out expect &&
99 test_path_is_missing .git/MERGE_HEAD &&
100 test_cmp important c0.c