Skip to content

Commit

Permalink
fix(git): quotes on values exec return
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Jan 22, 2021
1 parent b265d06 commit 4e78c4e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Helper/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class Git
{
/**
* @var string
*/
protected static $delimiter = '----DELIMITER---';

/**
* Run shell command on working dir.
*
Expand All @@ -14,8 +19,13 @@ class Git
protected static function run($string): string
{
$value = shell_exec($string);
$value = Formatter::clean((string)$value);

return Formatter::clean((string)$value);
// Fix for some git versions
$value = trim($value, "'");
$value = str_replace(self::$delimiter . "'\n'", self::$delimiter . "\n", $value);

return $value;
}

/**
Expand Down Expand Up @@ -82,9 +92,8 @@ public static function getRemoteUrl(): string
*/
public static function getCommits(string $options = ''): array
{
$commits = self::run("git log --pretty=format:'%B%H----DELIMITER----' {$options}") . "\n";

$commitsArray = explode("----DELIMITER----\n", $commits);
$commits = self::run("git log --pretty=format:'%B%H" . self::$delimiter . "' {$options}") . "\n";
$commitsArray = explode(self::$delimiter . "\n", $commits);
array_pop($commitsArray);

return $commitsArray;
Expand All @@ -95,8 +104,8 @@ public static function getCommits(string $options = ''): array
*/
public static function getTags(): array
{
$tags = self::run("git tag --sort=-creatordate --list --format='%(refname:strip=2)----DELIMITER----'") . "\n";
$tagsArray = explode("----DELIMITER----\n", $tags);
$tags = self::run("git tag --sort=-creatordate --list --format='%(refname:strip=2)" . self::$delimiter . "'") . "\n";
$tagsArray = explode(self::$delimiter . "\n", $tags);
array_pop($tagsArray);

$tagsArray = array_reverse($tagsArray);
Expand Down

0 comments on commit 4e78c4e

Please sign in to comment.