Skip to content

Commit 0415656

Browse files
committed
MC-37324: Add fallback to 'patch' command when 'git' command is not available
- Remove redundant exceptions
1 parent 8644f03 commit 0415656

File tree

6 files changed

+21
-68
lines changed

6 files changed

+21
-68
lines changed

config/services.xml

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
<service id="Magento\CloudPatches\Patch\PatchCommandNotFound" autowire="false"/>
3131
<service id="Magento\CloudPatches\Patch\PatchCommandException" autowire="false"/>
3232
<service id="Magento\CloudPatches\Shell\Command\DriverException" autowire="false"/>
33-
<service id="Magento\CloudPatches\Shell\Command\GitDriverException" autowire="false"/>
34-
<service id="Magento\CloudPatches\Shell\Command\PatchDriverException" autowire="false"/>
3533
<service id="Magento\CloudPatches\Patch\PatchCommand" autowire="false"/>
3634
<service id="Magento\CloudPatches\Patch\PatchCommandInterface" alias="Magento\CloudPatches\Patch\PatchCommand"/>
3735
<service id="statusPool" class="Magento\CloudPatches\Patch\Status\StatusPool" lazy="true">

src/Shell/Command/DriverException.php

+13
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,23 @@
88
namespace Magento\CloudPatches\Shell\Command;
99

1010
use Magento\CloudPatches\Patch\PatchCommandException;
11+
use Symfony\Component\Process\Exception\ProcessFailedException;
12+
use Throwable;
1113

1214
/**
1315
* Patch command driver exception
1416
*/
1517
class DriverException extends PatchCommandException
1618
{
19+
/**
20+
* @param Throwable $previous
21+
*/
22+
public function __construct(Throwable $previous)
23+
{
24+
$message = $previous->getMessage();
25+
if ($previous instanceof ProcessFailedException) {
26+
$message = $previous->getProcess()->getErrorOutput() ?: ($previous->getProcess()->getOutput() ?: $message);
27+
}
28+
parent::__construct($message, $previous->getCode(), $previous);
29+
}
1730
}

src/Shell/Command/GitDriver.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function apply(string $patch)
3838
$this->processFactory->create(['git', 'apply'], $patch)
3939
->mustRun();
4040
} catch (ProcessFailedException $exception) {
41-
throw new GitDriverException($exception);
41+
throw new DriverException($exception);
4242
}
4343
}
4444

@@ -51,7 +51,7 @@ public function revert(string $patch)
5151
$this->processFactory->create(['git', 'apply', '--reverse'], $patch)
5252
->mustRun();
5353
} catch (ProcessFailedException $exception) {
54-
throw new GitDriverException($exception);
54+
throw new DriverException($exception);
5555
}
5656
}
5757

@@ -64,7 +64,7 @@ public function applyCheck(string $patch)
6464
$this->processFactory->create(['git', 'apply', '--check'], $patch)
6565
->mustRun();
6666
} catch (ProcessFailedException $exception) {
67-
throw new GitDriverException($exception);
67+
throw new DriverException($exception);
6868
}
6969
}
7070

@@ -77,7 +77,7 @@ public function revertCheck(string $patch)
7777
$this->processFactory->create(['git', 'apply', '--reverse', '--check'], $patch)
7878
->mustRun();
7979
} catch (ProcessFailedException $exception) {
80-
throw new GitDriverException($exception);
80+
throw new DriverException($exception);
8181
}
8282
}
8383

src/Shell/Command/GitDriverException.php

-29
This file was deleted.

src/Shell/Command/PatchDriver.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function apply(string $patch)
3939
$this->processFactory->create(['patch', '--silent', '-p1', '--no-backup-if-mismatch'], $patch)
4040
->mustRun();
4141
} catch (ProcessFailedException $exception) {
42-
throw new PatchDriverException($exception);
42+
throw new DriverException($exception);
4343
}
4444
}
4545

@@ -53,7 +53,7 @@ public function revert(string $patch)
5353
$this->processFactory->create(['patch', '--silent', '-p1', '--no-backup-if-mismatch', '--reverse'], $patch)
5454
->mustRun();
5555
} catch (ProcessFailedException $exception) {
56-
throw new PatchDriverException($exception);
56+
throw new DriverException($exception);
5757
}
5858
}
5959

@@ -66,7 +66,7 @@ public function applyCheck(string $patch)
6666
$this->processFactory->create(['patch', '--silent', '-p1', '--dry-run'], $patch)
6767
->mustRun();
6868
} catch (ProcessFailedException $exception) {
69-
throw new PatchDriverException($exception);
69+
throw new DriverException($exception);
7070
}
7171
}
7272

@@ -79,7 +79,7 @@ public function revertCheck(string $patch)
7979
$this->processFactory->create(['patch', '--silent', '-p1', '--reverse', '--dry-run'], $patch)
8080
->mustRun();
8181
} catch (ProcessFailedException $exception) {
82-
throw new PatchDriverException($exception);
82+
throw new DriverException($exception);
8383
}
8484
}
8585

src/Shell/Command/PatchDriverException.php

-29
This file was deleted.

0 commit comments

Comments
 (0)