Skip to content

Commit

Permalink
Merge branch 'release/1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosister committed Jun 12, 2017
2 parents a6409cc + 09e2eef commit aa4bac7
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 26 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ php:
- 5.5
- 5.6
- 7.0
- hhvm

before_script:
- curl -s https://getcomposer.org/installer | php
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM php:7

RUN php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer

RUN apt-get update && \
apt-get install -yqq git && \
git config --global user.email "[email protected]" && \
git config --global user.name "GitElephant tests" && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
apt-get install -yqq zlib1g-dev && \
docker-php-ext-install zip && \
rm -rf /var/lib/apt/lists/*
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
}
},
"config": {
"platform": {
"php": "5.3.3"
}
"platform": {
"php": "5.3.3"
}
}
}
38 changes: 20 additions & 18 deletions composer.lock

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

5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
git:
build: .
volumes:
- .:/code
working_dir: /code
6 changes: 5 additions & 1 deletion src/GitElephant/Command/PushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(Repository $repo = null)
* @throws \RuntimeException
* @return string
*/
public function push($remote = 'origin', $branch = 'master')
public function push($remote = 'origin', $branch = 'master', $args = null)
{
if ($remote instanceof Remote) {
$remote = $remote->getName();
Expand All @@ -62,6 +62,10 @@ public function push($remote = 'origin', $branch = 'master')
$this->addCommandSubject($remote);
$this->addCommandSubject2($branch);

if(!is_null($args)) {
$this->addCommandArgument($args);
}

return $this->getCommand();
}
}
70 changes: 70 additions & 0 deletions src/GitElephant/Command/ResetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Created by PhpStorm.
* User: christian
* Date: 3/2/16
* Time: 11:29 AM
*/

namespace GitElephant\Command;


use GitElephant\Objects\Commit;
use GitElephant\Objects\TreeishInterface;
use \GitElephant\Repository;

class ResetCommand extends BaseCommand
{
const GIT_RESET_COMMAND = 'reset';

const OPTION_HARD = '--hard';
const OPTION_MERGE = '--merge';
const OPTION_SOFT = '--soft';

/**
* constructor
*
* @param \GitElephant\Repository $repo The repository object this command
* will interact with
*/
public function __construct(Repository $repo = null)
{
parent::__construct($repo);
}

/**
* @param TreeishInterface|Commit|string $arg
* @param array $options
*
* @throws \RuntimeException
* @return string
*/
public function reset($arg = null, array $options = array())
{
$this->clearAll();
$this->addCommandName(self::GIT_RESET_COMMAND);
// if there are options add them.
if (! is_null($options)) {
foreach ($options as $option) {
$this->addCommandArgument($option);
}
}
if($arg!=null){
$this->addCommandSubject2($arg);
}

return $this->getCommand();
}

/**
* @param Repository $repository
* @return ResetCommand
*/
public static function getInstance(Repository $repository=null)
{
return new self($repository);
}



}
40 changes: 39 additions & 1 deletion src/GitElephant/Objects/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function getDiff()
*/
private function parseOutputLines($outputLines)
{
$message = '';
$message = array();
foreach ($outputLines as $line) {
$matches = array();
if (preg_match('/^commit (\w+)$/', $line, $matches) > 0) {
Expand Down Expand Up @@ -406,4 +406,42 @@ public function revParse(Array $options = array())

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

/**
* Is the commit tagged?
*
* return true if some tag of repository point to this commit
* return false otherwise
*
* @return bool
*/
public function tagged()
{
$result = false;
foreach ($this->repository->getTags() as $tag) {
if ($tag->getSha() == $this->getSha()) {
$result = true;
break;
}
}

return $result;
}

/**
* Return Tags that point to this commit
*
* @return Tag[]
*/
public function getTags()
{
$currentCommitTags = array();
foreach ($this->repository->getTags() as $tag) {
if ($tag->getSha() == $this->getSha()) {
$currentCommitTags[] = $tag;
}
}

return $currentCommitTags;
}
}
13 changes: 11 additions & 2 deletions src/GitElephant/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use \GitElephant\Command\PullCommand;
use \GitElephant\Command\PushCommand;
use \GitElephant\Command\RemoteCommand;
use \GitElephant\Exception\InvalidRepositoryPathException;
use GitElephant\Command\ResetCommand;
use \GitElephant\Command\Caller\Caller;
use \GitElephant\Objects\Author;
use \GitElephant\Objects\Remote;
Expand Down Expand Up @@ -327,6 +327,15 @@ public function isBare()
return trim($this->caller->getOutput()) === 'true';
}

/**
* @param TreeishInterface|Commit|string $arg
* @param array $options
*/
public function reset($arg,$options)
{
$this->caller->execute(ResetCommand::getInstance($this)->reset($arg,$options));
}

/**
* Get the repository status
*
Expand Down Expand Up @@ -1026,7 +1035,7 @@ public function pull($from = null, $ref = null, $rebase = true)
}

/**
* Fetch from and merge with another repository or a local branch
* Push changes to remote repository
*
* @param string $to
* @param string $ref
Expand Down
33 changes: 33 additions & 0 deletions tests/GitElephant/Command/ResetCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Created by PhpStorm.
* User: christian
* Date: 3/2/16
* Time: 1:11 PM
*/

namespace GitElephant\Command;

use GitElephant\Objects\Commit;
use \GitElephant\TestCase;

class ResetCommandTest extends TestCase
{
/**
* setUp
*/
public function setUp()
{
$this->initRepository();
$this->getRepository()->init();
$this->addFile('test');
$this->getRepository()->commit('test', true);
$this->getRepository()->createBranch('test', 'master');
}

public function testResetHard()
{
$rstc = ResetCommand::getInstance();
$this->assertEquals("reset '--hard' 'dbeac'",$rstc->reset('dbeac',array(ResetCommand::OPTION_HARD)));
}
}
23 changes: 23 additions & 0 deletions tests/GitElephant/Objects/CommitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,27 @@ public function testRevParse()
$revParse = $commit->revParse();
$this->assertEquals($commit->getSha(), $revParse[0]);
}

public function testCommitWithoutTag()
{
$this->getRepository()->init();
$this->addFile('test');
$this->repository->stage();
$commit = Commit::create($this->repository, 'first commit', true);
$this->assertFalse($commit->tagged());
}

public function testCommitWithTag()
{
$this->getRepository()->init();
$this->addFile('test');
$this->repository->stage();
$commit = Commit::create($this->repository, 'first commit', true);
Tag::create($this->repository, '1.0.0');
$this->assertTrue($commit->tagged());
$this->assertCount(1, $commit->getTags());
$commitTags = $commit->getTags();
$this->assertEquals('1.0.0', $commitTags[0]->getName());
}

}
Loading

0 comments on commit aa4bac7

Please sign in to comment.