Skip to content

Commit 661c464

Browse files
committed
MC-37324: Add fallback to 'patch' command when 'git' command is not available
1 parent 68a4f8c commit 661c464

File tree

7 files changed

+30
-21
lines changed

7 files changed

+30
-21
lines changed

config/services.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
</service>
8080
<service id="Magento\CloudPatches\Patch\PatchBuilder" shared="false"/>
8181
<service id="patchCommand" class="Magento\CloudPatches\Patch\PatchCommand">
82-
<argument key="$commands" type="collection">
82+
<argument key="$drivers" type="collection">
8383
<argument type="service" id="Magento\CloudPatches\Shell\Command\GitDriver"/>
8484
<argument type="service" id="Magento\CloudPatches\Shell\Command\PatchDriver"/>
8585
</argument>

src/Patch/PatchCommand.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,73 +17,73 @@ class PatchCommand implements PatchCommandInterface
1717
/**
1818
* @var DriverInterface[]
1919
*/
20-
private $commands;
20+
private $drivers;
2121

2222
/**
2323
* @var DriverInterface
2424
*/
25-
private $command;
25+
private $driver;
2626

2727
/**
28-
* @param DriverInterface[] $commands
28+
* @param DriverInterface[] $drivers
2929
*/
3030
public function __construct(
31-
array $commands
31+
array $drivers
3232
) {
33-
$this->commands = $commands;
33+
$this->drivers = $drivers;
3434
}
3535

3636
/**
3737
* @inheritDoc
3838
*/
3939
public function apply(string $patch)
4040
{
41-
$this->getCommand()->apply($patch);
41+
$this->getDriver()->apply($patch);
4242
}
4343

4444
/**
4545
* @inheritDoc
4646
*/
4747
public function revert(string $patch)
4848
{
49-
$this->getCommand()->revert($patch);
49+
$this->getDriver()->revert($patch);
5050
}
5151

5252
/**
5353
* @inheritDoc
5454
*/
5555
public function applyCheck(string $patch)
5656
{
57-
$this->getCommand()->applyCheck($patch);
57+
$this->getDriver()->applyCheck($patch);
5858
}
5959

6060
/**
6161
* @inheritDoc
6262
*/
6363
public function revertCheck(string $patch)
6464
{
65-
$this->getCommand()->revertCheck($patch);
65+
$this->getDriver()->revertCheck($patch);
6666
}
6767

6868
/**
69-
* Return first available command
69+
* Returns first available driver
7070
*
7171
* @return DriverInterface
7272
* @throws PatchCommandNotFound
7373
*/
74-
private function getCommand(): DriverInterface
74+
private function getDriver(): DriverInterface
7575
{
76-
if ($this->command === null) {
77-
foreach ($this->commands as $command) {
78-
if ($command->isInstalled()) {
79-
$this->command = $command;
76+
if ($this->driver === null) {
77+
foreach ($this->drivers as $driver) {
78+
if ($driver->isInstalled()) {
79+
$this->driver = $driver;
8080
break;
8181
}
8282
}
83-
if ($this->command === null) {
83+
if ($this->driver === null) {
8484
throw new PatchCommandNotFound();
8585
}
8686
}
87-
return $this->command;
87+
return $this->driver;
8888
}
8989
}

src/Patch/PatchCommandInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function apply(string $patch);
3131
public function revert(string $patch);
3232

3333
/**
34-
* Checks if the patch can be applied.
34+
* Checks if patch can be applied.
3535
*
3636
* @param string $patch
3737
* @return void
@@ -40,7 +40,7 @@ public function revert(string $patch);
4040
public function applyCheck(string $patch);
4141

4242
/**
43-
* Checks if the patch can be reversed
43+
* Checks if patch can be reverted
4444
*
4545
* @param string $patch
4646
* @return void

src/Patch/PatchCommandNotFound.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use Magento\CloudPatches\App\GenericException;
1111

12+
/**
13+
* Exception thrown if none of defined patch drivers is available
14+
*/
1215
class PatchCommandNotFound extends GenericException
1316
{
1417
public function __construct()

src/Shell/Command/DriverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\CloudPatches\Patch\PatchCommandInterface;
1111

1212
/**
13-
* Patch driver interface
13+
* Patch command driver interface
1414
*/
1515
interface DriverInterface extends PatchCommandInterface
1616
{

src/Shell/Command/GitDriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class GitDriver implements DriverInterface
2121
*/
2222
private $processFactory;
2323

24+
/**
25+
* @param ProcessFactory $processFactory
26+
*/
2427
public function __construct(
2528
ProcessFactory $processFactory
2629
) {

src/Shell/Command/PatchDriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class PatchDriver implements DriverInterface
2121
*/
2222
private $processFactory;
2323

24+
/**
25+
* @param ProcessFactory $processFactory
26+
*/
2427
public function __construct(
2528
ProcessFactory $processFactory
2629
) {

0 commit comments

Comments
 (0)