Merge branch 'rl/show-empty-prefix' into maint
[git/mingw/j6t.git] / t / t7607-merge-overwrite.sh
blobaa74184c31cd6b2bd2e0e566e6805e60eed7aff8
1 #!/bin/sh
3 test_description='git-merge
5 Do not overwrite changes.'
7 . ./test-lib.sh
9 test_expect_success 'setup' '
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 &&
14 test_commit c2 c2.c &&
15 git reset --hard c0 &&
16 mkdir sub &&
17 echo "sub/f" > sub/f &&
18 mkdir sub2 &&
19 echo "sub2/f" > sub2/f &&
20 git add sub/f sub2/f &&
21 git commit -m sub &&
22 git tag sub &&
23 echo "VERY IMPORTANT CHANGES" > important
26 test_expect_success 'will not overwrite untracked file' '
27 git reset --hard c1 &&
28 cp important c2.c &&
29 test_must_fail git merge c2 &&
30 test_path_is_missing .git/MERGE_HEAD &&
31 test_cmp important c2.c
34 test_expect_success 'will overwrite tracked file' '
35 git reset --hard c1 &&
36 cp important c2.c &&
37 git add c2.c &&
38 git commit -m important &&
39 git checkout c2
42 test_expect_success 'will not overwrite new file' '
43 git reset --hard c1 &&
44 cp important c2.c &&
45 git add c2.c &&
46 test_must_fail git merge c2 &&
47 test_path_is_missing .git/MERGE_HEAD &&
48 test_cmp important c2.c
51 test_expect_success 'will not overwrite staged changes' '
52 git reset --hard c1 &&
53 cp important c2.c &&
54 git add c2.c &&
55 rm c2.c &&
56 test_must_fail git merge c2 &&
57 test_path_is_missing .git/MERGE_HEAD &&
58 git checkout c2.c &&
59 test_cmp important c2.c
62 test_expect_success 'will not overwrite removed file' '
63 git reset --hard c1 &&
64 git rm c1.c &&
65 git commit -m "rm c1.c" &&
66 cp important c1.c &&
67 test_must_fail git merge c1a &&
68 test_cmp important c1.c
71 test_expect_success 'will not overwrite re-added file' '
72 git reset --hard c1 &&
73 git rm c1.c &&
74 git commit -m "rm c1.c" &&
75 cp important c1.c &&
76 git add c1.c &&
77 test_must_fail git merge c1a &&
78 test_path_is_missing .git/MERGE_HEAD &&
79 test_cmp important c1.c
82 test_expect_success 'will not overwrite removed file with staged changes' '
83 git reset --hard c1 &&
84 git rm c1.c &&
85 git commit -m "rm c1.c" &&
86 cp important c1.c &&
87 git add c1.c &&
88 rm c1.c &&
89 test_must_fail git merge c1a &&
90 test_path_is_missing .git/MERGE_HEAD &&
91 git checkout c1.c &&
92 test_cmp important c1.c
95 test_expect_success 'will not overwrite untracked subtree' '
96 git reset --hard c0 &&
97 rm -rf sub &&
98 mkdir -p sub/f &&
99 cp important sub/f/important &&
100 test_must_fail git merge sub &&
101 test_path_is_missing .git/MERGE_HEAD &&
102 test_cmp important sub/f/important
105 cat >expect <<\EOF
106 error: The following untracked working tree files would be overwritten by merge:
108 sub2
109 Please move or remove them before you can merge.
110 Aborting
113 test_expect_success 'will not overwrite untracked file in leading path' '
114 git reset --hard c0 &&
115 rm -rf sub &&
116 cp important sub &&
117 cp important sub2 &&
118 test_must_fail git merge sub 2>out &&
119 test_cmp out expect &&
120 test_path_is_missing .git/MERGE_HEAD &&
121 test_cmp important sub &&
122 test_cmp important sub2 &&
123 rm -f sub sub2
126 test_expect_success SYMLINKS 'will not overwrite untracked symlink in leading path' '
127 git reset --hard c0 &&
128 rm -rf sub &&
129 mkdir sub2 &&
130 ln -s sub2 sub &&
131 test_must_fail git merge sub &&
132 test_path_is_missing .git/MERGE_HEAD
135 test_expect_success SYMLINKS 'will not be confused by symlink in leading path' '
136 git reset --hard c0 &&
137 rm -rf sub &&
138 ln -s sub2 sub &&
139 git add sub &&
140 git commit -m ln &&
141 git checkout sub
144 cat >expect <<\EOF
145 error: Untracked working tree file 'c0.c' would be overwritten by merge.
146 fatal: read-tree failed
149 test_expect_success 'will not overwrite untracked file on unborn branch' '
150 git reset --hard c0 &&
151 git rm -fr . &&
152 git checkout --orphan new &&
153 cp important c0.c &&
154 test_must_fail git merge c0 2>out &&
155 test_i18ncmp out expect
158 test_expect_success 'will not overwrite untracked file on unborn branch .git/MERGE_HEAD sanity etc.' '
159 test_when_finished "rm c0.c" &&
160 test_path_is_missing .git/MERGE_HEAD &&
161 test_cmp important c0.c
164 test_expect_success 'failed merge leaves unborn branch in the womb' '
165 test_must_fail git rev-parse --verify HEAD
168 test_expect_success 'set up unborn branch and content' '
169 git symbolic-ref HEAD refs/heads/unborn &&
170 rm -f .git/index &&
171 echo foo > tracked-file &&
172 git add tracked-file &&
173 echo bar > untracked-file
176 test_expect_success 'will not clobber WT/index when merging into unborn' '
177 git merge master &&
178 grep foo tracked-file &&
179 git show :tracked-file >expect &&
180 grep foo expect &&
181 grep bar untracked-file
184 test_done