Platformsh\Cli\Helper\GitHelper::execute PHP Method

execute() public method

Execute a Git command.
public execute ( array $args, string | false $dir = null, boolean $mustRun = false, boolean $quiet = true ) : string | boolean
$args array Command arguments (everything after 'git').
$dir string | false The path to a Git repository. Set to false if the command should not run inside a repository.
$mustRun boolean Enable exceptions if the Git command fails.
$quiet boolean Suppress command output.
return string | boolean The command output, true if there is no output, or false if the command fails.
    public function execute(array $args, $dir = null, $mustRun = false, $quiet = true)
    {
        // If enabled, set the working directory to the repository.
        if ($dir !== false) {
            $dir = $dir ?: $this->repositoryDir;
        }
        // Run the command.
        array_unshift($args, 'git');
        return $this->shellHelper->execute($args, $dir, $mustRun, $quiet);
    }

Usage Example

Esempio n. 1
0
 /**
  * Get a hash of the application files.
  *
  * This should change if any of the application files or build settings
  * change.
  *
  * @param string $appRoot
  *
  * @return string|false
  */
 public function getTreeId($appRoot)
 {
     $hashes = [];
     // Get a hash representing all the files in the application, excluding
     // the project config folder (CLI_PROJECT_CONFIG_DIR).
     $tree = $this->gitHelper->execute(['ls-files', '-s'], $appRoot);
     if ($tree === false) {
         return false;
     }
     $tree = preg_replace('#^|\\n[^\\n]+?' . preg_quote($this->config->get('service.project_config_dir')) . '\\n|$#', "\n", $tree);
     $hashes[] = sha1($tree);
     // Include the hashes of untracked and modified files.
     $others = $this->gitHelper->execute(['ls-files', '--modified', '--others', '--exclude-standard', '-x ' . $this->config->get('service.project_config_dir'), '.'], $appRoot);
     if ($others === false) {
         return false;
     }
     $count = 0;
     foreach (explode("\n", $others) as $filename) {
         if ($count > 5000) {
             return false;
         }
         $filename = "{$appRoot}/{$filename}";
         if (is_file($filename)) {
             $hashes[] = sha1_file($filename);
             $count++;
         }
     }
     // Include relevant build settings.
     $relevant = ['abslinks', 'copy', 'clone', 'no-cache', 'working-copy', 'lock'];
     $settings = array_intersect_key($this->settings, array_flip($relevant));
     $hashes[] = serialize($settings);
     $hashes[] = self::BUILD_VERSION;
     // Combine them all.
     return sha1(implode(' ', $hashes));
 }
All Usage Examples Of Platformsh\Cli\Helper\GitHelper::execute