Collect git information

@return Collection
177459
public function collectFromGit()
    {
        // Initial git data
        $git = new Collection();

        $gitDirectory = $this->getDirectory().DIRECTORY_SEPARATOR.self::GIT_DIRECTORY;

        if (is_dir($gitDirectory)) {
            // Get refs info from HEAD
            $branch = '';
            $head = Yaml::parse($gitDirectory.DIRECTORY_SEPARATOR.self::GIT_HEAD);

            // @codeCoverageIgnoreStart
            if (is_array($head) && array_key_exists('ref', $head)) {
                $ref = $head['ref'];
                $r = explode('/', $ref);
                $branch = array_pop($r);
            } 
            // @codeCoverageIgnoreEnd

            // Assign branch information
            $git->set('branch', $branch);

            // Get log information
            $logRaw = self::execute('cd '.$this->getDirectory().';git log -1');
            $idRaw = $logRaw[0];
            $authorRaw = $logRaw[1];

            // Build head information
            if (strpos($authorRaw, '<') !== false) {
                 list($author, $email) = explode('<', str_replace('Author:', '', $authorRaw));

                $id = trim(str_replace('commit', '', $idRaw));
                $author_name = $committer_name = trim($author);
                $author_email = $committer_email = trim($email, '>');
                $message = $logRaw[4].(isset($logRaw[5]) ? '...' : '');
            }
           

            // Assign Head information
            $git->set('head', compact('id', 'author_name', 'author_email', 
                            'committer_name', 'committer_email', 'message'));

            // Get remotes information
            $remotes = array();
            $configRaw = self::execute('cd '.$this->getDirectory().';git config --local -l');
            array_walk($configRaw,function($v) use(&$remotes)
            {
                if (0 === strpos($v, 'remote')) {
                    list($key, $prop) = explode('=', $v);
                    $k = explode('.', $key);
                    $attribute = array_pop($k);
                    $name = array_pop($k);
                    $remotes[$name]['name'] = $name;
                    $remotes[$name][$attribute] = $prop;
                }
            });

            // Assign Remotes information
            $git->set('remotes', array_values($remotes));
        }

        return $git;
    }
554888
protected function collectCommit()
    {
        $commitResult = $this->command->getHeadCommit();

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

        $commit = new Commit();

        return $commit
            ->setId($commitResult[0])
            ->setAuthorName($commitResult[1])
            ->setAuthorEmail($commitResult[2])
            ->setCommitterName($commitResult[3])
            ->setCommitterEmail($commitResult[4])
            ->setMessage($commitResult[5]);
    }
190821
public function updateMany(): Collection
	{
		$collection = new Collection();

		foreach ($this->getInput() as $item) {
			$repository = clone $this;
			$repository->setInput($item);
			$collection->add($repository->update($repository->getInputId()));
		}

		return $collection;
	}
167315
public function duplicateCollection()
    {
        $app = Application::getFacadeApplication();
        $cloner = $app->make(Cloner::class);
        $clonerOptions = $app->build(ClonerOptions::class)->setKeepOriginalAuthor(true);
        $newCollection = $cloner->cloneCollection($this, $clonerOptions);

        return $newCollection;
    }
367739
public function count() {
        $repo = $this->getRepository();

        return $repo->aggregate($this->limit(0), __FUNCTION__, $repo->getPrimaryKey());
    }
805663
public function all()
    {
        $key = $this->getKey();

        $tags = $this->getTags();

        if ($this->cache->has($key, $tags)) {
            return $this->cache->get($key, $tags);
        }

        $collection = $this->repo->all();

        $this->cache->put($key, $collection, $tags);

        return $collection;
    }
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];
            }
        }
    }
736499
public function collect(Request $request, Response $response, \Exception $exception = null)
	{

		$fs = new Filesystem();

		// is there a web directory ?

		if ($fs->exists('../web') || $fs->exists('../public_html') || $fs->exists('../public')) {
			$gitPath = '../.git';
		} else {
			// unit tests
			$gitPath = '.git';
		}

		// if there is no .git directory
		if (!$fs->exists($gitPath)) {
			$this->data['gitData'] = false;
			return;
		}

		// get latest commit information
		exec("git log -1", $data);

		if (isset($data) && !empty($data)) {

			// there is some information
			$this->data['gitData'] = true;

			foreach ($data as $d) {

				if (strpos($d, 'commit') === 0) {

					// commit Id

					$this->data['commit'] = substr($d, 7);

				} elseif (strpos($d, 'Author') === 0) {

					// author and email

					preg_match('$Author: ([^<]+)<(.+)>$', $d, $author);

					if (isset($author[1])) {
						$this->data['author'] = trim($author[1]);
					}
					if (isset($author[2])) {
						$this->data['email'] = $author[2];
					}

				} elseif (strpos($d, 'Date') === 0) {

					$date = trim(substr($d, 5)); // ddd mmm n hh:mm:ss yyyy +gmt

					// date of commit
					$dateCommit = date_create($date);

					// actual date at runtime
					$dateRuntime = new \DateTime();
					$dateNow = date_create($dateRuntime->format('Y-m-d H:i:s'));

					// difference
					$time = date_diff($dateCommit, $dateNow);

					// static time difference : minutes and seconds
					$this->data['timeCommitIntervalMinutes'] = $time->format('%y')*365*24*60+$time->format('%m')*30*24*60+$time->format('%d')*24*60+$time->format('%h')*60+$time->format('%i');
					$this->data['timeCommitIntervalSeconds'] = $time->format('%s');

					// full readable date
					$this->data['date'] = $date;

				} elseif (strpos($d, 'Merge') === 0) {

					// merge information

					$this->data['merge'] = trim(substr($d, 6));

				} else {

					// commit message

					$this->data['message'] = trim($d);

				}

			}

			unset($data);

			exec("git status", $data);

			if (isset($data[0])) {

				if (strstr($data[0], 'On branch')) {

					// branch name

					$this->data['branch'] = trim(substr($data[0], strpos($data[0], 'On branch')+9));

				}
			}

		} else {

			// no git data

			$this->data['gitData'] = false;

		}


	}
