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

Skip to content

Commit f6666fe

Browse files
committed
Update source/dist refs when a commit is recovered from, fixes composer#1130
1 parent 543599c commit f6666fe

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/Composer/Downloader/GitDownloader.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ public function doDownload(PackageInterface $package, $path)
4343
$this->runCommand($commandCallable, $package->getSourceUrl(), $path, true);
4444
$this->setPushUrl($package, $path);
4545

46-
$this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate());
46+
if ($newRef = $this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate())) {
47+
if ($package->getDistReference() === $package->getSourceReference()) {
48+
$package->setDistReference($newRef);
49+
}
50+
$package->setSourceReference($newRef);
51+
}
4752
}
4853

4954
/**
@@ -72,7 +77,12 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
7277
};
7378

7479
$this->runCommand($commandCallable, $target->getSourceUrl(), $path);
75-
$this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate());
80+
if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) {
81+
if ($target->getDistReference() === $target->getSourceReference()) {
82+
$target->setDistReference($newRef);
83+
}
84+
$target->setSourceReference($newRef);
85+
}
7686
}
7787

7888
/**
@@ -183,6 +193,15 @@ protected function reapplyChanges($path)
183193
}
184194
}
185195

196+
/**
197+
* Updates the given apth to the given commit ref
198+
*
199+
* @param string $path
200+
* @param string $reference
201+
* @param string $branch
202+
* @param DateTime $date
203+
* @return null|string if a string is returned, it is the commit reference that was checked out if the original could not be found
204+
*/
186205
protected function updateToCommit($path, $reference, $branch, $date)
187206
{
188207
$template = 'git checkout %s && git reset --hard %1$s';
@@ -264,7 +283,7 @@ protected function updateToCommit($path, $reference, $branch, $date)
264283
if (0 === $this->process->execute($command, $output, $path)) {
265284
$this->io->write(' '.$reference.' is gone (history was rewritten?), recovered by checking out '.$newReference);
266285

267-
return;
286+
return $newReference;
268287
}
269288
}
270289

0 commit comments

Comments
 (0)