Load GIT Info
@throws \RuntimeException
554137
protected function loadGitInfo()
    {
        // Carregar versao
        $process = new Process('git log --pretty="%H" -n1 HEAD', base_path());
        if ($process->run() != 0)
            throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.');
        $this->params['package_version'] = trim($process->getOutput());

        // Carregar Data de atualizacao
        $process = new Process('git log -n1 --pretty=%ci HEAD', base_path());
        if ($process->run() != 0)
            throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.');

        $date = new \DateTime(trim($process->getOutput()));
        $date->setTimezone(new \DateTimeZone('UTC'));
        $this->versionDate = $date->format('Y-m-d H:i:s');
        $this->params['release_date'] = trim($process->getOutput());
    }
631252
protected function doExecute()
    {
        if ($this->console->getMode() !== 'dev') {
            throw new \RuntimeException(
                '<error>STOP!</error> please run <info>' . $this->getEnvCmd() . '</info>.'
            );
        }

        $repository = $this->getRepository();

        if (!$this->getOption('no-backup')) {
            // backup
            $this->backup();
        }

        $repository['path'] = $this->console->get('migration.dir');

        try {
            $repository->migrate($this->getArgument(0, null));

            if ($this->getOption('seed') && (string) $this->getArgument(0) !== '0') {
                $io = clone $this->io;

                $io->setArguments(['seed', 'import']);
                $io->setOption('no-backup', true);

                $this->console->getRootCommand()->setIO($io)->execute();
            }
        } catch (\Exception $e) {
            $prompter = new BooleanPrompter();

            $this->out()->out('<error>An error occurred: ' . $e->getMessage() . '</error>');

            if ($prompter->ask('Do you want to restore to last backup? [Y/n] (Y): ', true)) {
                $this->getBackupRepository()->restoreLatest();
            }

            throw $e;
        }

        return true;
    }
930582
def load(self, commit=None):
        """"""
        git_info = self.record_git_info(commit)
        LOGGER.debug("Loading the result for commit '%s'.", git_info.hexsha)
        filename = self.get_filename(git_info)
        LOGGER.debug("Loading the result '%s'.", filename)
        result = super(RepoResultManager, self).load(filename)
        self.add_git(result.meta, git_info)
        return result
766060
private function open()
    {
        if (null === ($this->handle = fopen($this->file, 'rb'))) {
            $this->handle = null;

            throw new RuntimeException(
                sprintf(
                    'The file "%s" could not be opened for reading.',
                    $this->file
                )
            );
        }
    }
1254428
public function getGitVersion()
    {
        try {
            return $this->getGitTag();
        } catch (RuntimeException $exception) {
            try {
                return $this->getGitHash(true);
            } catch (RuntimeException $exception) {
                throw new RuntimeException(
                    sprintf(
                        'The tag or commit hash could not be retrieved from "%s": %s',
                        dirname($this->file),
                        $exception->getMessage()
                    ),
                    0,
                    $exception
                );
            }
        }
    }
518768
protected function loadConfig()
    {
        if (self::$config_path === null) {
            throw new \BadMethodCallException('Config path is null');
        }

        $key = "$this->cnab/$this->bank_code";

        if (!array_key_exists($key, self::$cache)) {
            $config_file = self::$config_path . "/cnab$key.yml";
            if (file_exists($config_file)) {
                self::$cache[$key] = Yaml::parseFile($config_file);
            } else {
                throw new \RuntimeException(sprintf(
                    "Config file for Bank '%s' in CNAB%s not found",
                    $this->bank_code,
                    $this->cnab
                ));
            }
        }

        $this->config = $key;
    }
