Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move git merge base to shell #77

Merged
merged 2 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions PhpcsChanged/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PhpcsChanged\CacheManager;
use function PhpcsChanged\{getNewPhpcsMessages, getNewPhpcsMessagesFromFiles, getVersion};
use function PhpcsChanged\SvnWorkflow\{getSvnUnifiedDiff, getSvnFileInfo, isNewSvnFile, getSvnUnmodifiedPhpcsOutput, getSvnModifiedPhpcsOutput, getSvnRevisionId};
use function PhpcsChanged\GitWorkflow\getGitMergeBase;

function getDebug(bool $debugEnabled): callable {
return
Expand Down Expand Up @@ -324,7 +323,7 @@ function runGitWorkflow(CliOptions $options, ShellOperator $shell, CacheManager
$shell->validateExecutableExists('cat', $cat);
$debug('executables are valid');
if ($options->gitBase) {
$options->gitBase = getGitMergeBase($git, [$shell, 'executeCommand'], $options->toArray(), $debug);
$options->gitBase = $shell->getGitMergeBase();
}
} catch(\Exception $err) {
$shell->printError($err->getMessage());
Expand Down
25 changes: 0 additions & 25 deletions PhpcsChanged/GitWorkflow.php

This file was deleted.

2 changes: 2 additions & 0 deletions PhpcsChanged/ShellOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public function getPhpcsOutputOfModifiedGitFile(string $fileName): string;
public function getPhpcsOutputOfUnmodifiedGitFile(string $fileName): string;

public function getGitUnifiedDiff(string $fileName): string;

public function getGitMergeBase(): string;
}
17 changes: 17 additions & 0 deletions PhpcsChanged/UnixShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ public function getGitUnifiedDiff(string $fileName): string {
return $unifiedDiff;
}

public function getGitMergeBase(): string {
if ($this->options->mode !== Modes::GIT_BASE) {
return '';
}
$debug = getDebug($this->options->debug);
$git = getenv('GIT') ?: 'git';
$mergeBaseCommand = "{$git} merge-base " . escapeshellarg($this->options->gitBase) . ' HEAD';
$debug('running merge-base command:', $mergeBaseCommand);
$mergeBase = $this->executeCommand($mergeBaseCommand);
if (! $mergeBase) {
$debug('merge-base command produced no output');
return $this->options->gitBase;
}
$debug('merge-base command output:', $mergeBase);
return trim($mergeBase);
}

public function isReadable(string $fileName): bool {
return is_readable($fileName);
}
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"files": [
"PhpcsChanged/Cli.php",
"PhpcsChanged/SvnWorkflow.php",
"PhpcsChanged/GitWorkflow.php",
"PhpcsChanged/functions.php"
]
},
Expand Down
1 change: 0 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@
require_once __DIR__ . '/PhpcsChanged/functions.php';
require_once __DIR__ . '/PhpcsChanged/Cli.php';
require_once __DIR__ . '/PhpcsChanged/SvnWorkflow.php';
require_once __DIR__ . '/PhpcsChanged/GitWorkflow.php';
13 changes: 13 additions & 0 deletions tests/helpers/TestShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,17 @@ public function getGitUnifiedDiff(string $fileName): string {
}
return $unifiedDiff;
}

public function getGitMergeBase(): string {
if ($this->options->mode !== Modes::GIT_BASE) {
return '';
}
$git = getenv('GIT') ?: 'git';
$mergeBaseCommand = "{$git} merge-base " . escapeshellarg($this->options->gitBase) . ' HEAD';
$mergeBase = $this->executeCommand($mergeBaseCommand);
if (! $mergeBase) {
return $this->options->gitBase;
}
return trim($mergeBase);
}
}