Skip to content

Commit a451860

Browse files
SDK-5621 Avoid integrator lock updates. #165 from spryker-sdk/bugfix/sdk-5621-avoid-integrator-lock-updates
SDK-5621 Avoid integrator lock updates
2 parents 6563df9 + 3ac8df9 commit a451860

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/IntegratorFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
use SprykerSdk\Integrator\Executor\ManifestExecutorInterface;
128128
use SprykerSdk\Integrator\Executor\Module\ModuleManifestExecutor;
129129
use SprykerSdk\Integrator\Executor\Module\ModuleManifestExecutorInterface;
130+
use SprykerSdk\Integrator\Executor\ProcessExecutor;
130131
use SprykerSdk\Integrator\Executor\ReleaseGroup\DiffGenerator;
131132
use SprykerSdk\Integrator\FileStorage\BucketFileStorage;
132133
use SprykerSdk\Integrator\FileStorage\BucketFileStorageInterface;
@@ -249,7 +250,7 @@ public function createIntegratorLockWriter(): IntegratorLockWriterInterface
249250
*/
250251
public function createIntegratorLockCleaner(): IntegratorLockCleanerInterface
251252
{
252-
return new IntegratorLockCleaner($this->getConfig());
253+
return new IntegratorLockCleaner($this->getConfig(), new ProcessExecutor());
253254
}
254255

255256
/**

src/IntegratorLock/IntegratorLockCleaner.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace SprykerSdk\Integrator\IntegratorLock;
1111

12+
use SprykerSdk\Integrator\Executor\ProcessExecutor;
1213
use SprykerSdk\Integrator\IntegratorConfig;
1314

1415
class IntegratorLockCleaner implements IntegratorLockCleanerInterface
@@ -18,12 +19,19 @@ class IntegratorLockCleaner implements IntegratorLockCleanerInterface
1819
*/
1920
protected IntegratorConfig $config;
2021

22+
/**
23+
* @var \SprykerSdk\Integrator\Executor\ProcessExecutor
24+
*/
25+
protected ProcessExecutor $processExecutor;
26+
2127
/**
2228
* @param \SprykerSdk\Integrator\IntegratorConfig $config
29+
* @param \SprykerSdk\Integrator\Executor\ProcessExecutor $processExecutor
2330
*/
24-
public function __construct(IntegratorConfig $config)
31+
public function __construct(IntegratorConfig $config, ProcessExecutor $processExecutor)
2532
{
2633
$this->config = $config;
34+
$this->processExecutor = $processExecutor;
2735
}
2836

2937
/**
@@ -34,5 +42,24 @@ public function deleteLock(): void
3442
$lockFilePath = $this->config->getIntegratorLockFilePath();
3543

3644
unlink($lockFilePath);
45+
46+
if (!$this->isLockFileChangeTrackedByGit($lockFilePath)) {
47+
return;
48+
}
49+
50+
$this->processExecutor->execute(['git', 'add', $lockFilePath]);
51+
$this->processExecutor->execute(['git', 'commit', '-m', 'Removed `integrator.lock` file.']);
52+
}
53+
54+
/**
55+
* @param string $filepath
56+
*
57+
* @return bool
58+
*/
59+
protected function isLockFileChangeTrackedByGit(string $filepath): bool
60+
{
61+
$process = $this->processExecutor->execute(['git', 'status', '--porcelain', $filepath]);
62+
63+
return $process->getOutput() !== '';
3764
}
3865
}

tests/SprykerSdkTest/Integrator/IntegratorLock/IntegratorLockTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace SprykerSdkTest\Integrator\IntegratorLock;
1111

12+
use SprykerSdk\Integrator\Executor\ProcessExecutor;
1213
use SprykerSdk\Integrator\IntegratorConfig;
1314
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner;
1415
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReader;
@@ -108,7 +109,7 @@ private function createIntegratorLockReader(string $tmpIntegratorLockFilePath):
108109
*/
109110
private function createIntegratorLockCleaner(string $tmpIntegratorLockFilePath): IntegratorLockCleaner
110111
{
111-
return new IntegratorLockCleaner($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
112+
return new IntegratorLockCleaner($this->mockIntegratorConfig($tmpIntegratorLockFilePath), new ProcessExecutor());
112113
}
113114

114115
/**

0 commit comments

Comments
 (0)