Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@marvil07
Copy link
Contributor

@marvil07 marvil07 commented May 29, 2016

I tried #4685 but it seems to not being creating the git mirror, so I extended it a little, on top of @luisfaceira changes; I have also added a version check for git, given that the --dissociate option is only available since 2.3.0-rc0, which is not yet the default on some *nix distributions.

PS: Please notice that this is my first attempt to read/modify composer, so I would be happy to rework this if needed.

luisfaceira and others added 7 commits May 29, 2016 12:36
Also added home dir to default initial settings
Added the usage of dissociate so that the repos work properly
even if the cache gets deleted after the clone
When creating a DownloaderMock a home config dir is
ensured to exist, so that no test fails for lack of it
that on a regular run would be set by the Factory
if (0 !== $this->process->execute('git --version', $output)) {
throw new \RuntimeException(self::sanitizeUrl('Failed retrieve git version, git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()));
}
if (strpos($output, 'git version ') === FALSE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a regex instead to capture the version from the string and return it?

@alcohol
Copy link
Member

alcohol commented Jun 7, 2016

I see that the test cases were adjusted to work as if this new feature is not available. I would really like to see a test case that does the opposite (assume the feature is available).

$this->gitUtil->runCommand($mirrorCommandCallable, $url, $path, true);
}
}
$cacheOptions = file_exists($cachePath) ? '--dissociate --reference '.ProcessExecutor::escape($cachePath).' ' : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this check should be done inside the if(version_compare) check. The ternary operator could even be gone.

if (0 !== $this->process->execute('git --version', $output)) {
throw new \RuntimeException(self::sanitizeUrl('Failed retrieve git version, git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()));
}
if (preg_match('/^git version (.*)/', $output, $matches) !== 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this pattern is the best idea.. but it'll do for now.


// --dissociate option is only available since git 2.3.0-rc0
if (version_compare($this->gitUtil->getVersion(), '2.3.0-rc0', '>=')) {
if (!file_exists($cachePath)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is not enought, we need to update the clone:
a) if the initial clone attempt failed (like on process timeout)
b) cache is out of date
In general, I think we need to always fetch the upstream to the cache if the directory already exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants