Collect all files with their commits.

@param GitRepository $git The git repository.

@return void
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;
    }
73814
public function ensureGitRemote($dir, $url)
    {
        if (!file_exists($dir . '/.git')) {
            throw new \InvalidArgumentException('The directory is not a Git repository');
        }
        $this->git->ensureInstalled();
        $currentUrl = $this->git->getConfig(
            sprintf('remote.%s.url', $this->config->get('detection.git_remote_name')),
            $dir
        );
        if (!$currentUrl) {
            $this->git->execute(
                ['remote', 'add', $this->config->get('detection.git_remote_name'), $url],
                $dir,
                true
            );
        } elseif ($currentUrl !== $url) {
            $this->git->execute([
                'remote',
                'set-url',
                $this->config->get('detection.git_remote_name'),
                $url
            ], $dir, true);
        }
    }
104081
private function repositoryAlreadySet($config, $repo)
    {
        if (!$config->repositories) {
            return false;
        } else {
            if (in_array($repo, $config->repositories)) {
                return true;
            } else {
                return false;
            }
        }
    }
15347
protected function collectRemotes()
    {
        $remotesResult = $this->executor->execute('git remote -v');

        if (count($remotesResult) === 0) {
            throw new \RuntimeException();
        }

        // parse command result
        $results = [];

        foreach ($remotesResult as $result) {
            if (strpos($result, ' ') !== false) {
                list($remote) = explode(' ', $result, 2);

                $results[] = $remote;
            }
        }

        // filter
        $results = array_unique($results);

        // create Remote instances
        $remotes = [];

        foreach ($results as $result) {
            if (strpos($result, "\t") !== false) {
                list($name, $url) = explode("\t", $result, 2);

                $remote = new RemoteInfo();
                $remotes[] = $remote->setName(trim($name))->setUrl(trim($url));
            }
        }

        return $remotes;
    }
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
                )
            );
        }
    }
230720
private void updateLocalRepository() throws GitAPIException {

        try {
            Git.open(new File(paasifyRepositoryDirecory)).pull().call();
        } catch (IOException e) {
            log.error("Cannot update local Git repository");
            log.error(e.getMessage());
        }
    }
677959
public function collect() : GitInfo
    {
        $branch = $this->collectBranch();
        $commit = $this->collectCommit();
        $remotes = $this->collectRemotes();

        return new GitInfo($branch, $commit, $remotes);
    }
260932
public function loadFrom(Repository $config, $configPath)
    {
        foreach ($this->filesIn($configPath) as $group => $configFile) {
            $config->set($group, require $configFile);
        }
    }
1294053
private function hasUncommittedChanges($git)
    {
        $status = $git->status()->short()->getIndexStatus();

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

        return true;
    }
547960
private function fetchAllFilesUnderGit()
  {
    $command = "git ls-files";
    exec($command, $output, $return);
    if ($return!=0) $this->logError("Can not execute command %s in exec", $command);

    foreach ($output as $filename)
    {
      $this->myLastCommitTimes[$filename] = 0;
    }
  }
894909
public function setDefault(): void
	{
		$repo = $this->getRepository();
		$locales = $repo->findAll();
		foreach ($locales as $locale) {
			/* @var $locale self */
			$locale->default = false;
			$repo->persist($locale);
		}
		$this->default = true;
		$repo->persist($this);
		$repo->flush();
	}
591484
def modified_files
      @modified_files ||= begin
        @modified_files = []

        rewritten_commits.each do |rewritten_commit|
          refs = "#{rewritten_commit.old_hash} #{rewritten_commit.new_hash}"
          @modified_files |= Overcommit::GitRepo.modified_files(refs: refs)
        end

        filter_modified_files(@modified_files)
      end
    end
360617
public function gitPull(bool $force = false): void
	{
		$this->maintenance();
		if ($force) {
			$this->git->update();
		} else {
			$this->git->authorizedUpdate();
		}
		$this->maintenance(false);
	}
1204702
def all_modified_files_coverage
      unless @project.nil?
        all_modified_files_coverage ||= begin
          modified_files = git.modified_files.nil? ? [] : git.modified_files
          added_files = git.added_files.nil? ? [] : git.added_files
          all_changed_files = modified_files | added_files
          @project.coverage_files.select do |file|
            all_changed_files.include? file.source_file_pathname_relative_to_repo_root.to_s
          end
        end

        all_modified_files_coverage
      end
    end
190893
def modified_files
      unless @modified_files
        currently_staged = Overcommit::GitRepo.modified_files(staged: true)
        @modified_files = currently_staged

        # Include files modified in last commit if amending
        if amendment?
          subcmd = 'show --format=%n'
          previously_modified = Overcommit::GitRepo.modified_files(subcmd: subcmd)
          @modified_files |= filter_modified_files(previously_modified)
        end
      end
      @modified_files
    end
630021
private function doSaveStash()
    {
        $pending = $this->repository->getWorkingCopy()->getDiffPending();
        if (!\count($pending->getFiles())) {
            return;
        }

        try {
            $this->io->write(['<fg=yellow>Detected unstaged changes... Stashing them!</fg=yellow>']);
            $this->repository->run('stash', ['save', '--quiet', '--keep-index', uniqid('grumphp')]);
        } catch (Exception $e) {
            // No worries ...
            $this->io->write([sprintf('<fg=red>Failed stashing changes: %s</fg=red>', $e->getMessage())]);

            return;
        }

        $this->stashIsApplied = true;
        $this->registerShutdownHandler();
    }
715075
void pull(File project) {
		try {
			try (Git git = this.gitFactory.open(project)) {
				PullCommand command = this.gitFactory.pull(git);
				command.setRebase(true).call();
			}
		}
		catch (Exception e) {
			throw new IllegalStateException(e);
		}
	}