10
10
11
11
namespace PhpMerge ;
12
12
13
- use GitWrapper \GitWrapper ;
14
- use GitWrapper \GitException ;
13
+ use Symplify \ GitWrapper \GitWrapper ;
14
+ use Symplify \ GitWrapper \ Exception \GitException ;
15
15
use PhpMerge \internal \Line ;
16
16
use PhpMerge \internal \Hunk ;
17
17
use PhpMerge \internal \PhpMergeBase ;
@@ -40,20 +40,20 @@ final class GitMerge extends PhpMergeBase implements PhpMergeInterface
40
40
/**
41
41
* The git working directory.
42
42
*
43
- * @var \GitWrapper\GitWorkingCopy
43
+ * @var \Symplify\ GitWrapper\GitWorkingCopy|null
44
44
*/
45
45
protected $ git ;
46
46
47
47
/**
48
48
* The git wrapper to use for merging.
49
49
*
50
- * @var \GitWrapper\GitWrapper
50
+ * @var \Symplify\ GitWrapper\GitWrapper
51
51
*/
52
52
protected $ wrapper ;
53
53
54
54
/**
55
55
* The temporary directory in which git can work.
56
- * @var string
56
+ * @var string|null
57
57
*/
58
58
protected $ dir ;
59
59
@@ -154,14 +154,15 @@ protected function mergeFile(string $file, string $base, string $remote, string
154
154
*/
155
155
protected static function getConflicts ($ file , $ baseText , $ remoteText , $ localText , &$ conflicts , &$ merged )
156
156
{
157
+ $ content = file_get_contents ($ file );
157
158
$ raw = new \ArrayObject (self ::splitStringByLines (file_get_contents ($ file )));
158
159
$ lineIterator = $ raw ->getIterator ();
159
160
$ state = 'unchanged ' ;
160
161
$ conflictIndicator = [
161
- '<<<<<<< HEAD ' => 'local ' ,
162
- '||||||| merged common ancestors ' => 'base ' ,
162
+ '<<<<<<< ' => 'local ' ,
163
+ '||||||| ' => 'base ' ,
163
164
'======= ' => 'remote ' ,
164
- '>>>>>>> original ' => 'end conflict ' ,
165
+ '>>>>>>> ' => 'end conflict ' ,
165
166
];
166
167
167
168
// Create hunks from the text diff.
@@ -185,9 +186,10 @@ protected static function getConflicts($file, $baseText, $remoteText, $localText
185
186
// Loop over all the lines in the file.
186
187
while ($ lineIterator ->valid ()) {
187
188
$ line = $ lineIterator ->current ();
188
- if (array_key_exists (trim ($ line ), $ conflictIndicator )) {
189
+ $ gitKey = substr (trim ($ line ), 0 , 7 );
190
+ if (array_key_exists ($ gitKey , $ conflictIndicator )) {
189
191
// Check for a line matching a conflict indicator.
190
- $ state = $ conflictIndicator [trim ( $ line ) ];
192
+ $ state = $ conflictIndicator [$ gitKey ];
191
193
$ skipedLines ++;
192
194
if ($ state == 'end conflict ' ) {
193
195
// We just treated a merge conflict.
@@ -234,9 +236,9 @@ protected static function getConflicts($file, $baseText, $remoteText, $localText
234
236
}
235
237
$ merged [] = $ line ;
236
238
237
- /** @var Hunk $r */
239
+ /** @var Hunk|null $r */
238
240
$ r = $ remoteIterator ->current ();
239
- /** @var Hunk $l */
241
+ /** @var Hunk|null $l */
240
242
$ l = $ localIterator ->current ();
241
243
242
244
if ($ r == $ l ) {
@@ -247,7 +249,7 @@ protected static function getConflicts($file, $baseText, $remoteText, $localText
247
249
248
250
// A hunk has been successfully merged, so we can just
249
251
// tally the lines added and removed and skip forward.
250
- if ($ r && $ r ->getStart () == $ lineNumber ) {
252
+ if (! is_null ( $ r ) && $ r ->getStart () == $ lineNumber ) {
251
253
if (!$ r ->hasIntersection ($ l )) {
252
254
$ lineNumber += count ($ r ->getRemovedLines ());
253
255
$ newLine += count ($ r ->getAddedLines ());
@@ -263,7 +265,7 @@ protected static function getConflicts($file, $baseText, $remoteText, $localText
263
265
$ newLine ++;
264
266
}
265
267
}
266
- } elseif ($ l && $ l ->getStart () == $ lineNumber ) {
268
+ } elseif (! is_null ( $ l ) && $ l ->getStart () == $ lineNumber ) {
267
269
if (!$ l ->hasIntersection ($ r )) {
268
270
$ lineNumber += count ($ l ->getRemovedLines ());
269
271
$ newLine += count ($ l ->getAddedLines ());
@@ -329,12 +331,12 @@ protected static function fixLastLine(array $lines, array $all): array
329
331
/**
330
332
* Constructor, not setting anything up.
331
333
*
332
- * @param \GitWrapper\GitWrapper $wrapper
334
+ * @param \Symplify\ GitWrapper\GitWrapper|null $wrapper
333
335
*/
334
336
public function __construct (GitWrapper $ wrapper = null )
335
337
{
336
338
if (!$ wrapper ) {
337
- $ wrapper = new GitWrapper ();
339
+ $ wrapper = new GitWrapper (' git ' );
338
340
}
339
341
$ this ->wrapper = $ wrapper ;
340
342
$ this ->conflict = '' ;
@@ -369,7 +371,7 @@ protected function setup()
369
371
*/
370
372
protected function cleanup ()
371
373
{
372
- if (is_dir ($ this ->dir )) {
374
+ if (isset ( $ this -> dir ) && is_dir ($ this ->dir )) {
373
375
// Recursively delete all files and folders.
374
376
$ files = new \RecursiveIteratorIterator (
375
377
new \RecursiveDirectoryIterator ($ this ->dir , \RecursiveDirectoryIterator::SKIP_DOTS ),
0 commit comments