100% of 345OPs |
100% of 52Lines |
89% of 18Branches |
100% of 16Paths |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum\cli\commands; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum\cli |
| 7 |
; |
| 8 |
|
| 9 |
class git |
| 10 |
{
|
| 11 |
const defaultPath = 'git'; |
| 12 |
|
| 13 |
protected $command = null; |
| 14 |
|
| 15 |
public function __construct($path = null)100% |
| 16 |
{
|
| 17 |
$this |
| 18 |
->setCommand() |
| 19 |
->setPath($path) |
| 20 |
; |
| 21 |
} |
| 22 |
|
| 23 |
public function setPath($path = null)100% |
| 24 |
{
|
| 25 |
$this->command->setBinaryPath($path ?: static::defaultPath); |
| 26 |
|
| 27 |
return $this; |
| 28 |
} |
| 29 |
|
| 30 |
public function getPath()100% |
| 31 |
{
|
| 32 |
return $this->command->getBinaryPath(); |
| 33 |
} |
| 34 |
|
| 35 |
public function setCommand(cli\command $command = null)100% |
| 36 |
{
|
| 37 |
$this->command = $command ?: new cli\command(); |
| 38 |
|
| 39 |
return $this; |
| 40 |
} |
| 41 |
|
| 42 |
public function getCommand()100% |
| 43 |
{
|
| 44 |
return $this->command; |
| 45 |
} |
| 46 |
|
| 47 |
public function addAllAndCommit($message)100% |
| 48 |
{
|
| 49 |
$this->command |
| 50 |
->reset() |
| 51 |
->addOption('commit -am \'' . addslashes($message) . '\'')
|
| 52 |
; |
| 53 |
|
| 54 |
return $this->run(); |
| 55 |
} |
| 56 |
|
| 57 |
public function resetHardTo($commit)100% |
| 58 |
{
|
| 59 |
$this->command |
| 60 |
->reset() |
| 61 |
->addOption('reset --hard ' . $commit)
|
| 62 |
; |
| 63 |
|
| 64 |
return $this->run(); |
| 65 |
} |
| 66 |
|
| 67 |
public function createTag($tag)100% |
| 68 |
{
|
| 69 |
$this->command |
| 70 |
->reset() |
| 71 |
->addOption('tag ' . $tag)
|
| 72 |
; |
| 73 |
|
| 74 |
return $this->run(); |
| 75 |
} |
| 76 |
|
| 77 |
public function deleteLocalTag($tag)100% |
| 78 |
{
|
| 79 |
$this->command |
| 80 |
->reset() |
| 81 |
->addOption('tag -d ' . $tag)
|
| 82 |
; |
| 83 |
|
| 84 |
return $this->run(); |
| 85 |
} |
| 86 |
|
| 87 |
public function push($remote = null, $branch = null)100% |
| 88 |
{
|
| 89 |
$this->command |
| 90 |
->reset() |
| 91 |
->addOption('push ' . ($remote ?: 'origin') . ' ' . ($branch ?: $this->getCurrentBranch()))
|
| 92 |
; |
| 93 |
|
| 94 |
return $this->run(); |
| 95 |
} |
| 96 |
|
| 97 |
public function forcePush($remote = null, $branch = null)100% |
| 98 |
{
|
| 99 |
$this->command |
| 100 |
->reset() |
| 101 |
->addOption('push --force ' . ($remote ?: 'origin') . ' ' . ($branch ?: $this->getCurrentBranch()))
|
| 102 |
; |
| 103 |
|
| 104 |
return $this->run(); |
| 105 |
} |
| 106 |
|
| 107 |
public function pushTag($tag, $remote = null)100% |
| 108 |
{
|
| 109 |
$this->command |
| 110 |
->reset() |
| 111 |
->addOption('push ' . ($remote ?: 'origin') . ' ' . $tag)
|
| 112 |
; |
| 113 |
|
| 114 |
return $this->run(); |
| 115 |
} |
| 116 |
|
| 117 |
public function checkoutAllFiles()100% |
| 118 |
{
|
| 119 |
$this->command |
| 120 |
->reset() |
| 121 |
->addOption('checkout .')
|
| 122 |
; |
| 123 |
|
| 124 |
return $this->run(); |
| 125 |
} |
| 126 |
|
| 127 |
protected function run()100% |
| 128 |
{
|
| 129 |
if ($this->command->run()->getExitCode() !== 0) |
| 130 |
{
|
| 131 |
throw new cli\command\exception('Unable to execute \'' . $this->command . '\': ' . $this->command->getStderr());
|
| 132 |
} |
| 133 |
|
| 134 |
return $this; |
| 135 |
} |
| 136 |
|
| 137 |
public function getCurrentBranch()100% |
| 138 |
{
|
| 139 |
$this->command |
| 140 |
->reset() |
| 141 |
->addOption('rev-parse --abbrev-ref HEAD')
|
| 142 |
; |
| 143 |
|
| 144 |
$branch = trim($this->run()->command->getStdout()) ?: 'master'; |
| 145 |
|
| 146 |
$this->command->reset(); |
| 147 |
|
| 148 |
return $branch; |
| 149 |
} |
| 150 |
} |