git: Ensure that everything is clean

This commit is contained in:
Oliver Davies 2020-06-01 19:54:57 +01:00
parent 964472bbf5
commit 66e1869c72

View file

@ -48,6 +48,7 @@ class ClosesPullRequests
{ {
$this->confirmCiStatusIsPassing(); $this->confirmCiStatusIsPassing();
// TODO: Check that the current branch has a tracking branch. // TODO: Check that the current branch has a tracking branch.
$this->ensureWorkingDirectoryAndIndexAreClean();
$this->fetchOrigin(); $this->fetchOrigin();
$this->ensureFeatureBranchInSync(); $this->ensureFeatureBranchInSync();
$this->ensureTargetBranchInSync(); $this->ensureTargetBranchInSync();
@ -58,6 +59,18 @@ class ClosesPullRequests
$this->deleteLocalBranch(); $this->deleteLocalBranch();
} }
private function ensureWorkingDirectoryAndIndexAreClean(): void
{
echo 'Ensuring that index and working directory are clean...' . PHP_EOL;
$isIndexClean = $this->run('git diff --cached --exit-code', self::RUN_TYPE_COMMAND);
$isWorkingDirClean = $this->run('git diff --exit-code', self::RUN_TYPE_COMMAND);
if (!$isIndexClean || !$isWorkingDirClean) {
$this->dieWithMessage('Index or working dir not clean. Aborting.');
}
}
private function getTargetBranchFromArgs(): string private function getTargetBranchFromArgs(): string
{ {
if (!$targetBranchName = $this->getArg('t:', ['target:'])) { if (!$targetBranchName = $this->getArg('t:', ['target:'])) {