Skip to content

Commit

Permalink
Add config option for update reference in path repository
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir.panivko committed Jan 31, 2022
1 parent 3ae1111 commit 2196373
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/Composer/Repository/PathRepository.php
Expand Up @@ -56,6 +56,13 @@
* "symlink": false
* }
* },
* {
* "type": "path",
* "url": "../../relative/path/to/package/",
* "options": {
* "updateReference": false
* }
* },
* ]
* @endcode
*
Expand All @@ -81,7 +88,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn

/**
* @var mixed[]
* @phpstan-var array{url: string, options?: array{symlink?: bool, relative?: bool, versions?: array<string, string>}}
* @phpstan-var array{url: string, options?: array{symlink?: bool, updateReference?: bool, relative?: bool, versions?: array<string, string>}}
*/
private $repoConfig;

Expand All @@ -91,14 +98,14 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
private $process;

/**
* @var array{symlink?: bool, relative?: bool, versions?: array<string, string>}
* @var array{symlink?: bool, updateReference: bool, relative: bool, versions?: array<string, string>}
*/
private $options;

/**
* Initializes path repository.
*
* @param array{url?: string, options?: array{symlink?: bool, relative?: bool, versions?: array<string, string>}} $repoConfig
* @param array{url?: string, options?: array{symlink?: bool, updateReference?: bool, relative?: bool, versions?: array<string, string>}} $repoConfig
* @param IOInterface $io
* @param Config $config
*/
Expand All @@ -118,6 +125,9 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config)
$filesystem = new Filesystem();
$this->options['relative'] = !$filesystem->isAbsolutePath($this->url);
}
if (!isset($this->options['updateReference'])) {
$this->options['updateReference'] = true;
}

parent::__construct();
}
Expand Down Expand Up @@ -193,7 +203,7 @@ protected function initialize()
}

$output = '';
if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H'.GitUtil::getNoShowSignatureFlag($this->process), $output, $path)) {
if ($this->options['updateReference'] && is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H'.GitUtil::getNoShowSignatureFlag($this->process), $output, $path)) {
$package['dist']['reference'] = trim($output);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -7,7 +7,7 @@
"dist": {
"type": "path",
"url": "evil-pkg",
"reference": "a95061d7a7e3cf4466381fd1abc504279c95b231"
"reference": "c78ed4017d8213c0921dbfee6ba33dbc3b23f667"
},
"type": "library",
"installation-source": "dist",
Expand Down
Expand Up @@ -16,7 +16,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../evil/pkg',
'aliases' => array(),
'reference' => 'a95061d7a7e3cf4466381fd1abc504279c95b231',
'reference' => 'c78ed4017d8213c0921dbfee6ba33dbc3b23f667',
'dev_requirement' => false,
),
'root/pkg' => array(
Expand Down

0 comments on commit 2196373

Please sign in to comment.