Skip to content

Commit

Permalink
Reintroduce few removed line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Mar 21, 2020
1 parent a37fb18 commit 5c28c99
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/GitElephant/Command/Caller/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ public function execute(
if ($git) {
$cmd = $this->getBinaryPath() . ' ' . $cmd;
}

if (stripos(PHP_OS, 'WIN') !== 0) {
// We rely on the C locale in all output we parse.
$cmd = 'LC_ALL=C ' . $cmd;
}

if (is_null($cwd) || !is_dir($cwd)) {
$cwd = $this->repositoryPath;
}
Expand All @@ -102,6 +104,7 @@ public function execute(
// compatibility fix required for symfony/process versions prior to v4.2.
$process = new Process($cmd, $cwd);
}

$process->setTimeout(15000);
$process->run();
if (!in_array($process->getExitCode(), $acceptedExitCodes)) {
Expand All @@ -111,6 +114,7 @@ public function execute(
$text .= "\n" . $process->getOutput();
throw new \RuntimeException($text);
}

$this->rawOutput = $process->getOutput();
// rtrim values
$values = array_map('rtrim', explode(PHP_EOL, $process->getOutput()));
Expand Down
12 changes: 8 additions & 4 deletions src/GitElephant/Command/CloneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,34 @@ public function cloneUrl(
bool $recursive = false
): string {
// get binary version before reset
$v = $this->getBinaryVersion();
$version = $this->getBinaryVersion();

$this->clearAll();
$this->addCommandName(static::GIT_CLONE_COMMAND);
$this->addCommandSubject($url);
if (null !== $to) {
$this->addCommandSubject2($to);
}

if (null !== $repoReference) {
// git documentation says the --branch was added in 2.0.0, but it exists undocumented at least back to 1.8.3.1
if (version_compare($v, '1.8.3.1', '<')) {
if (version_compare($version, '1.8.3.1', '<')) {
throw new \RuntimeException(
'Please upgrade to git v1.8.3.1 or newer to support cloning a specific branch. You have ' . $v . '.'
'Please upgrade to git v1.8.3.1 or newer to support cloning a specific branch. You have ' . $version . '.'
);
}
$this->addCommandArgument('--branch=' . $repoReference);
}

if (null !== $depth) {
$this->addCommandArgument('--depth=' . $depth);
// shallow-submodules is a nice to have feature. Just ignoring if git version not high enough
// It would be nice if this had a logger injected for us to log notices
if (version_compare($v, '2.9.0', '>=') && $recursive && 1 == $depth) {
if (version_compare($version, '2.9.0', '>=') && $recursive && 1 == $depth) {
$this->addCommandArgument('--shallow-submodules');
}
}

if ($recursive) {
$this->addCommandArgument('--recursive');
}
Expand Down
4 changes: 4 additions & 0 deletions src/GitElephant/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,23 @@ public function diff($of, $with = null, $path = null): string
$this->addCommandArgument('-M');
$this->addCommandArgument('--dst-prefix=DST/');
$this->addCommandArgument('--src-prefix=SRC/');

$subject = '';

if (is_null($with)) {
$subject .= $of . '^..' . $of;
} else {
$subject .= $with . '..' . $of;
}

if (!is_null($path)) {
if (!is_string($path)) {
/** @var Object $path */
$path = $path->getPath();
}
$this->addPath($path);
}

$this->addCommandSubject($subject);

return $this->getCommand();
Expand Down
4 changes: 4 additions & 0 deletions src/GitElephant/Command/FetchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ public function fetch($remote = null, $branch = null, array $options = []): stri
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);
}
Expand Down
7 changes: 7 additions & 0 deletions src/GitElephant/Command/LogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,34 @@ public function showObjectLog(NodeObject $obj, $branch = null, int $limit = null
public function showLog($ref, $path = null, $limit = null, int $offset = null, bool $firstParent = false): string
{
$this->clearAll();

$this->addCommandName(self::GIT_LOG);
$this->addCommandArgument('-s');
$this->addCommandArgument('--pretty=raw');
$this->addCommandArgument('--no-color');

if (null !== $limit) {
$limit = (int) $limit;
$this->addCommandArgument('--max-count=' . $limit);
}

if (null !== $offset) {
$offset = (int) $offset;
$this->addCommandArgument('--skip=' . $offset);
}

if ($firstParent) {
$this->addCommandArgument('--first-parent');
}

if ($ref instanceof TreeishInterface) {
$ref = $ref->getSha();
}

if (null !== $path && !empty($path)) {
$this->addPath($path);
}

$this->addCommandSubject($ref);

return $this->getCommand();
Expand Down
8 changes: 8 additions & 0 deletions src/GitElephant/Command/LogRangeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,38 @@ public function showLog(
$firstParent = false
): string {
$this->clearAll();

$this->addCommandName(self::GIT_LOG);
$this->addCommandArgument('-s');
$this->addCommandArgument('--pretty=raw');
$this->addCommandArgument('--no-color');

if (null !== $limit) {
$limit = (int) $limit;
$this->addCommandArgument('--max-count=' . $limit);
}

if (null !== $offset) {
$offset = (int) $offset;
$this->addCommandArgument('--skip=' . $offset);
}

if ($firstParent) {
$this->addCommandArgument('--first-parent');
}

if ($refStart instanceof TreeishInterface) {
$refStart = $refStart->getSha();
}

if ($refEnd instanceof TreeishInterface) {
$refEnd = $refEnd->getSha();
}

if (null !== $path && !empty($path)) {
$this->addPath($path);
}

$this->addCommandSubject($refStart . '..' . $refEnd);

return $this->getCommand();
Expand Down
5 changes: 4 additions & 1 deletion src/GitElephant/Command/LsTreeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ public function tree($ref = 'HEAD', $path = null): string
} else {
$subjectPath = $path;
}

$what = $ref;
if ($ref instanceof TreeishInterface) {
$what = $ref->getSha();
}
$subject = $what;

$this->clearAll();

$this->addCommandName(self::LS_TREE_COMMAND);
$this->addCommandArgument('-l');
$subject = $what;
$this->addCommandSubject($subject);
$this->addPath($subjectPath);

Expand Down
15 changes: 15 additions & 0 deletions src/GitElephant/Command/MainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,25 @@ public function unstage($what): string
public function commit($message, $stageAll = false, $author = null, $allowEmpty = false): string
{
$this->clearAll();

if (trim($message) === '' || is_null($message)) {
throw new \InvalidArgumentException(sprintf('You can\'t commit without message'));
}
$this->addCommandName(self::GIT_COMMIT);

if ($stageAll) {
$this->addCommandArgument('-a');
}

if ($author !== null) {
$this->addCommandArgument('--author');
$this->addCommandArgument($author);
}

if ($allowEmpty) {
$this->addCommandArgument('--allow-empty');
}

$this->addCommandArgument('-m');
$this->addCommandSubject($message);

Expand All @@ -173,12 +178,14 @@ public function commit($message, $stageAll = false, $author = null, $allowEmpty
public function checkout($ref): string
{
$this->clearAll();

$what = $ref;
if ($ref instanceof Branch) {
$what = $ref->getName();
} elseif ($ref instanceof TreeishInterface) {
$what = $ref->getSha();
}

$this->addCommandName(self::GIT_CHECKOUT);
$this->addCommandArgument('-q');
$this->addCommandSubject($what);
Expand All @@ -199,14 +206,17 @@ public function checkout($ref): string
public function move($from, $to): string
{
$this->clearAll();

$from = trim($from);
if (!$this->validatePath($from)) {
throw new \InvalidArgumentException('Invalid source path');
}

$to = trim($to);
if (!$this->validatePath($to)) {
throw new \InvalidArgumentException('Invalid destination path');
}

$this->addCommandName(self::GIT_MOVE);
$this->addCommandSubject($from);
$this->addCommandSubject2($to);
Expand All @@ -228,17 +238,22 @@ public function move($from, $to): string
public function remove($path, $recursive, $force): string
{
$this->clearAll();

$path = trim($path);
if (!$this->validatePath($path)) {
throw new \InvalidArgumentException('Invalid path');
}

$this->addCommandName(self::GIT_REMOVE);

if ($recursive) {
$this->addCommandArgument('-r');
}

if ($force) {
$this->addCommandArgument('-f');
}

$this->addPath($path);

return $this->getCommand();
Expand Down
5 changes: 5 additions & 0 deletions src/GitElephant/Command/MergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,21 @@ public function merge(Branch $with, $message = '', array $options = []): string
"Invalid options: cannot use flags --ff-only and --no-ff together."
);
}

$normalizedOptions = $this->normalizeOptions($options, $this->mergeCmdSwitchOptions());

$this->clearAll();
$this->addCommandName(static::MERGE_COMMAND);

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

if (!empty($message)) {
$this->addCommandArgument('-m');
$this->addCommandArgument($message);
}

$this->addCommandSubject($with->getFullRef());

return $this->getCommand();
Expand Down
5 changes: 4 additions & 1 deletion src/GitElephant/Command/PushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,19 @@ public function __construct(Repository $repo = null)
*/
public function push($remote = 'origin', $branch = 'master', string $args = null): string
{
$this->clearAll();

if ($remote instanceof Remote) {
$remote = $remote->getName();
}
if ($branch instanceof Branch) {
$branch = $branch->getName();
}
$this->clearAll();

$this->addCommandName(self::GIT_PUSH_COMMAND);
$this->addCommandSubject($remote);
$this->addCommandSubject2($branch);

if (!is_null($args)) {
$this->addCommandArgument($args);
}
Expand Down
1 change: 1 addition & 0 deletions src/GitElephant/Command/Remote/AddSubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function prepare($name, $url, $options = []): self
$this->addCmdSwitchOptions(),
$this->addCmdValueOptions()
);

$this->addCommandName(self::GIT_REMOTE_ADD);
$this->addCommandSubject($name);
$this->addCommandSubject($url);
Expand Down
1 change: 1 addition & 0 deletions src/GitElephant/Command/Remote/ShowSubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function prepare($name = null, $queryRemotes = true): self
if ($name) {
$this->addCommandSubject($name);
}

if (!$queryRemotes) {
$this->addCommandArgument('-n');
}
Expand Down
3 changes: 3 additions & 0 deletions src/GitElephant/Command/RemoteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ public function __construct(Repository $repo = null)
public function remote(SubCommandCommand $subcommand = null, array $options = []): string
{
$normalizedOptions = $this->normalizeOptions($options, $this->remoteCmdSwitchOptions());

$this->clearAll();

$this->addCommandName(self::GIT_REMOTE);

foreach ($normalizedOptions as $value) {
$this->addCommandArgument($value);
}
Expand Down
1 change: 1 addition & 0 deletions src/GitElephant/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function __construct(Repository $repo = null)
public function showCommit($ref): string
{
$this->clearAll();

$this->addCommandName(self::GIT_SHOW);
$this->addCommandArgument('-s');
$this->addCommandArgument('--pretty=raw');
Expand Down
6 changes: 6 additions & 0 deletions src/GitElephant/Command/StashCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ public function __construct(Repository $repo = null)
public function save($message = null, $includeUntracked = false, $keepIndex = false): string
{
$this->clearAll();

$this->addCommandName(self::STASH_COMMAND . ' save');

if (!is_null($message)) {
$this->addCommandSubject($message);
}

if ($includeUntracked) {
$this->addCommandArgument('--include-untracked');
}

if ($keepIndex) {
$this->addCommandArgument('--keep-index');
}
Expand All @@ -79,7 +83,9 @@ public function save($message = null, $includeUntracked = false, $keepIndex = fa
public function listStashes(array $options = null): string
{
$this->clearAll();

$this->addCommandName(self::STASH_COMMAND . ' list');

if (null !== $options) {
$this->addCommandSubject($options);
}
Expand Down
Loading

0 comments on commit 5c28c99

Please sign in to comment.