@@ -46,7 +46,170 @@ def test_analysis
46
46
47
47
analysis = repo . merge_analysis ( "branch" )
48
48
assert_equal [ :normal ] , analysis
49
+ end
50
+
51
+ def assert_equal_index ( expected_entries , index )
52
+ expected_entries . each do |mode , oid , stage , path |
53
+ entry = index [ path , stage ]
54
+
55
+ refute_nil entry
56
+ assert_equal mode , entry [ :mode ]
57
+ assert_equal oid , entry [ :oid ]
58
+ end
59
+
60
+ assert_equal expected_entries . count , index . count
61
+ end
62
+
63
+ def test_renames_enabled
64
+ repo = FixtureRepo . from_libgit2 ( "merge-resolve" )
65
+
66
+ ours = repo . rev_parse ( "rename_conflict_ours" )
67
+ theirs = repo . rev_parse ( "rename_conflict_theirs" )
68
+ base = repo . rev_parse ( repo . merge_base ( ours , theirs ) )
69
+
70
+ index = ours . tree . merge ( theirs . tree , base . tree , renames : true )
71
+
72
+ assert_equal_index [
73
+ [ 0100644 , "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e" , 0 , "0a-no-change.txt" ] ,
74
+ [ 0100644 , "f0ce2b8e4986084d9b308fb72709e414c23eb5e6" , 0 , "0b-duplicated-in-ours.txt" ] ,
75
+ [ 0100644 , "f0ce2b8e4986084d9b308fb72709e414c23eb5e6" , 1 , "0b-rewritten-in-ours.txt" ] ,
76
+ [ 0100644 , "e376fbdd06ebf021c92724da9f26f44212734e3e" , 2 , "0b-rewritten-in-ours.txt" ] ,
77
+ [ 0100644 , "b2d399ae15224e1d58066e3c8df70ce37de7a656" , 3 , "0b-rewritten-in-ours.txt" ] ,
78
+ [ 0100644 , "2f56120107d680129a5d9791b521cb1e73a2ed31" , 0 , "0c-duplicated-in-theirs.txt" ] ,
79
+ [ 0100644 , "2f56120107d680129a5d9791b521cb1e73a2ed31" , 1 , "0c-rewritten-in-theirs.txt" ] ,
80
+ [ 0100644 , "efc9121fdedaf08ba180b53ebfbcf71bd488ed09" , 2 , "0c-rewritten-in-theirs.txt" ] ,
81
+ [ 0100644 , "712ebba6669ea847d9829e4f1059d6c830c8b531" , 3 , "0c-rewritten-in-theirs.txt" ] ,
82
+ [ 0100644 , "0d872f8e871a30208305978ecbf9e66d864f1638" , 0 , "1a-newname-in-ours-edited-in-theirs.txt" ] ,
83
+ [ 0100644 , "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb" , 0 , "1a-newname-in-ours.txt" ] ,
84
+ [ 0100644 , "ed9523e62e453e50dd9be1606af19399b96e397a" , 0 , "1b-newname-in-theirs-edited-in-ours.txt" ] ,
85
+ [ 0100644 , "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136" , 0 , "1b-newname-in-theirs.txt" ] ,
86
+ [ 0100644 , "178940b450f238a56c0d75b7955cb57b38191982" , 0 , "2-newname-in-both.txt" ] ,
87
+ [ 0100644 , "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9" , 2 , "3a-newname-in-ours-deleted-in-theirs.txt" ] ,
88
+ [ 0100644 , "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9" , 1 , "3a-renamed-in-ours-deleted-in-theirs.txt" ] ,
89
+ [ 0100644 , "36219b49367146cb2e6a1555b5a9ebd4d0328495" , 3 , "3b-newname-in-theirs-deleted-in-ours.txt" ] ,
90
+ [ 0100644 , "36219b49367146cb2e6a1555b5a9ebd4d0328495" , 1 , "3b-renamed-in-theirs-deleted-in-ours.txt" ] ,
91
+ [ 0100644 , "227792b52aaa0b238bea00ec7e509b02623f168c" , 2 , "4a-newname-in-ours-added-in-theirs.txt" ] ,
92
+ [ 0100644 , "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a" , 3 , "4a-newname-in-ours-added-in-theirs.txt" ] ,
93
+ [ 0100644 , "227792b52aaa0b238bea00ec7e509b02623f168c" , 1 , "4a-renamed-in-ours-added-in-theirs.txt" ] ,
94
+ [ 0100644 , "de872ee3618b894992e9d1e18ba2ebe256a112f9" , 2 , "4b-newname-in-theirs-added-in-ours.txt" ] ,
95
+ [ 0100644 , "98d52d07c0b0bbf2b46548f6aa521295c2cb55db" , 3 , "4b-newname-in-theirs-added-in-ours.txt" ] ,
96
+ [ 0100644 , "98d52d07c0b0bbf2b46548f6aa521295c2cb55db" , 1 , "4b-renamed-in-theirs-added-in-ours.txt" ] ,
97
+ [ 0100644 , "d3719a5ae8e4d92276b5313ce976f6ee5af2b436" , 2 , "5a-newname-in-ours-added-in-theirs.txt" ] ,
98
+ [ 0100644 , "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714" , 3 , "5a-newname-in-ours-added-in-theirs.txt" ] ,
99
+ [ 0100644 , "d3719a5ae8e4d92276b5313ce976f6ee5af2b436" , 1 , "5a-renamed-in-ours-added-in-theirs.txt" ] ,
100
+ [ 0100644 , "d3719a5ae8e4d92276b5313ce976f6ee5af2b436" , 3 , "5a-renamed-in-ours-added-in-theirs.txt" ] ,
101
+ [ 0100644 , "385c8a0f26ddf79e9041e15e17dc352ed2c4cced" , 2 , "5b-newname-in-theirs-added-in-ours.txt" ] ,
102
+ [ 0100644 , "63247125386de9ec90a27ad36169307bf8a11a38" , 3 , "5b-newname-in-theirs-added-in-ours.txt" ] ,
103
+ [ 0100644 , "63247125386de9ec90a27ad36169307bf8a11a38" , 1 , "5b-renamed-in-theirs-added-in-ours.txt" ] ,
104
+ [ 0100644 , "63247125386de9ec90a27ad36169307bf8a11a38" , 2 , "5b-renamed-in-theirs-added-in-ours.txt" ] ,
105
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 2 , "6-both-renamed-1-to-2-ours.txt" ] ,
106
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 3 , "6-both-renamed-1-to-2-theirs.txt" ] ,
107
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 1 , "6-both-renamed-1-to-2.txt" ] ,
108
+ [ 0100644 , "b42712cfe99a1a500b2a51fe984e0b8a7702ba11" , 1 , "7-both-renamed-side-1.txt" ] ,
109
+ [ 0100644 , "b42712cfe99a1a500b2a51fe984e0b8a7702ba11" , 3 , "7-both-renamed-side-1.txt" ] ,
110
+ [ 0100644 , "b69fe837e4cecfd4c9a40cdca7c138468687df07" , 1 , "7-both-renamed-side-2.txt" ] ,
111
+ [ 0100644 , "b69fe837e4cecfd4c9a40cdca7c138468687df07" , 2 , "7-both-renamed-side-2.txt" ] ,
112
+ [ 0100644 , "b42712cfe99a1a500b2a51fe984e0b8a7702ba11" , 2 , "7-both-renamed.txt" ] ,
113
+ [ 0100644 , "b69fe837e4cecfd4c9a40cdca7c138468687df07" , 3 , "7-both-renamed.txt" ] ,
114
+ ] , index
115
+ end
49
116
117
+ def test_renames_disabled
118
+ repo = FixtureRepo . from_libgit2 ( "merge-resolve" )
119
+
120
+ ours = repo . rev_parse ( "rename_conflict_ours" )
121
+ theirs = repo . rev_parse ( "rename_conflict_theirs" )
122
+ base = repo . rev_parse ( repo . merge_base ( ours , theirs ) )
123
+
124
+ index = ours . tree . merge ( theirs . tree , base . tree , renames : false )
125
+
126
+ assert_equal_index [
127
+ [ 0100644 , "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e" , 0 , "0a-no-change.txt" ] ,
128
+ [ 0100644 , "f0ce2b8e4986084d9b308fb72709e414c23eb5e6" , 0 , "0b-duplicated-in-ours.txt" ] ,
129
+ [ 0100644 , "f0ce2b8e4986084d9b308fb72709e414c23eb5e6" , 1 , "0b-rewritten-in-ours.txt" ] ,
130
+ [ 0100644 , "e376fbdd06ebf021c92724da9f26f44212734e3e" , 2 , "0b-rewritten-in-ours.txt" ] ,
131
+ [ 0100644 , "b2d399ae15224e1d58066e3c8df70ce37de7a656" , 3 , "0b-rewritten-in-ours.txt" ] ,
132
+ [ 0100644 , "2f56120107d680129a5d9791b521cb1e73a2ed31" , 0 , "0c-duplicated-in-theirs.txt" ] ,
133
+ [ 0100644 , "2f56120107d680129a5d9791b521cb1e73a2ed31" , 1 , "0c-rewritten-in-theirs.txt" ] ,
134
+ [ 0100644 , "efc9121fdedaf08ba180b53ebfbcf71bd488ed09" , 2 , "0c-rewritten-in-theirs.txt" ] ,
135
+ [ 0100644 , "712ebba6669ea847d9829e4f1059d6c830c8b531" , 3 , "0c-rewritten-in-theirs.txt" ] ,
136
+ [ 0100644 , "c3d02eeef75183df7584d8d13ac03053910c1301" , 0 , "1a-newname-in-ours-edited-in-theirs.txt" ] ,
137
+ [ 0100644 , "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb" , 0 , "1a-newname-in-ours.txt" ] ,
138
+ [ 0100644 , "c3d02eeef75183df7584d8d13ac03053910c1301" , 1 , "1a-renamed-in-ours-edited-in-theirs.txt" ] ,
139
+ [ 0100644 , "0d872f8e871a30208305978ecbf9e66d864f1638" , 3 , "1a-renamed-in-ours-edited-in-theirs.txt" ] ,
140
+ [ 0100644 , "241a1005cd9b980732741b74385b891142bcba28" , 0 , "1b-newname-in-theirs-edited-in-ours.txt" ] ,
141
+ [ 0100644 , "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136" , 0 , "1b-newname-in-theirs.txt" ] ,
142
+ [ 0100644 , "241a1005cd9b980732741b74385b891142bcba28" , 1 , "1b-renamed-in-theirs-edited-in-ours.txt" ] ,
143
+ [ 0100644 , "ed9523e62e453e50dd9be1606af19399b96e397a" , 2 , "1b-renamed-in-theirs-edited-in-ours.txt" ] ,
144
+ [ 0100644 , "178940b450f238a56c0d75b7955cb57b38191982" , 0 , "2-newname-in-both.txt" ] ,
145
+ [ 0100644 , "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9" , 0 , "3a-newname-in-ours-deleted-in-theirs.txt" ] ,
146
+ [ 0100644 , "36219b49367146cb2e6a1555b5a9ebd4d0328495" , 0 , "3b-newname-in-theirs-deleted-in-ours.txt" ] ,
147
+ [ 0100644 , "227792b52aaa0b238bea00ec7e509b02623f168c" , 2 , "4a-newname-in-ours-added-in-theirs.txt" ] ,
148
+ [ 0100644 , "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a" , 3 , "4a-newname-in-ours-added-in-theirs.txt" ] ,
149
+ [ 0100644 , "de872ee3618b894992e9d1e18ba2ebe256a112f9" , 2 , "4b-newname-in-theirs-added-in-ours.txt" ] ,
150
+ [ 0100644 , "98d52d07c0b0bbf2b46548f6aa521295c2cb55db" , 3 , "4b-newname-in-theirs-added-in-ours.txt" ] ,
151
+ [ 0100644 , "d3719a5ae8e4d92276b5313ce976f6ee5af2b436" , 2 , "5a-newname-in-ours-added-in-theirs.txt" ] ,
152
+ [ 0100644 , "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714" , 3 , "5a-newname-in-ours-added-in-theirs.txt" ] ,
153
+ [ 0100644 , "385c8a0f26ddf79e9041e15e17dc352ed2c4cced" , 2 , "5b-newname-in-theirs-added-in-ours.txt" ] ,
154
+ [ 0100644 , "63247125386de9ec90a27ad36169307bf8a11a38" , 3 , "5b-newname-in-theirs-added-in-ours.txt" ] ,
155
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 0 , "6-both-renamed-1-to-2-ours.txt" ] ,
156
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 0 , "6-both-renamed-1-to-2-theirs.txt" ] ,
157
+ [ 0100644 , "b42712cfe99a1a500b2a51fe984e0b8a7702ba11" , 2 , "7-both-renamed.txt" ] ,
158
+ [ 0100644 , "b69fe837e4cecfd4c9a40cdca7c138468687df07" , 3 , "7-both-renamed.txt" ] ,
159
+ ] , index
50
160
end
51
161
162
+ def test_renames_default
163
+ repo = FixtureRepo . from_libgit2 ( "merge-resolve" )
164
+
165
+ ours = repo . rev_parse ( "rename_conflict_ours" )
166
+ theirs = repo . rev_parse ( "rename_conflict_theirs" )
167
+ base = repo . rev_parse ( repo . merge_base ( ours , theirs ) )
168
+
169
+ index = ours . tree . merge ( theirs . tree , base . tree )
170
+
171
+ assert_equal_index [
172
+ [ 0100644 , "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e" , 0 , "0a-no-change.txt" ] ,
173
+ [ 0100644 , "f0ce2b8e4986084d9b308fb72709e414c23eb5e6" , 0 , "0b-duplicated-in-ours.txt" ] ,
174
+ [ 0100644 , "f0ce2b8e4986084d9b308fb72709e414c23eb5e6" , 1 , "0b-rewritten-in-ours.txt" ] ,
175
+ [ 0100644 , "e376fbdd06ebf021c92724da9f26f44212734e3e" , 2 , "0b-rewritten-in-ours.txt" ] ,
176
+ [ 0100644 , "b2d399ae15224e1d58066e3c8df70ce37de7a656" , 3 , "0b-rewritten-in-ours.txt" ] ,
177
+ [ 0100644 , "2f56120107d680129a5d9791b521cb1e73a2ed31" , 0 , "0c-duplicated-in-theirs.txt" ] ,
178
+ [ 0100644 , "2f56120107d680129a5d9791b521cb1e73a2ed31" , 1 , "0c-rewritten-in-theirs.txt" ] ,
179
+ [ 0100644 , "efc9121fdedaf08ba180b53ebfbcf71bd488ed09" , 2 , "0c-rewritten-in-theirs.txt" ] ,
180
+ [ 0100644 , "712ebba6669ea847d9829e4f1059d6c830c8b531" , 3 , "0c-rewritten-in-theirs.txt" ] ,
181
+ [ 0100644 , "0d872f8e871a30208305978ecbf9e66d864f1638" , 0 , "1a-newname-in-ours-edited-in-theirs.txt" ] ,
182
+ [ 0100644 , "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb" , 0 , "1a-newname-in-ours.txt" ] ,
183
+ [ 0100644 , "ed9523e62e453e50dd9be1606af19399b96e397a" , 0 , "1b-newname-in-theirs-edited-in-ours.txt" ] ,
184
+ [ 0100644 , "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136" , 0 , "1b-newname-in-theirs.txt" ] ,
185
+ [ 0100644 , "178940b450f238a56c0d75b7955cb57b38191982" , 0 , "2-newname-in-both.txt" ] ,
186
+ [ 0100644 , "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9" , 2 , "3a-newname-in-ours-deleted-in-theirs.txt" ] ,
187
+ [ 0100644 , "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9" , 1 , "3a-renamed-in-ours-deleted-in-theirs.txt" ] ,
188
+ [ 0100644 , "36219b49367146cb2e6a1555b5a9ebd4d0328495" , 3 , "3b-newname-in-theirs-deleted-in-ours.txt" ] ,
189
+ [ 0100644 , "36219b49367146cb2e6a1555b5a9ebd4d0328495" , 1 , "3b-renamed-in-theirs-deleted-in-ours.txt" ] ,
190
+ [ 0100644 , "227792b52aaa0b238bea00ec7e509b02623f168c" , 2 , "4a-newname-in-ours-added-in-theirs.txt" ] ,
191
+ [ 0100644 , "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a" , 3 , "4a-newname-in-ours-added-in-theirs.txt" ] ,
192
+ [ 0100644 , "227792b52aaa0b238bea00ec7e509b02623f168c" , 1 , "4a-renamed-in-ours-added-in-theirs.txt" ] ,
193
+ [ 0100644 , "de872ee3618b894992e9d1e18ba2ebe256a112f9" , 2 , "4b-newname-in-theirs-added-in-ours.txt" ] ,
194
+ [ 0100644 , "98d52d07c0b0bbf2b46548f6aa521295c2cb55db" , 3 , "4b-newname-in-theirs-added-in-ours.txt" ] ,
195
+ [ 0100644 , "98d52d07c0b0bbf2b46548f6aa521295c2cb55db" , 1 , "4b-renamed-in-theirs-added-in-ours.txt" ] ,
196
+ [ 0100644 , "d3719a5ae8e4d92276b5313ce976f6ee5af2b436" , 2 , "5a-newname-in-ours-added-in-theirs.txt" ] ,
197
+ [ 0100644 , "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714" , 3 , "5a-newname-in-ours-added-in-theirs.txt" ] ,
198
+ [ 0100644 , "d3719a5ae8e4d92276b5313ce976f6ee5af2b436" , 1 , "5a-renamed-in-ours-added-in-theirs.txt" ] ,
199
+ [ 0100644 , "d3719a5ae8e4d92276b5313ce976f6ee5af2b436" , 3 , "5a-renamed-in-ours-added-in-theirs.txt" ] ,
200
+ [ 0100644 , "385c8a0f26ddf79e9041e15e17dc352ed2c4cced" , 2 , "5b-newname-in-theirs-added-in-ours.txt" ] ,
201
+ [ 0100644 , "63247125386de9ec90a27ad36169307bf8a11a38" , 3 , "5b-newname-in-theirs-added-in-ours.txt" ] ,
202
+ [ 0100644 , "63247125386de9ec90a27ad36169307bf8a11a38" , 1 , "5b-renamed-in-theirs-added-in-ours.txt" ] ,
203
+ [ 0100644 , "63247125386de9ec90a27ad36169307bf8a11a38" , 2 , "5b-renamed-in-theirs-added-in-ours.txt" ] ,
204
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 2 , "6-both-renamed-1-to-2-ours.txt" ] ,
205
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 3 , "6-both-renamed-1-to-2-theirs.txt" ] ,
206
+ [ 0100644 , "d8fa77b6833082c1ea36b7828a582d4c43882450" , 1 , "6-both-renamed-1-to-2.txt" ] ,
207
+ [ 0100644 , "b42712cfe99a1a500b2a51fe984e0b8a7702ba11" , 1 , "7-both-renamed-side-1.txt" ] ,
208
+ [ 0100644 , "b42712cfe99a1a500b2a51fe984e0b8a7702ba11" , 3 , "7-both-renamed-side-1.txt" ] ,
209
+ [ 0100644 , "b69fe837e4cecfd4c9a40cdca7c138468687df07" , 1 , "7-both-renamed-side-2.txt" ] ,
210
+ [ 0100644 , "b69fe837e4cecfd4c9a40cdca7c138468687df07" , 2 , "7-both-renamed-side-2.txt" ] ,
211
+ [ 0100644 , "b42712cfe99a1a500b2a51fe984e0b8a7702ba11" , 2 , "7-both-renamed.txt" ] ,
212
+ [ 0100644 , "b69fe837e4cecfd4c9a40cdca7c138468687df07" , 3 , "7-both-renamed.txt" ] ,
213
+ ] , index
214
+ end
52
215
end
0 commit comments