Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
[FEATURE] RS-1988 aoe/tagging library checkout-Prozess anpassen
Browse files Browse the repository at this point in the history
  • Loading branch information
michael.sandritter committed Jul 19, 2016
1 parent d66ae1e commit 5882f86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 126 deletions.
30 changes: 1 addition & 29 deletions src/Vcs/Driver/GitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function hasChangesSinceTag($tag, $branch, $path, OutputInterface $output
{
try {
$this->getGit()->getAdapter()->execute('fetch', ['origin'], $path);
$this->checkoutBranch($branch, $path, $output);
$this->getGit()->getAdapter()->execute('branch', [$branch ,'origin/' . $branch, '-fq'], $path);
$diff = $this->getGit()->getAdapter()->execute('diff', array('--ignore-all-space', $tag), $path);
} catch (\RuntimeException $e) {
if (false !== strpos($e->getMessage(), 'unknown revision or path')) {
Expand All @@ -128,34 +128,6 @@ public function hasChangesSinceTag($tag, $branch, $path, OutputInterface $output
return true;
}

/**
* @param $branch
* @param $path
* @param OutputInterface $output
* @throws \Exception
*/
private function checkoutBranch($branch, $path, OutputInterface $output)
{
try {
$this->getGit()->getAdapter()->execute('checkout', ['-b', $branch ,'origin/' . $branch], $path);
} catch (\Exception $e) {
if (preg_match("/branch .+ already exists/", $e->getMessage()) === 1) {
$output->writeln(
sprintf(
'<info>checkout -b %s %s failed, because local branch "%s" already exists</info>',
$branch,
'origin/' . $branch,
$branch
)
);
$this->getGit()->getAdapter()->execute('checkout', [$branch], $path);
$output->writeln('<info>checkout local branch: "'. $branch .'"</info>');
} else {
throw $e;
}
}
}

/**
* @return Git
*/
Expand Down
105 changes: 8 additions & 97 deletions test/Vcs/Driver/GitDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public function shouldNotHaveChangesSinceTagWithNullValueFromGitAdapter()
);

$adapter->expects($this->at(1))->method('execute')->with(
'checkout',
array('-b', 'master', 'origin/master'),
'branch',
array('master', 'origin/master', '-fq'),
'/home/my/vcs/repo'
);

Expand All @@ -214,95 +214,6 @@ public function shouldNotHaveChangesSinceTagWithNullValueFromGitAdapter()
$this->assertFalse($driver->hasChangesSinceTag('0.2.5', 'master', '/home/my/vcs/repo', $output));
}

/**
* @test
*/
public function shouldCheckoutLocalBranchIfItAlreadyExists()
{
$adapter = $this->givenAnAdapter();
$output = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')
->disableOriginalConstructor()
->getMock();

$adapter->expects($this->at(0))->method('execute')->with(
'fetch',
array('origin'),
'/home/my/vcs/repo'
);

$adapter->expects($this->at(1))->method('execute')->with(
'checkout',
array('-b', 'master', 'origin/master'),
'/home/my/vcs/repo'
)->willThrowException(new \Exception('fatal: branch master already exists'));

$adapter->expects($this->at(2))->method('execute')->with(
'checkout',
array('master'),
'/home/my/vcs/repo'
);

$adapter->expects($this->at(3))->method('execute')->with(
'diff',
array('--ignore-all-space', '0.2.5'),
'/home/my/vcs/repo'
)->will($this->returnValue(null));

$git = $this->getMockBuilder('Webcreate\\Vcs\\Git')
->disableOriginalConstructor()
->setMethods(array('getAdapter'))
->getMock();
$git->expects($this->any())->method('getAdapter')->will($this->returnValue($adapter));

$driver = $this->givenADriver();

$driver->expects($this->any())->method('getGit')->will(
$this->returnValue($git)
);

/** @var GitDriver $driver */
$driver->hasChangesSinceTag('0.2.5', 'master', '/home/my/vcs/repo', $output);
}

/**
* @test
* @expectedException \Exception
*/
public function shouldThrowExceptionWhileTryingToCheckoutBranch()
{
$adapter = $this->givenAnAdapter();
$output = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')
->disableOriginalConstructor()
->getMock();

$adapter->expects($this->at(0))->method('execute')->with(
'fetch',
array('origin'),
'/home/my/vcs/repo'
);

$adapter->expects($this->at(1))->method('execute')->with(
'checkout',
array('-b', 'master', 'origin/master'),
'/home/my/vcs/repo'
)->willThrowException(new \Exception('fatal: something is wrong'));

$git = $this->getMockBuilder('Webcreate\\Vcs\\Git')
->disableOriginalConstructor()
->setMethods(array('getAdapter'))
->getMock();
$git->expects($this->any())->method('getAdapter')->will($this->returnValue($adapter));

$driver = $this->givenADriver();

$driver->expects($this->any())->method('getGit')->will(
$this->returnValue($git)
);

/** @var GitDriver $driver */
$driver->hasChangesSinceTag('0.2.5', 'master', '/home/my/vcs/repo', $output);
}

/**
* @test
*/
Expand All @@ -320,8 +231,8 @@ public function shouldNotHaveChangesSinceTagWithEmptyStringValueFromGitAdapter()
);

$adapter->expects($this->at(1))->method('execute')->with(
'checkout',
array('-b', 'master', 'origin/master'),
'branch',
array('master', 'origin/master', '-fq'),
'/home/my/vcs/repo'
);

Expand Down Expand Up @@ -365,8 +276,8 @@ public function shouldHaveChangesSinceTag()
);

$adapter->expects($this->at(1))->method('execute')->with(
'checkout',
array('-b', 'master', 'origin/master'),
'branch',
array('master', 'origin/master', '-fq'),
'/home/my/vcs/repo'
);

Expand Down Expand Up @@ -417,8 +328,8 @@ public function shouldHaveChangesSinceTagOnUnknownTag()
);

$adapter->expects($this->at(1))->method('execute')->with(
'checkout',
array('-b', 'master', 'origin/master'),
'branch',
array('master', 'origin/master', '-fq'),
'/home/my/vcs/repo'
);

Expand Down

0 comments on commit 5882f86

Please sign in to comment.