Skip to content

Commit

Permalink
updated deps and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosister committed May 27, 2013
1 parent e621327 commit 89071b3
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ the *Repository* class is the main class where you can find every method you nee
``` php
<?php
// get the current status
$repo->getStatus(); // returns an array of lines of the status message
$repo->getStatusOutput(); // returns an array of lines of the status message

// branches
$repo->getBranches(); // return an array of Branch objects
Expand Down
2 changes: 2 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ todo
* git blame
* blobs management
* submodules management
* remotes
* better status handling with --porcelain

31 changes: 17 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/GitElephant/Command/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function execute($cmd, $git = true, $cwd = null)
$process->setTimeout(15000);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
throw new \RuntimeException($process->getOutput());
}
$this->rawOutput = $process->getOutput();
// rtrim values
Expand Down
7 changes: 6 additions & 1 deletion src/GitElephant/Command/MainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ public function init()
/**
* Get the repository status
*
* @param bool $porcelain
*
* @return string
*/
public function status()
public function status($porcelain = false)
{
$this->clearAll();
$this->addCommandName(self::GIT_STATUS);
if ($porcelain) {
$this->addCommandArgument('--porcelain');
}

return $this->getCommand();
}
Expand Down
11 changes: 11 additions & 0 deletions src/GitElephant/Objects/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public function __construct(Repository $repository, $name)
$this->createFromCommand();
}

/**
* @param \GitElephant\Repository $repository repository instance
* @param string $name branch name
*
* @return Branch
*/
public static function checkout(Repository $repository, $name)
{
return new self($repository, $name);
}

/**
* get the branch properties from command
*
Expand Down
14 changes: 13 additions & 1 deletion src/GitElephant/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,21 @@ public function commit($message, $stageAll = false, $ref = null)
/**
* Get the repository status
*
* @return array output lines
* @return array
*/
public function getStatus()
{
$this->caller->execute(MainCommand::getInstance()->status(true));

return array_map('trim', $this->caller->getOutputLines());
}

/**
* Get the repository status as a string
*
* @return array
*/
public function getStatusOutput()
{
$this->caller->execute(MainCommand::getInstance()->status());

Expand Down
14 changes: 14 additions & 0 deletions tests/GitElephant/Objects/BranchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,19 @@ public function testConstructor()
$this->assertEquals('develop', $b->getName());
$this->assertEquals('test commit', $b->getComment());
$this->assertFalse($b->getCurrent());
$this->setExpectedException('InvalidArgumentException');
$this->fail(Branch::checkout($this->getRepository(), 'non-existent'));
}

/**
* __toString
*/
public function testToString()
{
$this->getRepository()->init();
$this->addFile('test');
$this->getRepository()->commit('test commit', true);
$b = Branch::checkout($this->getRepository(), 'master');
$this->assertEquals($this->getRepository()->getLog()->last()->getSha(), $b->__toString());
}
}
37 changes: 27 additions & 10 deletions tests/GitElephant/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

class RepositoryTest extends TestCase
{
/**
* setUp
*/
public function setUp()
{
$this->initRepository();
Expand Down Expand Up @@ -54,14 +57,17 @@ public function testInit()
{
$this->getRepository()->init();
$match = false;
foreach ($this->getRepository()->getStatus() as $line) {
foreach ($this->getRepository()->getStatusOutput() as $line) {
if (preg_match('/nothing to commit?(.*)/', $line)) {
$match = true;
}
}
$this->assertTrue($match, 'init problem, git status on an empty repo should give nothing to commit');
}

/**
* testName
*/
public function testName()
{
$this->getRepository()->setName('test-repo');
Expand All @@ -77,7 +83,7 @@ public function testStage()
$this->addFile('test');
$this->getRepository()->stage();
$match = false;
foreach ($this->getRepository()->getStatus() as $line) {
foreach ($this->getRepository()->getStatusOutput() as $line) {
if (preg_match('/(.*)Changes to be committed(.*)/', $line)) {
$match = true;
}
Expand All @@ -87,7 +93,7 @@ public function testStage()

/**
* @covers GitElephant\Repository::commit
* @covers GitElephant\Repository::getStatus
* @covers GitElephant\Repository::getStatusOutput
*/
public function testCommit()
{
Expand All @@ -96,7 +102,7 @@ public function testCommit()
$this->getRepository()->stage();
$this->getRepository()->commit('initial import');
$match = false;
foreach ($this->getRepository()->getStatus() as $line) {
foreach ($this->getRepository()->getStatusOutput() as $line) {
if (preg_match('/nothing to commit?(.*)/', $line)) {
$match = true;
}
Expand All @@ -107,7 +113,7 @@ public function testCommit()
$this->addFile('test2');
$this->getRepository()->commit('commit 2', true, 'develop');
$match = false;
foreach ($this->getRepository()->getStatus() as $line) {
foreach ($this->getRepository()->getStatusOutput() as $line) {
if (preg_match('/nothing to commit?(.*)/', $line)) {
$match = true;
}
Expand All @@ -116,12 +122,15 @@ public function testCommit()
}

/**
* @expectedException RuntimeException
* @covers GitElephant\Repository::getStatus
* @covers GitElephant\Repository::getStatusOutput
*/
public function testGetStatus()
{
$this->assertStringStartsWith('fatal: Not a git repository', $this->getRepository()->getStatus(), 'get status should return "fatal: Not a git repository"');
$this->getRepository()->init();
$this->addFile('test');
$this->getRepository()->commit('test commit', true);
$output = $this->getRepository()->getStatusOutput();
$this->assertStringEndsWith('master', $output[0]);
}

/**
Expand Down Expand Up @@ -544,22 +553,28 @@ public function testMove()
$this->addFile('foo');
$this->getRepository()->commit('commit 1', true);
$this->getRepository()->move('foo', 'bar');
$status = $this->getRepository()->getStatus();
$status = $this->getRepository()->getStatusOutput();

$this->assertRegExp('/(.*): foo -> bar/', $status[4]);
}

/**
* testRemove
*/
public function testRemove()
{
$this->getRepository()->init();
$this->addFile('foo');
$this->getRepository()->commit('commit 1', true);
$this->getRepository()->remove('foo');
$status = $this->getRepository()->getStatus();
$status = $this->getRepository()->getStatusOutput();

$this->assertRegExp('/(.*): foo/', $status[4]);
}

/**
* testCountCommits
*/
public function testCountCommits()
{
$this->getRepository()->init();
Expand Down Expand Up @@ -592,6 +607,8 @@ public function testHumanishName()
* testCreateFromRemote
*
* @group online
*
* @return null
*/
public function testCreateFromRemote()
{
Expand Down

0 comments on commit 89071b3

Please sign in to comment.