@@ -126,8 +126,8 @@ function merge($ancestor, $ours, $theirs) {
126
126
foreach ($ merged [$ key ] as $ package ) {
127
127
// if we have a conflict, convert the conflicting values back to package definition arrays
128
128
if (preg_match ('/^ ' . CONFLICT_PLACEHOLDER . '$/ ' , $ package , $ matches )) {
129
- $ conflicts [$ matches [1 ]] = array_map (function ($ json ) {
130
- return json_decode ($ json , true );
129
+ $ conflicts [$ matches [1 ]] = array_map (function ($ json ) use ( $ void ) {
130
+ return $ json === $ void ? $ void : json_decode ($ json , true );
131
131
}, $ conflicts [$ matches [1 ]]);
132
132
$ packageArray [] = $ package ;
133
133
}
@@ -150,14 +150,25 @@ function merge($ancestor, $ours, $theirs) {
150
150
151
151
// if we have conflicts, replace the conflict markers with the actual conflicting values
152
152
if (count ($ conflicts )) {
153
- $ merged = preg_replace_callback ('/^(\s+)(.+)" ' . CONFLICT_PLACEHOLDER . '"(,?)$/m ' , function ($ matches ) use ($ conflicts , $ markerLen ) {
153
+ $ merged = preg_replace_callback ('/^(\s+)(.+)" ' . CONFLICT_PLACEHOLDER . '"(,?)$/m ' , function ($ matches ) use ($ conflicts , $ markerLen, $ void ) {
154
154
list (, $ space , $ property , $ conflictNum , $ comma ) = $ matches ;
155
- // replace the conflict placeholder with theirs/ours values surrounded by conflict markers
156
- return str_repeat ('< ' , $ markerLen ) . " HEAD \n"
157
- . $ space . $ property . preg_replace ('/\n/ ' , "\n$ space " , json_encode ($ conflicts [$ conflictNum ][1 ], JSON_ENCODE_OPTIONS )) . $ comma . "\n"
158
- . str_repeat ('= ' , $ markerLen ) . "\n"
159
- . $ space . $ property . preg_replace ('/\n/ ' , "\n$ space " , json_encode ($ conflicts [$ conflictNum ][0 ], JSON_ENCODE_OPTIONS )) . $ comma . "\n"
160
- . str_repeat ('> ' , $ markerLen );
155
+ // build the replacement
156
+ $ parts = [];
157
+ // add opening conflict marker
158
+ $ parts [] = str_repeat ('< ' , $ markerLen ) . ' HEAD ' ;
159
+ // add their value, if not void
160
+ if ($ conflicts [$ conflictNum ][1 ] !== $ void ) {
161
+ $ parts [] = $ space . $ property . preg_replace ('/\n/ ' , "\n$ space " , json_encode ($ conflicts [$ conflictNum ][1 ], JSON_ENCODE_OPTIONS )) . $ comma ;
162
+ }
163
+ // add conflict marker divider
164
+ $ parts [] = str_repeat ('= ' , $ markerLen );
165
+ // add our value, if not void
166
+ if ($ conflicts [$ conflictNum ][0 ] !== $ void ) {
167
+ $ parts [] = $ space . $ property . preg_replace ('/\n/ ' , "\n$ space " , json_encode ($ conflicts [$ conflictNum ][0 ], JSON_ENCODE_OPTIONS )) . $ comma ;
168
+ }
169
+ // add closing conflict marker
170
+ $ parts [] = str_repeat ('> ' , $ markerLen );
171
+ return implode ("\n" , $ parts );
161
172
}, $ merged );
162
173
}
163
174
0 commit comments