Raw
1 #!/bin/sh
2
3 test_description="merge cases"
4
5 # The setup for all of them, pictorially, is:
6 #
7 # A
8 # o
9 # / \
10 # O o ?
11 # \ /
12 # o
13 # B
14 #
15 # To help make it easier to follow the flow of tests, they have been
16 # divided into sections and each test will start with a quick explanation
17 # of what commits O, A, and B contain.
18 #
19 # Notation:
20 # z/{b,c} means files z/b and z/c both exist
21 # x/d_1 means file x/d exists with content d1. (Purpose of the
22 # underscore notation is to differentiate different
23 # files that might be renamed into each other's paths.)
24
25 . ./test-lib.sh
26
27 # Testcase basic, conflicting changes in 'numerals'
28
29 test_setup_numerals () {
30 git init numerals_$1 &&
31 (
32 cd numerals_$1 &&
33
34 >README &&
35 test_write_lines I II III >numerals &&
36 git add README numerals &&
37 test_tick &&
38 git commit -m "O" &&
39
40 git branch O &&
41 git branch A &&
42 git branch B &&
43
44 git checkout A &&
45 test_write_lines I II III IIII >numerals &&
46 git add numerals &&
47 test_tick &&
48 git commit -m "A" &&
49
50 git checkout B &&
51 test_write_lines I II III IV >numerals &&
52 git add numerals &&
53 test_tick &&
54 git commit -m "B" &&
55
56 cat <<-EOF >expected-index &&
57 H README
58 M numerals
59 M numerals
60 M numerals
61 EOF
62
63 cat <<-EOF >expected-merge
64 I
65 II
66 III
67 <<<<<<< HEAD
68 IIII
69 =======
70 IV
71 >>>>>>> B^0
72 EOF
73
74 )
75 }
76
77 test_expect_success 'conflicting entries written to worktree even if sparse' '
78 test_setup_numerals plain &&
79 (
80 cd numerals_plain &&
81
82 git checkout A^0 &&
83
84 test_path_is_file README &&
85 test_path_is_file numerals &&
86
87 git sparse-checkout init &&
88 git sparse-checkout set --no-cone README &&
89
90 test_path_is_file README &&
91 test_path_is_missing numerals &&
92
93 test_must_fail git merge -s recursive B^0 &&
94
95 git ls-files -t >index_files &&
96 test_cmp expected-index index_files &&
97
98 test_path_is_file README &&
99 test_path_is_file numerals &&
100
101 test_cmp expected-merge numerals &&
102
103 # 4 other files:
104 # * expected-merge
105 # * expected-index
106 # * index_files
107 # * others
108 git ls-files -o >others &&
109 test_line_count = 4 others
110 )
111 '
112
113 test_expect_success 'present-despite-SKIP_WORKTREE handled reasonably' '
114 test_setup_numerals in_the_way &&
115 (
116 cd numerals_in_the_way &&
117
118 git checkout A^0 &&
119
120 test_path_is_file README &&
121 test_path_is_file numerals &&
122
123 git sparse-checkout init &&
124 git sparse-checkout set --no-cone README &&
125
126 test_path_is_file README &&
127 test_path_is_missing numerals &&
128
129 echo foobar >numerals &&
130
131 test_must_fail git merge -s recursive B^0 &&
132
133 test_path_is_missing .git/MERGE_HEAD &&
134
135 test_path_is_file numerals &&
136
137 # numerals should still have "foobar" in it
138 echo foobar >expect &&
139 test_cmp expect numerals
140 )
141 '
142
143 test_done