Exemple #1
0
 /**
  * Compares local revision to the remote one and
  * builds files to upload and delete
  *
  * @throws Exception if unknown git diff status
  * @return string
  */
 public function compare()
 {
     $remoteRevision = null;
     $filesToUpload = array();
     $filesToDelete = array();
     // The revision file goes inside the submodule.
     if ($this->isSubmodule) {
         $this->revisionFile = $this->isSubmodule . '/' . $this->revisionFile;
     }
     if ($this->bridge->exists($this->revisionFile)) {
         $remoteRevision = $this->bridge->get($this->revisionFile);
         $message = "\r\n» Taking it from '" . substr($remoteRevision, 0, 7) . "'";
     } else {
         $message = "\r\n» Fresh deployment - grab a coffee";
     }
     // A remote version exists.
     if ($remoteRevision) {
         // Get the files from the diff.
         $output = $this->git->diff($remoteRevision);
         foreach ($output as $line) {
             // Added, changed or modified.
             if ($line[0] == 'A' or $line[0] == 'C' or $line[0] == 'M') {
                 $filesToUpload[] = trim(substr($line, 1));
             } elseif ($line[0] == 'D') {
                 $filesToDelete[] = trim(substr($line, 1));
             } else {
                 throw new Exception("Unknown git-diff status: {$line[0]}");
             }
         }
     } else {
         $filesToUpload = $this->git->files();
     }
     // Remove ignored files from the list of uploads.
     $filesToUpload = array_diff($filesToUpload, $this->ignoredFiles);
     $this->filesToUpload = $filesToUpload;
     $this->filesToDelete = $filesToDelete;
     return $message;
 }