diff --git a/src/Vcs/Driver/GitDriver.php b/src/Vcs/Driver/GitDriver.php index d171355..a923aec 100644 --- a/src/Vcs/Driver/GitDriver.php +++ b/src/Vcs/Driver/GitDriver.php @@ -50,6 +50,7 @@ public function tag($tag, $branch, $path) try { $this->getGit()->getAdapter()->execute('tag', array($tag), $path); $this->getGit()->getAdapter()->execute('pull', ['origin', $branch], $path); + $this->getGit()->getAdapter()->execute('branch', [$branch ,'origin/' . $branch, '-f'], $path); $this->getGit()->getAdapter()->execute('push', ['origin', $branch], $path); $this->getGit()->getAdapter()->execute('push', array('origin', 'tag', $tag), $path); } catch (\Exception $e) { @@ -112,7 +113,6 @@ public function hasChangesSinceTag($tag, $branch, $path, OutputInterface $output { try { $this->getGit()->getAdapter()->execute('fetch', ['origin'], $path); - $this->getGit()->getAdapter()->execute('branch', [$branch ,'origin/' . $branch, '-f'], $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')) { diff --git a/test/Vcs/Driver/GitDriverTest.php b/test/Vcs/Driver/GitDriverTest.php index 8fa145a..401fade 100644 --- a/test/Vcs/Driver/GitDriverTest.php +++ b/test/Vcs/Driver/GitDriverTest.php @@ -42,12 +42,18 @@ public function shouldTagAndPush() ); $adapter->expects($this->at(2))->method('execute')->with( + 'branch', + array('myBranch', 'feature/myBranch', '-f'), + '/home/my/vcs/repo' + ); + + $adapter->expects($this->at(3))->method('execute')->with( 'push', array('origin', 'feature/myBranch'), '/home/my/vcs/repo' ); - $adapter->expects($this->at(3))->method('execute')->with( + $adapter->expects($this->at(4))->method('execute')->with( 'push', array('origin', 'tag', '0.2.5'), '/home/my/vcs/repo' @@ -57,11 +63,11 @@ public function shouldTagAndPush() ->disableOriginalConstructor() ->setMethods(array('getAdapter')) ->getMock(); - $git->expects($this->exactly(4))->method('getAdapter')->will($this->returnValue($adapter)); + $git->expects($this->any())->method('getAdapter')->will($this->returnValue($adapter)); $driver = $this->givenADriver(); - $driver->expects($this->exactly(4))->method('getGit')->will( + $driver->expects($this->any())->method('getGit')->will( $this->returnValue($git) ); @@ -93,18 +99,24 @@ public function shouldCleanOnError() ); $adapter->expects($this->at(2))->method('execute')->with( + 'branch', + array('myBranch', 'feature/myBranch', '-f'), + '/home/my/vcs/repo' + ); + + $adapter->expects($this->at(3))->method('execute')->with( 'push', array('origin', 'master'), '/home/my/vcs/repo' )->will($this->throwException(new \Exception('could not push to remote'))); - $adapter->expects($this->at(3))->method('execute')->with( + $adapter->expects($this->at(4))->method('execute')->with( 'reset', array('--hard'), '/home/my/vcs/repo' ); - $adapter->expects($this->at(4))->method('execute')->with( + $adapter->expects($this->at(5))->method('execute')->with( 'tag', array('-d', '0.2.5'), '/home/my/vcs/repo' @@ -114,11 +126,11 @@ public function shouldCleanOnError() ->disableOriginalConstructor() ->setMethods(array('getAdapter')) ->getMock(); - $git->expects($this->exactly(5))->method('getAdapter')->will($this->returnValue($adapter)); + $git->expects($this->exactly(6))->method('getAdapter')->will($this->returnValue($adapter)); $driver = $this->givenADriver(); - $driver->expects($this->exactly(5))->method('getGit')->will( + $driver->expects($this->exactly(6))->method('getGit')->will( $this->returnValue($git) );