1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dandelion\VersionControl; |
6
|
|
|
|
7
|
|
|
use Dandelion\Configuration\ConfigurationLoaderInterface; |
8
|
|
|
use Dandelion\Exception\RuntimeException; |
9
|
|
|
use Dandelion\Process\ProcessFactory; |
10
|
|
|
|
11
|
|
|
use function sprintf; |
12
|
|
|
|
13
|
|
|
class SplitshLite implements SplitshLiteInterface |
14
|
|
|
{ |
15
|
|
|
public const DEFAULT_PATH_TO_BINARY = '/usr/local/bin/splitsh-lite'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \Dandelion\Process\ProcessFactory |
19
|
|
|
*/ |
20
|
|
|
protected $processFactory; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Dandelion\Configuration\ConfigurationLoaderInterface |
24
|
|
|
*/ |
25
|
|
|
protected $configurationLoader; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \Dandelion\Process\ProcessFactory $processFactory |
29
|
|
|
* @param \Dandelion\Configuration\ConfigurationLoaderInterface $configurationLoader |
30
|
|
|
*/ |
31
|
|
|
public function __construct( |
32
|
|
|
ProcessFactory $processFactory, |
33
|
|
|
ConfigurationLoaderInterface $configurationLoader |
34
|
|
|
) { |
35
|
|
|
$this->processFactory = $processFactory; |
36
|
|
|
$this->configurationLoader = $configurationLoader; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $pathToPackage |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
* |
44
|
|
|
* @throws \Exception |
45
|
|
|
*/ |
46
|
|
|
public function getSha1(string $pathToPackage): string |
47
|
|
|
{ |
48
|
|
|
$command = [ |
49
|
|
|
$this->getPathToBinary(), |
50
|
|
|
sprintf('--prefix=%s', $pathToPackage), |
51
|
|
|
'--quiet' |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
$process = $this->processFactory->create($command); |
55
|
|
|
|
56
|
|
|
$process->run(); |
57
|
|
|
|
58
|
|
|
if (!$process->isSuccessful()) { |
59
|
|
|
throw new RuntimeException($process->getExitCodeText(), $process->getExitCode()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return trim($process->getOutput()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
* |
68
|
|
|
* @throws \Exception |
69
|
|
|
*/ |
70
|
|
|
protected function getPathToBinary(): string |
71
|
|
|
{ |
72
|
|
|
$configuration = $this->configurationLoader->load(); |
73
|
|
|
|
74
|
|
|
return $configuration->getPathToSplitshLite() ?? static::DEFAULT_PATH_TO_BINARY; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|