Beispiel #1
0
 /**
  * Check out a clean working copy from SVN
  * @param \Cogeco\Build\Entity\WorkingCopy $workingCopy
  * @param int $revision
  * @param int $externalsRevision
  */
 public static function checkoutClean(WorkingCopy $workingCopy, $revision = 0, $externalsRevision = 0)
 {
     $rev = $revision === 0 ? 'HEAD' : $revision;
     $extRev = $externalsRevision === 0 ? 'HEAD' : $rev;
     self::log("-- Getting a clean checkout at ");
     if ($revision > 0) {
         self::log("revision {$revision}");
     } else {
         self::log("head revision");
     }
     if ($externalsRevision > 0) {
         self::log(" with externals at revision {$externalsRevision}");
     }
     self::log("\n\n");
     // Get the repo information to validate the requested revision numbers to checkout
     $svnRemoteInfo = self::getRepoInfo($workingCopy, $revision);
     $realRevision = $svnRemoteInfo->commitRevision;
     $realExtRevision = $externalsRevision;
     // Correct the requested revision number to the last commit one from the repo
     if ($revision !== $realRevision) {
         self::log("Check out last commit revision {$realRevision}\n\n");
     }
     // Determine the real externals revision number as well
     if ($externalsRevision === $revision) {
         $realExtRevision = $realRevision;
     } else {
         $svnRemoteExtInfo = self::getRepoInfo($workingCopy, $externalsRevision);
         // Correct the requested revision number to the last commit one from the repo
         if ($externalsRevision !== $svnRemoteExtInfo->commitRevision) {
             self::log("Checking out last (externals) commit revision {$svnRemoteExtInfo->commitRevision}\n\n");
             $realExtRevision = $svnRemoteExtInfo->commitRevision;
         }
     }
     // Get local svn info
     if (empty($workingCopy->info)) {
         try {
             $workingCopy->info = SvnTask::getInfo($workingCopy);
         } catch (Exception $e) {
             $workingCopy->info = NULL;
             // Indicates that the working copy is not checked out yet
         }
     }
     // The Working copy and remote repo do not share the same URL.
     // We must delete the working copy and do a fresh checkout
     if (!empty($workingCopy->info) && $workingCopy->info->url !== $svnRemoteInfo->url) {
         self::log("- Emptying the working copy folder\n\n");
         FileSystemTask::rrmdir($workingCopy->dir->getPath(), FALSE);
         $workingCopy->info = NULL;
     }
     if ($workingCopy->info === NULL) {
         self::log("- Checkout a fresh copy\n\n");
         self::checkout($workingCopy, $realRevision);
         $workingCopy->info = SvnTask::getInfo($workingCopy);
     } else {
         self::cleanUp($workingCopy);
     }
     // Do a bit of cleanup
     self::revert($workingCopy);
     self::purgeIgnoredAndUnversioned($workingCopy);
     // Set the externals and update the info object
     if (self::setExternalsToRevision($workingCopy, $realExtRevision)) {
         self::update($workingCopy, $realRevision);
         $workingCopy->info = SvnTask::getInfo($workingCopy);
     }
 }