Merge branch 'cb/maint-orphan-merge-noclobber'
[git/kirr.git] / t / t7607-merge-overwrite.sh
blob3988900fc33f0f5f9cdd416096df619aec2d577e
1 #!/bin/sh
3 test_description='git-merge
5 Do not overwrite changes.'
7 . ./test-lib.sh
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 &&
18 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 &&
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 &&
41 git add 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 &&
49 git add c2.c &&
50 rm c2.c &&
51 test_must_fail git merge c2 &&
52 git checkout c2.c &&
53 test_cmp important c2.c
56 test_expect_success 'will not overwrite removed file' '
57 git reset --hard c1 &&
58 git rm c1.c &&
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 &&
67 git rm c1.c &&
68 git commit -m "rm c1.c" &&
69 cat important > c1.c &&
70 git add 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 &&
77 git rm c1.c &&
78 git commit -m "rm c1.c" &&
79 cat important > c1.c &&
80 git add c1.c &&
81 rm c1.c &&
82 test_must_fail git merge c1a &&
83 git checkout c1.c &&
84 test_cmp important c1.c
87 cat >expect <<\EOF
88 error: Untracked working tree file 'c0.c' would be overwritten by merge.
89 fatal: read-tree failed
90 EOF
92 test_expect_success 'will not overwrite untracked file on unborn branch' '
93 git reset --hard c0 &&
94 git rm -fr . &&
95 git checkout --orphan new &&
96 cp important c0.c &&
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
103 test_done