Retrieve the latest tag from a branch.

@param string $branch The branch name to retrieve the tag from.

@return null|string Returns null when no tag has been found, the tag name otherwise.
190754
protected function getTagFromBranch($branch)
    {
        $git  = new GitRepository($this->input->getArgument('git-dir'));
        $tag  = trim($git->describe()->tags()->always()->execute($branch));
        $hash = trim($git->revParse()->short(false)->execute($branch));
        return $hash !== $tag ? $tag : null;
    }
943655
public function getMainBranch()
    {
        $filtered = array_filter(
            $this->getBranches(),
            function (Branch $branch) {
                return $branch->getCurrent();
            }
        );
        sort($filtered);

        return $filtered[0];
    }
151445
public function lastTag(string $name)
    {
        $lastTag = null;

        foreach ($this->tags as $tag) {
            if ($tag->name == $name) {
                $lastTag = $tag;
            }
        }

        return $lastTag;
    }
122611
public function getHoursLoggedForLastMonth($project = null, $branches = null)
    {
        $startDate   = date_format(date_sub(date_create(), date_interval_create_from_date_string('1 month')), 'm/01/Y');
        $endDate = date_format(date_sub(date_create(), date_interval_create_from_date_string('1 month')), 'm/t/Y');

        return $this->getHoursLoggedFor($startDate, $endDate, $project, $branches);
    }
615516
public function getNextTag($prefix = null)
    {
        $existingTags = $this->listPrefixedTags($prefix);

        $lastTag = array_pop($existingTags);

        if (0 >= preg_match('/^[0-9]+\.[0-9]+\.[0-9]+$/', $lastTag, $matches)) {
            throw new \RuntimeException(sprintf("Unable to parse latest tag, expected pattern X.X.X, found: %s", $lastTag), 22);
        }

        list ($major, $minor, $release) = explode('.', $lastTag, 3);

        return sprintf('%s.%s.%s', $major, $minor, (((int) $release) + 1));
    }
422529
protected function optimizeBranchesHead(array &$branches)
	{
		// Capture common output
		$before = $this->optimizeBranchesOutput($branches, 'head');

		// Move the branch output to the tail for branches that have no body
		foreach ($branches as &$branch)
		{
			if ($branch['body'] !== '' || !empty($branch['tail']))
			{
				continue;
			}

			$branch['tail'] = array_reverse($branch['head']);
			$branch['head'] = [];
		}
		unset($branch);

		return $before;
	}
564205
public function getFirstChild(Branch $branch = null)
    {
        if (null === $branch) {
            return null;
        }

        //reset return first child or false if is not found
        $children = $branch->getChildren();
        $first = reset($children);

        return $first ? $first : null;
    }
1210022
public function getHoursLoggedForThisMonth($project = null, $branches = null)
    {
        $startDate   = date('m/01/Y');
        $endDate = date('m/d/Y');

        return $this->getHoursLoggedFor($startDate, $endDate, $project, $branches);
    }
1219794
public function lastIndexByName($name) {
        for ($i = count($this->tokens) - 1; $i >= 0; $i--) {
            if ($this->tokens[$i]->getName() === $name) {
                return $i;
            }
        }

        return null;
    }
632986
public static function execute()
    {
        $release = null;

        // Get release-name from branch
        $input = \Deployer\input();
        if ($input->hasOption('branch')) {
            $branch = $input->getOption('branch');
            if (!empty($branch)) {
                $release = $branch;
            }
        }

        if ($release !== null) {
            return $release;
        }

        // Get release-name from tag
        $input = \Deployer\input();
        if ($input->hasOption('tag')) {
            $tag = $input->getOption('tag');
            if (!empty($tag)) {
                $release = $tag;
            }
        }

        if ($release !== null) {
            return $release;
        }

        $release = date('Ymdhis');

        return $release;
    }
