Merge c2ebc9532f
into 71e8395ebd
commit
5ef25904dd
|
@ -53,6 +53,10 @@ Some improvement _could_ be made to git's conflict resolving by using a custom g
|
|||
|
||||
An example of this can be found at [balbuf's composer git merge driver](https://github.com/balbuf/composer-git-merge-driver).
|
||||
|
||||
### Handling the trivial case
|
||||
|
||||
In a small number of cases, only the `content-hash` will show as being conflicted as the version control system may be able to cleanly merge the remaining text in the file. This typically happens when two different packages have been added or updated in each side of the merge, with no overlapping nor conflicting dependencies. When this occurs, running `composer update --lock` may be enough to update the lock file.
|
||||
|
||||
## Important considerations
|
||||
|
||||
Keep in mind that whenever merge conflicts occur on the lock file, the information, about the exact version
|
||||
|
|
|
@ -344,6 +344,14 @@ class JsonFile
|
|||
}
|
||||
$data = json_decode($json, true);
|
||||
if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
|
||||
$lines = explode("\n", $json);
|
||||
if (isset($lines[9]) && strpos($lines[9], '"content-hash": "') !== false && strpos($lines[7], '"content-hash": "') !== false) {
|
||||
// We may have found a git merge conflict in composer.lock. Remove the offending lines and try again.
|
||||
unset($lines[6], $lines[7], $lines[9], $lines[10]);
|
||||
$lines[8] = ' "content-hash": "VCS merge conflict detected. Please run `composer update --lock`.",';
|
||||
return self::parseJson(implode("\n", $lines), $file);
|
||||
}
|
||||
|
||||
self::validateSyntax($json, $file);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
<<<<<<< HEAD
|
||||
"content-hash": "e0281a92ffdb4118e47df762a8e80d8d",
|
||||
=======
|
||||
"content-hash": "19ff2417ff3290c12442b3d170de974e",
|
||||
>>>>>>> branch-name
|
||||
"packages": [],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
<<<<<<< HEAD
|
||||
"content-hash": "e0281a92ffdb4118e47df762a8e80d8d",
|
||||
=======
|
||||
"content-hash": "19ff2417ff3290c12442b3d170de974e",
|
||||
>>>>>>> branch-name
|
||||
"packages": [],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
|
@ -364,6 +364,78 @@ class JsonFileTest extends TestCase
|
|||
self::assertEquals($data, $doubleData);
|
||||
}
|
||||
|
||||
public function testComposerLockFileMergeConflictSimple(): void
|
||||
{
|
||||
$data = [
|
||||
'_readme' => [
|
||||
'This file locks the dependencies of your project to a known state',
|
||||
'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies',
|
||||
'This file is @generated automatically',
|
||||
],
|
||||
'content-hash' => 'VCS merge conflict detected. Please run `composer update --lock`.',
|
||||
'packages' => [],
|
||||
'packages-dev' => [],
|
||||
'aliases' => [],
|
||||
'minimum-stability' => "stable",
|
||||
'stability-flags' => [],
|
||||
'prefer-stable' => false,
|
||||
'prefer-lowest' => false,
|
||||
'platform' => [],
|
||||
'platform-dev' => [],
|
||||
'plugin-api-version' => '2.3.0',
|
||||
];
|
||||
|
||||
$json = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-simple.txt');
|
||||
|
||||
$this->assertEquals($data, JsonFile::parseJson($json));
|
||||
}
|
||||
|
||||
public function testComposerLockFileMergeConflictSimpleCRLF(): void
|
||||
{
|
||||
$data = [
|
||||
'_readme' => [
|
||||
'This file locks the dependencies of your project to a known state',
|
||||
'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies',
|
||||
'This file is @generated automatically',
|
||||
],
|
||||
'content-hash' => 'VCS merge conflict detected. Please run `composer update --lock`.',
|
||||
'packages' => [],
|
||||
'packages-dev' => [],
|
||||
'aliases' => [],
|
||||
'minimum-stability' => "stable",
|
||||
'stability-flags' => [],
|
||||
'prefer-stable' => false,
|
||||
'prefer-lowest' => false,
|
||||
'platform' => [],
|
||||
'platform-dev' => [],
|
||||
'plugin-api-version' => '2.3.0',
|
||||
];
|
||||
|
||||
$json = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-simple.txt');
|
||||
|
||||
$this->assertEquals($data, JsonFile::parseJson($json));
|
||||
}
|
||||
|
||||
public function testComposerLockFileMergeConflictComplex(): void
|
||||
{
|
||||
$data = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-complex.txt');
|
||||
|
||||
$this->expectException(ParsingException::class);
|
||||
// We don't care here what the error message says, just that there is an exception thrown.
|
||||
// Other tests verify that the message text is sensible.
|
||||
JsonFile::parseJson($data);
|
||||
}
|
||||
|
||||
public function testComposerLockFileMergeConflictComplexCRLF(): void
|
||||
{
|
||||
$data = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-complex-crlf.txt');
|
||||
|
||||
$this->expectException(ParsingException::class);
|
||||
// We don't care here what the error message says, just that there is an exception thrown.
|
||||
// Other tests verify that the message text is sensible.
|
||||
JsonFile::parseJson($data);
|
||||
}
|
||||
|
||||
public function testPreserveIndentationAfterRead(): void
|
||||
{
|
||||
copy(__DIR__.'/Fixtures/tabs.json', __DIR__.'/Fixtures/tabs2.json');
|
||||
|
|
Loading…
Reference in New Issue