1061501
protected function collectBranch()
    {
        $branchesResult = $this->command->getBranches();

        foreach ($branchesResult as $result) {
            if (strpos($result, '* ') === 0) {
                $exploded = explode('* ', $result, 2);

                return $exploded[1];
            }
        }

        throw new \RuntimeException();
    }
1291041
public function collectSiteMapItems()
    {
        $itemCollection = [];
        $modules = config('site-mapped-modules', [
            'blog' => 'Grafite\Cms\Repositories\BlogRepository',
            'page' => 'Grafite\Cms\Repositories\PageRepository',
            'events' => 'Grafite\Cms\Repositories\EventRepository',
        ]);

        foreach ($modules as $module => $repository) {
            try {
                $items = collect([]);

                if (method_exists($repository, 'arePublic')) {
                    $items = app($repository)->arePublic();
                }

                foreach ($items as $item) {
                    $itemCollection[] = [
                        'url' => url($module.'/'.$item->url),
                        'updated_at' => $item->updated_at->format('Y-m-d'),
                    ];
                }
            } catch (ReflectionException $e) {
                // It just means we couldn't find
                // the Repository class
            }
        }

        return collect($itemCollection);
    }
643596
public function listCollections() {

        foreach ($this->getCollectionNames() as $name) {
            if(!isset($this->collections[$name])) {
                $this->collections[$name] = new Collection($name, $this);
            }
        }

        return $this->collections;
    }
591075
private function loadCollections()
    {
        $collections = new ArrayCollection();

        $finder = new Finder();
        $finder->files()->name('*.dat')->in($this->filepath);

        foreach ($finder as $file) {
            $name = $file->getBasename('.dat');
            $collections->set($name, $this->createCollection($name));
        }

        return $collections;
    }
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;
    }
  }
861170
public static function getCollection()
    {
        $collections = [
            JSON_ERROR_NONE => null,
            JSON_ERROR_DEPTH => [
                'message' => 'Maximum stack depth exceeded',
                'error-code' => 1,
            ],
            JSON_ERROR_STATE_MISMATCH => [
                'message' => 'Underflow or the modes mismatch',
                'error-code' => 2,
            ],
            JSON_ERROR_CTRL_CHAR => [
                'message' => 'Unexpected control char found',
                'error-code' => 3,
            ],
            JSON_ERROR_SYNTAX => [
                'message' => 'Syntax error, malformed JSON',
                'error-code' => 4,
            ],
            JSON_ERROR_UTF8 => [
                'message' => 'Malformed UTF-8 characters',
                'error-code' => 5,
            ],
            JSON_ERROR_RECURSION => [
                'message' => 'Recursion error in value to be encoded',
                'error-code' => 6,
            ],
            JSON_ERROR_INF_OR_NAN => [
                'message' => 'Error NAN/INF in value to be encoded',
                'error-code' => 7,
            ],
            JSON_ERROR_UNSUPPORTED_TYPE => [
                'message' => 'Type value given cannot be encoded',
                'error-code' => 8,
            ],
            'default' => [
                'message' => 'Unknown error',
                'error-code' => 999,
            ],
        ];

        if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
            $collections[JSON_ERROR_INVALID_PROPERTY_NAME] = [
                'message' => 'Name value given cannot be encoded',
                'error-code' => 9,
            ];
            $collections[JSON_ERROR_UTF16] = [
                'message' => 'Malformed UTF-16 characters',
                'error-code' => 10,
            ];
        }

        return $collections;
    }
307814
public function collect() : array
    {
        $this->readEnv = [];

        $this
            ->fillTravisCi()
            ->fillCircleCi()
            ->fillAppVeyor()
            ->fillJenkins()
            ->fillScrutinizer();

        return $this->readEnv;
    }
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;
    }
555426
public function collectConfigs()
    {
        if (!$this->collectedConfig) {
            $config = $this->config;
            foreach ($this->bundles as $bundle) {
                $reflection = new \ReflectionClass($bundle);
                if (is_file($file = dirname($reflection->getFileName()) . '/Resources/config/requirejs.yml')) {
                    $bundleConfig = Yaml::parse(file_get_contents(realpath($file)));
                    $config = array_merge_recursive($config, $bundleConfig);
                }
            }
            $this->collectedConfig = $config;
        }
        return $this->collectedConfig;
    }