740977
function find_ancestor_tag($tag)
    {
        global $debugObject;
        if (is_object($debugObject)) { $debugObject->debugLogEntry(1); }

        // Start by including ourselves in the comparison.
        $returnDom = $this;

        while (!is_null($returnDom))
        {
            if (is_object($debugObject)) { $debugObject->debugLog(2, "Current tag is: " . $returnDom->tag); }

            if ($returnDom->tag == $tag)
            {
                break;
            }
            $returnDom = $returnDom->parent;
        }
        return $returnDom;
    }
345205
public function getTag($name)
		{
			$comment = $this->ref->getDocComment();
			preg_match('/@' .$name. '\s+(.+)/', $comment, $matches);
			return $matches ? $matches[1] : null;
		}
60839
private function retrieve_tag($tag)
    {
        if (isset($this->tags[$tag . 'count'])) { //if the openener is not in the Object we ignore it
            $temp_parent = $this->tags['parent']; //check to see if it's a closable tag.
            while ($temp_parent) { //till we reach '' (the initial value);
                if ($tag . $this->tags[$tag . 'count'] === $temp_parent) { //if this is it use it
                    break;
                }
                $temp_parent = isset($this->tags[$temp_parent . 'parent']) ? $this->tags[$temp_parent . 'parent'] : ''; //otherwise keep on climbing up the DOM Tree
            }
            if ($temp_parent) { //if we caught something
                $this->indent_level = $this->tags[$tag . $this->tags[$tag . 'count']]; //set the indent_level accordingly
                $this->tags['parent'] = $this->tags[$temp_parent . 'parent']; //and set the current parent
            }
            unset($this->tags[$tag . $this->tags[$tag . 'count'] . 'parent']); //delete the closed tags parent reference...
            unset($this->tags[$tag . $this->tags[$tag . 'count']]); //...and the tag itself
            if ($this->tags[$tag . 'count'] === 1) {
                unset($this->tags[$tag . 'count']);
            } else {
                $this->tags[$tag . 'count']--;
            }
        }
    }
547880
public function getFirstTag($name)
    {
        foreach ($this->tags as $i => $tag) {
            if (strtolower($tag->getName()) == $name) {
                return $this->tags[$i];
            }
        }

        return null;
    }
982323
public function updateSourceCode($branch = CFG_GIT_BRANCH)
    {
        // Check that name is not any other command
        if (!FileSystem::checkFileName($branch)) {
            return $this;
        }

        // To use this command owner of folder and git repository must be the same as web user
        exec('git reset --hard origin/' . $branch . ' 2>&1; git pull -v origin ' . $branch . ' 2>&1', $out);
        if ($out) {
            $this->result_message[] = $out;
        }

        // Clear all caches - may be required to show fresh data
        @Cacher::getInstance()->clearAllCaches();

        // Invalidate all frontend assets
        $setting = SettingEntityRepository::findOneEntityByCriteria(['name' => 'last_assets_invalidate_time']);
        if (!$setting) {
            $setting = new SettingEntity();
            $setting->setName('last_assets_invalidate_time');
        }

        $setting->setValue(NOW);
        $setting->save();

        return $this;
    }
1242520
public function getCurrentBranchName() {
		try {
			$branch = $this->extractFromCommand('git branch -a', function ($value) {
				if(isset($value[0]) && $value[0] === '*') {
					return trim(substr($value, 1));
				}
				
				return false;
			});
			if(is_array($branch)) {
				return $branch[0];
			}
		} catch(ShellException $e) {
		}
		throw new ShellException('Getting current branch name failed.');
	}
12662
public function fetch($remote = null, $branch = null, Array $options = array())
    {
        if ($remote instanceof Remote) {
            $remote = $remote->getName();
        }
        if ($branch instanceof Branch) {
            $branch = $branch->getName();
        }
        $normalizedOptions = $this->normalizeOptions($options, $this->fetchCmdSwitchOptions());

        $this->clearAll();
        $this->addCommandName(self::GIT_FETCH_COMMAND);

        foreach ($normalizedOptions as $value) {
            $this->addCommandArgument($value);
        }

        if (!is_null($remote)) {
            $this->addCommandSubject($remote);
        }
        if (!is_null($branch)) {
            $this->addCommandSubject2($branch);
        }

        return $this->getCommand();
    }