Fetch the current commit.

@param GitRepository $git The git repository.

@return array
770535
private function fetchCurrentCommit(GitRepository $git)
    {
        return \json_decode(
            \sprintf(
                '[%s]',
                // git show --format=$this->logFormat() --quiet
                $git->show()->format($this->logFormat())->execute('--quiet')
            ),
            true
        );
    }
467740
public function getCombinedStatus($owner, $repo, $ref)
	{
		$data = array();

		return $this->client->request("/repos/$owner/$repo/commits/$ref/status", 'GET', $data, 200, 'GitHubStatus', false);
	}
336168
public function repository(string $user, string $repo): ?array
    {
        $api = $this->client->api('repo');
        $params = [$user, $repo];

        $repo = $this->callGitHub([$api, 'show'], $params);

        return is_array($repo) ? $repo : null;
    }
513121
public function getCommitUrl(Repo $repo, $commitSHA)
    {
        return $this->helper->getCommitUrl($repo->getSlug(), $commitSHA);
    }
867109
public function get_remote_api_readme( $git, $request ) {
		if ( ! $this->local_file_exists( 'readme.txt' ) ) {
			return false;
		}

		$response = isset( $this->response['readme'] ) ? $this->response['readme'] : false;

		// Set $response from local file if no update available.
		if ( ! $response && ! $this->can_update_repo( $this->type ) ) {
			$response = $this->get_local_info( $this->type, 'readme.txt' );
		}

		if ( ! $response ) {
			self::$method = 'readme';
			$response     = $this->api( $request );
			$response     = $this->decode_response( $git, $response );
		}

		if ( ! $response && ! is_wp_error( $response ) ) {
			$response          = new \stdClass();
			$response->message = 'No readme found';
		}

		if ( $this->validate_response( $response ) ) {
			return false;
		}

		if ( $response && ! isset( $this->response['readme'] ) ) {
			$parser   = new Readme_Parser( $response );
			$response = $parser->parse_data();
			$this->set_repo_cache( 'readme', $response );
		}

		$this->set_readme_info( $response );

		return true;
	}
687435
public static function getRepositoryByUrl($url)
	{
		$remoteRepos = self::_getRemoteRepositories();
		foreach ($remoteRepos as $repo)
		{
			$config = $repo->getRepoConfig();
			if ($config['url'] == $url)
			{
				return $repo;
			}
		}
		return null;
	}
19512
public function getGitDir(): string
    {
        $gitDir = $this->config->getGitDir();
        if (!$this->fileSystem->exists($gitDir)) {
            throw new RuntimeException('The configured GIT directory could not be found.');
        }

        return $this->getRelativePath($gitDir);
    }
155865
public function getPersistence()
    {
        $persistence = $this->getContainer()->get('liip.translation.persistence');

        if (false === $persistence instanceof GitPersistence) {
            throw new \RuntimeException(sprintf(
                'Cannot initialize git repository, configured persistence should be "%s", "%s" given',
                'Liip\TranslationBundle\Persistence\GitPersistence',
                get_class($persistence)
            ));
        }

        return $persistence;
    }
865640
protected function parseGitUrl($gitUrl)
    {
        $gitDomain = $this->config->get('detection.git_domain');
        $pattern = '/^([a-z0-9]{12,})@git\.(([a-z0-9\-]+\.)?' . preg_quote($gitDomain) . '):\1\.git$/';
        if (!preg_match($pattern, $gitUrl, $matches)) {
            return false;
        }

        return ['id' => $matches[1], 'host' => $matches[2]];
    }
769245
public function collectFilesWithCommits(GitRepository $git)
    {
        // git show --format="%H" --quiet
        $lastCommitId = $git->show()->format('%H')->execute('--quiet');
        $cacheId      = \md5(__FUNCTION__ . $lastCommitId);

        if ($this->cachePool->has($cacheId)) {
            $fromCache = $this->cachePool->get($cacheId);

            $this->commitCollection   = $fromCache['commitCollection'];
            $this->filePathMapping    = $fromCache['filePathMapping'];
            $this->filePathCollection = $fromCache['filePathCollection'];

            return;
        }

        $commitCollection   = [];
        $filePathMapping    = [];
        $filePathCollection = [];

        $this->prepareCommitCollection(
            $git,
            $this->fetchAllCommits($git, $lastCommitId),
            $commitCollection,
            $filePathMapping,
            $filePathCollection
        );

        $this->cachePool->set(
            $cacheId,
            [
                'commitCollection'   => $commitCollection,
                'filePathMapping'    => $filePathMapping,
                'filePathCollection' => $filePathCollection
            ]
        );

        $this->commitCollection   = $commitCollection;
        $this->filePathMapping    = $filePathMapping;
        $this->filePathCollection = $filePathCollection;
    }
