Skip to content

Commit ff40569

Browse files
committed
MC-37324: Add fallback to 'patch' command when 'git' command is not available
- Remove formatErrorOutput
1 parent 6cbccf8 commit ff40569

File tree

12 files changed

+10
-88
lines changed

12 files changed

+10
-88
lines changed

src/Command/Process/Action/RevertAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private function printPatchRevertingFailed(OutputInterface $output, PatchInterfa
179179
'Reverting patch %s (%s) failed.%s',
180180
$patch->getId(),
181181
$patch->getPath(),
182-
$this->renderer->formatErrorOutput($errorOutput)
182+
PHP_EOL . $errorOutput
183183
);
184184

185185
$this->logger->error($errorMessage);

src/Command/Process/ApplyLocal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function run(InputInterface $input, OutputInterface $output)
9595
$errorMessage = sprintf(
9696
'Applying patch %s failed.%s',
9797
$patch->getPath(),
98-
$this->renderer->formatErrorOutput($exception->getMessage())
98+
PHP_EOL . $exception->getMessage()
9999
);
100100

101101
throw new RuntimeException($errorMessage, $exception->getCode());

src/Command/Process/Ece/Revert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function ($patch) {
121121
$errorMessage = sprintf(
122122
'Reverting patch %s failed.%s',
123123
$patch->getPath(),
124-
$this->renderer->formatErrorOutput($exception->getMessage())
124+
PHP_EOL . $exception->getMessage()
125125
);
126126
$this->printError($output, $errorMessage);
127127
}

src/Command/Process/Renderer.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,6 @@ public function printPatchInfo(
140140
$output->writeln('');
141141
}
142142

143-
/**
144-
* Format error output.
145-
*
146-
* @param string $errorOutput
147-
* @return string
148-
*/
149-
public function formatErrorOutput(string $errorOutput): string
150-
{
151-
if (preg_match('#^.*?Error Output:(?<errors>.*?)$#is', $errorOutput, $matches)) {
152-
$errorOutput = PHP_EOL . 'Error Output:' . $matches['errors'];
153-
}
154-
155-
return $errorOutput;
156-
}
157-
158143
/**
159144
* Asks a confirmation question to the user.
160145
*

src/Patch/Conflict/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function process(
8484
'Applying patch %s (%s) failed.%s%s',
8585
$patch->getId(),
8686
$patch->getPath(),
87-
$this->renderer->formatErrorOutput($exceptionMessage),
87+
PHP_EOL. $exceptionMessage,
8888
$conflictDetails ? PHP_EOL . $conflictDetails : ''
8989
);
9090

src/Shell/Command/DriverException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ private function formatMessage(string $message): string
3737
$errorMsg = null;
3838
$generalMsg = null;
3939
if (preg_match('#^.*?Error Output:(?<errors>.*?)$#is', $result, $matches)) {
40-
$errorMsg = PHP_EOL .'Error Output:' . $matches['errors'];
40+
$errorMsg = 'Error Output:' . $matches['errors'];
4141
$result = str_replace($errorMsg, '', $result);
4242
if (!trim(str_replace('=', '', $matches['errors']))) {
4343
$errorMsg = null;
4444
}
4545
}
4646
if (empty($errorMsg) && preg_match('#^.*?Output:(?<errors>.*?)$#is', $result, $matches)) {
47-
$generalMsg = PHP_EOL .'Output:' . $matches['errors'];
47+
$generalMsg = 'Output:' . $matches['errors'];
4848
if (!trim(str_replace('=', '', $matches['errors']))) {
4949
$generalMsg = null;
5050
}

src/Test/Unit/Command/Process/Action/RevertActionTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ public function testRevertWithException()
184184
$this->applier->method('revert')
185185
->willThrowException(new ApplierException('Error'));
186186

187-
$this->renderer->expects($this->once())
188-
->method('formatErrorOutput')
189-
->with('Error');
190187
$outputMock->expects($this->once())
191188
->method('writeln')
192189
->withConsecutive(

src/Test/Unit/Command/Process/ApplyLocalTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ function ($path, $title) {
171171
->method('process')
172172
->withConsecutive([[$patch1]])
173173
->willReturn($rollbackMessages);
174-
$this->renderer->expects($this->once())
175-
->method('formatErrorOutput')
176-
->with('Applier error message');
177174

178175
$this->expectException(RuntimeException::class);
179176
$this->manager->run($inputMock, $outputMock);

src/Test/Unit/Command/Process/Ece/RevertTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ function ($path, $title) {
165165
}
166166
);
167167

168-
$this->renderer->expects($this->once())
169-
->method('formatErrorOutput')
170-
->with('Applier error message');
171-
172168
$this->revertAction->expects($this->once())
173169
->method('execute')
174170
->withConsecutive([$inputMock, $outputMock, []]);

src/Test/Unit/Command/Process/RendererTest.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -122,53 +122,6 @@ public function printPatchInfoDataProvider(): array
122122
];
123123
}
124124

125-
/**
126-
* Tests error output formatting.
127-
*
128-
* @param string $errorOutput
129-
* @param string $expectedOutput
130-
* @dataProvider formatErrorOutputDataProvider
131-
*/
132-
public function testFormatErrorOutput(string $errorOutput, string $expectedOutput)
133-
{
134-
$this->assertEquals($expectedOutput, $this->renderer->formatErrorOutput($errorOutput));
135-
}
136-
137-
/**
138-
* @return array
139-
*/
140-
public function formatErrorOutputDataProvider(): array
141-
{
142-
return [
143-
[
144-
'error' => 'The command "\'git\' \'apply\' \'/path/to/patch/MC-1111_test_patch_1.1.1_ce.patch\'" failed.
145-
146-
Exit Code: 1(General error)
147-
148-
Working directory: /path/to/patch
149-
150-
Output:
151-
================
152-
153-
154-
Error Output:
155-
================
156-
error: patch failed: vendor/magento/module-admin-analytics/Controller/Adminhtml/Config/DisableAdminUsage.php:23
157-
error: vendor/magento/module-admin-analytics/Controller/Adminhtml/Config/DisableAdminUsage.php: patch does not apply',
158-
159-
'expectedOutput' => '
160-
Error Output:
161-
================
162-
error: patch failed: vendor/magento/module-admin-analytics/Controller/Adminhtml/Config/DisableAdminUsage.php:23
163-
error: vendor/magento/module-admin-analytics/Controller/Adminhtml/Config/DisableAdminUsage.php: patch does not apply'
164-
],
165-
[
166-
'error' => 'Some other output',
167-
'expectedOutput' => 'Some other output'
168-
],
169-
];
170-
}
171-
172125
/**
173126
* Creates patch mock.
174127
*

0 commit comments

Comments
 (0)