@@ -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