261780
public function getRepoURL(InputInterface $input, OutputInterface $output)
    {
        return 'git@github.com:' . $this->gitHubUsername($input,$output) . '/' . $this->repoName($input) . '.git';
    }
1132688
public static function extractRepositoryNameFromUrl($url) {
		// /path/to/repo.git => repo
		// host.xz:foo/.git => foo
		$directory = rtrim($url, '/');
		if(substr($directory, -5) === '/.git') {
			$directory = substr($directory, 0, -5);
		}
		$directory = basename($directory, '.git');
		if(($pos = strrpos($directory, ':')) !== false) {
			$directory = substr($directory, $pos + 1);
		}
		return $directory;
	}
1099893
private function buildFileHistory(GitRepository $git)
    {
        $filePath = $this->getFilePathCollection($this->currentPath);

        // If the commit history only merges,
        // then use the last merge commit for find the renaming file for follow the history.
        if (\count((array) $filePath['commits']) === $this->countMergeCommits($filePath['commits'])) {
            $commit = $filePath['commits'][\array_reverse(\array_keys($filePath['commits']))[0]];
            if ($this->isMergeCommit($commit)) {
                $parents = \explode(' ', $commit['parent']);

                $arguments = [
                    $git->getConfig()->getGitExecutablePath(),
                    'diff',
                    $commit['commit'],
                    $parents[1],
                    '--diff-filter=R',
                    '--name-status',
                    '--format=',
                    '-M'
                ];

                // git diff currentCommit rightCommit --diff-filter=R --name-status --format='' -M
                $matches = $this->matchFileInformation($this->runCustomGit($arguments, $git));
                foreach ($matches as $match) {
                    if (!\in_array($this->currentPath, $match)) {
                        continue;
                    }

                    $this->currentPath = $match['to'];
                    $filePath          = $this->getFilePathCollection($this->currentPath);
                    break;
                }
            }
        }

        $fileHistory = $this->fetchFileHistory($this->currentPath, $git);
        if (!\count($fileHistory)) {
            return;
        }

        foreach ($fileHistory as $pathHistory) {
            $filePath['pathHistory'][\md5($pathHistory)] = $this->getFilePathCollection($pathHistory);
        }

        $this->setFilePathCollection($this->currentPath, $filePath);
    }
143165
protected function fetchRepositoryUpdates(PackageInterface $package, $path, $url)
    {
        /**
         * Copy-pasted from doUpdate
         *
         * @see GitDownloader::doUpdate()
         */
        $this->io->write('    Checking out ' . $package->getSourceReference());
        $command = $this->getFetchCommand();
        $commandCallable = function ($url) use ($command) {
            return sprintf($command, ProcessExecutor::escape($url));
        };
        $this->gitUtil->runCommand($commandCallable, $url, $path);
        return $this;
    }
1294053
private function hasUncommittedChanges($git)
    {
        $status = $git->status()->short()->getIndexStatus();

        if (empty($status)) {
            return false;
        }

        return true;
    }
548867
public function getCommit()
    {
        $data = $this->object;
        if ($data['type'] !== 'commit') {
            throw new \RuntimeException('This ref is not a commit');
        }
        $url = Project::getProjectBaseFromUrl($this->getUri()) . '/git/commits';

        return Commit::get($data['sha'], $url, $this->client);
    }
606216
public function get_api_release_asset( $git, $request ) {
		$response = isset( $this->response['release_asset'] ) ? $this->response['release_asset'] : false;

		if ( $response && $this->exit_no_update( $response ) ) {
			return false;
		}

		if ( ! $response ) {
			self::$method = 'release_asset';
			$response     = $this->api( $request );
			$response     = $this->parse_release_asset( $git, $request, $response );

			if ( ! $response && ! is_wp_error( $response ) ) {
				$response          = new \stdClass();
				$response->message = 'No release asset found';
			}
		}

		if ( $response && ! isset( $this->response['release_asset'] ) ) {
			$this->set_repo_cache( 'release_asset', $response );
		}

		if ( $this->validate_response( $response ) ) {
			return false;
		}

		return $response;
	}