154507
public function main()
    {
        if (null === $this->getRepository()) {
            throw new BuildException('"repository" is required parameter');
        }

        $client = $this->getGitClient(false, $this->getRepository());
        $command = $client->getCommand('push');
        $command
            ->setOption('tags', $this->isTags())
            ->setOption('mirror', $this->isMirror())
            ->setOption('delete', $this->isDelete())
            ->setOption('q', $this->isQuiet())
            ->setOption('force', $this->isForce());

        // set operation target
        if ($this->isAllRemotes()) { // --all
            $command->setOption('all', true);
            $this->log('git-push: push to all refs', Project::MSG_INFO);
        } elseif ($this->isMirror()) { // <repository> [<refspec>]
            $command->setOption('mirror', true);
            $this->log('git-push: mirror all refs', Project::MSG_INFO);
        } elseif ($this->getDestination()) { // <repository> [<refspec>]
            $command->addArgument($this->getDestination());
            if ($this->getRefspec()) {
                $command->addArgument($this->getRefspec());
            }
            $this->log(
                sprintf(
                    'git-push: pushing to %s %s',
                    $this->getDestination(),
                    $this->getRefspec()
                ),
                Project::MSG_INFO
            );
        } else {
            throw new BuildException('At least one destination must be provided');
        }

        $this->log('git-push command: ' . $command->createCommandString(), Project::MSG_INFO);

        try {
            $output = $command->execute();
        } catch (Exception $e) {
            throw new BuildException('Task execution failed.', $e);
        }

        $this->log('git-push: complete', Project::MSG_INFO);
        if ($this->isDelete()) {
            $this->log('git-push: branch delete requested', Project::MSG_INFO);
        }
        $this->log('git-push output: ' . trim($output), Project::MSG_INFO);
    }
1225734
private function __index(): array {
        $this->indexedRes  = array();
        $this->commitedRes = array();

        if (count($this->paths) === 0) {
            throw new RuntimeException('No paths set');
        }

        try {
            foreach ($this->paths as $path) {
                foreach (new DirectoryIterator(self::containerDir() . $path) as $i) {
                    $this->indexEntry($i);
                }
            }
        } catch (\Throwable $e) {
            if ($e instanceof IndexerException) {
                $this->commitedRes = array_merge($this->commitedRes, $e->getCommitedResources());
            }
            throw new IndexerException($e->getMessage(), $e->getCode(), $e, $this->commitedRes);
        }

        return array($this->indexedRes, $this->commitedRes);
    }
1312164
protected function collectCommit() : CommitInfo
    {
        $commitResult = $this->executor->execute("git log -1 --pretty=format:%H%n%aN%n%ae%n%cN%n%ce%n%s%n%at");

        if (count($commitResult) !== 7 || array_keys($commitResult) !== range(0, 6)) {
            throw new \RuntimeException();
        }

        $commit = new CommitInfo();

        return $commit
            ->setId(trim($commitResult[0]))
            ->setAuthorName(trim($commitResult[1]))
            ->setAuthorEmail(trim($commitResult[2]))
            ->setCommitterName(trim($commitResult[3]))
            ->setCommitterEmail(trim($commitResult[4]))
            ->setMessage($commitResult[5])
            ->setDate((int) $commitResult[6]);
    }
1001672
public function commit()
    {
        try {
            $this->storeAllTables();

            $this->snapshot = [];
        } catch (\Exception $e) {
            throw new \RuntimeException('Commit failed: ' . $e->getMessage(), 0, $e);
        }
    }
