當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Git::diff方法代碼示例

本文整理匯總了PHP中Git::diff方法的典型用法代碼示例。如果您正苦於以下問題:PHP Git::diff方法的具體用法?PHP Git::diff怎麽用?PHP Git::diff使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Git的用法示例。


在下文中一共展示了Git::diff方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getDiff

 function getDiff($proj, $commit)
 {
     return Git::diff($proj, $commit);
 }
開發者ID:nurulimamnotes,項目名稱:php-git,代碼行數:4,代碼來源:project.php

示例2: compare

 /**
  * Compare revisions and returns array of files to upload:.
  *
  *      [
  *          'upload' => $filesToUpload,
  *          'delete' => $filesToDelete
  *      ];
  *
  * @param string $localRevision
  *
  * @throws \Exception if unknown git diff status
  *
  * @return 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]];
 }
開發者ID:banago,項目名稱:phploy,代碼行數:93,代碼來源:PHPloy.php

示例3:

     break;
 case 'log':
     if (isset($_GET['path'])) {
         $result = $git->getLog(getWorkspacePath($_GET['path']));
         if ($result === false) {
             echo '{"status":"error","message":"Failed to get log!"}';
         } else {
             echo '{"status":"success","data":' . json_encode($result) . '}';
         }
     } else {
         echo '{"status":"error","message":"Missing parameter!"}';
     }
     break;
 case 'diff':
     if (isset($_GET['repo']) && isset($_GET['path'])) {
         $result = $git->diff(getWorkspacePath($_GET['repo']), $_GET['path']);
         if ($result === false) {
             echo '{"status":"error","message":"Failed to get diff!"}';
         } else {
             echo $result;
         }
     } else {
         echo '{"status":"error","message":"Missing parameter!"}';
     }
     break;
 case 'checkout':
     if (isset($_GET['repo']) && isset($_GET['path'])) {
         if ($git->checkout(getWorkspacePath($_GET['repo']), $_GET['path'])) {
             echo '{"status":"success","message":"Changes reverted!"}';
         } else {
             echo '{"status":"error","message":"Failed to undo changes!"}';
開發者ID:practico,項目名稱:Codiad-CodeGit,代碼行數:31,代碼來源:controller.php


注:本文中的Git::diff方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。