Banago\PHPloy\PHPloy::compare PHP Méthode

compare() public méthode

[ 'upload' => $filesToUpload, 'delete' => $filesToDelete ];
public compare ( string $localRevision ) : array
$localRevision string
Résultat array
    public function compare($localRevision)
    {
        $remoteRevision = null;
        $filesToUpload = [];
        $filesToDelete = [];
        if ($this->currentSubmoduleName) {
            $this->dotRevision = $this->currentSubmoduleName . '/' . $this->dotRevisionFilename;
        } else {
            $this->dotRevision = $this->dotRevisionFilename;
        }
        // Fetch the .revision file from the server and write it to $tmpFile
        $this->debug("Fetching {$this->dotRevision} file");
        if ($this->connection->has($this->dotRevision)) {
            $remoteRevision = $this->connection->read($this->dotRevision);
            $this->debug('Remote revision: <bold>' . $remoteRevision);
        } else {
            $this->cli->comment('No revision found - uploading everything...');
        }
        // Checkout the specified Git branch
        if (!empty($this->servers[$this->currentlyDeploying]['branch'])) {
            $output = $this->git->checkout($this->servers[$this->currentlyDeploying]['branch'], $this->repo);
            if (isset($output[0])) {
                if (strpos($output[0], 'error') === 0) {
                    throw new \Exception('Stash your modifications before deploying.');
                }
            }
            if (isset($output[1])) {
                if ($output[1][0] === 'M') {
                    throw new \Exception('Stash your modifications before deploying.');
                }
            }
            if (isset($output[0])) {
                $this->cli->out($output[0]);
            }
        }
        $output = $this->git->diff($remoteRevision, $localRevision, $this->repo);
        $this->debug(implode("\r\n", $output));
        /*
         * Git Status Codes
         *
         * A: addition of a file
         * C: copy of a file into a new one
         * D: deletion of a file
         * M: modification of the contents or mode of a file
         * R: renaming of a file
         * T: change in the type of the file
         * U: file is unmerged (you must complete the merge before it can be committed)
         * X: "unknown" change type (most probably a bug, please report it)
         */
        if (!empty($remoteRevision)) {
            foreach ($output as $line) {
                $status = $line[0];
                if (strpos($line, 'warning: CRLF will be replaced by LF in') !== false) {
                    continue;
                } elseif (strpos($line, 'The file will have its original line endings in your working directory.') !== false) {
                    continue;
                } elseif ($status === 'A' or $status === 'C' or $status === 'M' or $status === 'T') {
                    $filesToUpload[] = trim(substr($line, 1));
                } elseif ($status == 'D') {
                    $filesToDelete[] = trim(substr($line, 1));
                } elseif ($status === 'R') {
                    list(, $oldFile, $newFile) = preg_split('/\\s+/', $line);
                    $filesToDelete[] = trim($oldFile);
                    $filesToUpload[] = trim($newFile);
                } else {
                    throw new \Exception("Unknown git-diff status. Use '--sync' to update remote revision or use '--debug' to see what's wrong.");
                }
            }
        } else {
            $filesToUpload = $output;
        }
        $filteredFilesToUpload = $this->filterIgnoredFiles($filesToUpload);
        $filteredFilesToDelete = $this->filterIgnoredFiles($filesToDelete);
        $filteredFilesToInclude = isset($this->filesToInclude[$this->currentlyDeploying]) ? $this->filterIncludedFiles($this->filesToInclude[$this->currentlyDeploying]) : [];
        $filesToUpload = array_merge($filteredFilesToUpload['files'], $filteredFilesToInclude);
        $filesToDelete = $filteredFilesToDelete['files'];
        $filesToSkip = array_merge($filteredFilesToUpload['filesToSkip'], $filteredFilesToDelete['filesToSkip']);
        return [$this->currentlyDeploying => ['delete' => $filesToDelete, 'upload' => $filesToUpload, 'exclude' => $filesToSkip]];
    }