977942
@SuppressWarnings("nls")
    private void load() {
        URL url = Version.class.getResource("version.properties");
        if (url == null) {
            this.versionString = "Unknown";
            this.versionDate = new Date().toString();
        } else {
            allProperties = new Properties();
            try(InputStream is = url.openStream()){
                allProperties.load(is);
                this.versionString = allProperties.getProperty("version", "Unknown");
                this.versionDate = allProperties.getProperty("date", new Date().toString());
                this.vcsDescribe = allProperties.getProperty("git.commit.id.describe", "Non-Git Build");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
477354
protected static function checkVersion()
    {
        if (self::$checked === true) {
            return true;
        }

        $process = new \SystemProcess\SystemProcess('git');
        $process->nonZeroExitCodeException = true;
        $process->argument('--version')->execute();

        if (!preg_match('(\\d+(?:\.\\d+)+)', $process->stdoutOutput, $match)) {
            throw new \RuntimeException('Could not determine GIT version.');
        }

        if (version_compare($match[0], '1.6', '>=')) {
            return self::$checked = true;
        }

        throw new \RuntimeException('Git is required in a minimum version of 1.6.');
    }
1310201
public function complete()
    {
        $folder  = SetupHelper::getRootFolder();
        $command = sprintf(
            'cd %1$s && git init',
            escapeshellarg($folder)
        );

        exec($command, $output, $return);

        if (0 !== $return) {
            throw new RuntimeException(
                sprintf(
                    'Could not initialize the VCS in folder "%1$s". [Exit Status: %2$d]',
                    $folder,
                    $return
                )
            );
        }
    }
1108354
protected function loadExternalConfig()
    {
        $config = new Repository(static::getDefaultConfig());
        $filesystem = new Filesystem();

        foreach ($this->getConfigFiles($filesystem) as $filename) {

            $this->output->writeln("<info>Reading config from <path>{$filename}</path></info>");

            if ($filesystem->extension($filename) == 'php') {
                $configValues = $filesystem->getRequire($filename);
            } else {
                $configValues = Yaml::parse($filesystem->get($filename));
            }

            $config->set(array_dot($configValues));
        }

        $this->container->instance('config', $config);
    }
772787
public function init() {
    $git_repo = exec('basename `git rev-parse --show-toplevel`');

    // Remove instructions for creating a new repo, because we've got one now.
    $readme_contents = file_get_contents('README.md');
    $start_string = '### Initial build (new repo)';
    $end_string = '### Initial build (existing repo)';
    $from = $this->findAllTextBetween($start_string, $end_string, $readme_contents);

    $find_replaces = array(
      array(
        'source' => 'composer.json',
        'from' => '"name": "thinkshout/drupal-project",',
        'to' => '"name": "thinkshout/' . $git_repo . '",',
      ),
      array(
        'source' => '.env.dist',
        'from' => 'TS_PROJECT="SITE"',
        'to' => 'TS_PROJECT="' . $git_repo . '"',
      ),
      array(
        'source' => 'README.md',
        'from' => array($from, 'new-project-name'),
        'to' => array($end_string, $git_repo),
      ),
    );

    foreach ($find_replaces as $find_replace) {
      $this->taskReplaceInFile($find_replace['source'])
        ->from($find_replace['from'])
        ->to($find_replace['to'])
        ->run();
    }
  }
1193653
def _gitinfo():
    '''  '''
    result = None
    repo_path = os.path.join(os.path.dirname(__file__), '..', '..', '..', '.git')

    if os.path.exists(repo_path):
        # Check if the .git is a file. If it is a file, it means that we are in a submodule structure.
        if os.path.isfile(repo_path):
            try:
                gitdir = yaml.load(open(repo_path)).get('gitdir')
                # There is a posibility the .git file to have an absolute path.
                if os.path.isabs(gitdir):
                    repo_path = gitdir
                else:
                    repo_path = os.path.join(repo_path.split('.git')[0], gitdir)
            except (IOError, AttributeError):
                return ''
        f = open(os.path.join(repo_path, "HEAD"))
        branch = f.readline().split('/')[-1].rstrip("\n")
        f.close()
        branch_path = os.path.join(repo_path, "refs", "heads", branch)
        if os.path.exists(branch_path):
            f = open(branch_path)
            commit = f.readline()[:10]
            f.close()
            date = time.localtime(os.stat(branch_path).st_mtime)
            if time.daylight == 0:
                offset = time.timezone
            else:
                offset = time.altzone
            result = "({0} {1}) last updated {2} (GMT {3:+04d})".format(branch, commit,
                time.strftime("%Y/%m/%d %H:%M:%S", date), offset / -36)
    else:
        result = ''
    return result
792410
private function collectInformation(): void
    {
        if (!$this->collectVersionInfo) {
            return;
        }

        $basePath = $this->basePath;
        [$code, $ret,] = Sys::run('git log --pretty="%H" -n1 HEAD', $basePath);

        if ($code !== 0) {
            throw new \RuntimeException(
                'Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.'
            );
        }

        $this->version = \trim($ret);

        [$code, $ret,] = Sys::run('git log -n1 --pretty=%ci HEAD', $basePath);

        if ($code !== 0) {
            throw new \RuntimeException(
                'Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.'
            );
        }

        $this->versionDate = new \DateTime(\trim($ret));
        $this->versionDate->setTimezone(new \DateTimeZone('UTC'));

        // 获取到最新的 tag
        [$code, $ret,] = Sys::run('git describe --tags --exact-match HEAD', $basePath);
        if ($code === 0) {
            $this->version = \trim($ret);
        } else {
            [$code1, $ret,] = Sys::run('git branch', $basePath);

            if ($code1 === 0) {
                $this->branchAliasVersion = \explode("\n", \trim($ret, "* \n"), 2)[0];
            }
        }
    }