Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes functional setRevision and update the quick guide #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ or run the following command:
php composer.phar require tivie/php-git-log-parser

## Quick guide
To parse the current git repository log, you can simply
To parse a git repository log, you can simply

```php
$repositoryPath = '/path_to_your_repo';
$revision = 'fe4f1105e10a8fedeb0b4f2f8c4ea43bec56a256..'

$parser = new \Tivie\GitLogParser\Parser();
$parser->setGitDir($repositoryPath);
$parser->setRevision($revision);
echo $parser->getCommand();
$logArray = $parser->parse();

```

## License
Expand Down
24 changes: 14 additions & 10 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public function __construct(Format $format = null, Command $command = null, $rev
$this->gitDir = __DIR__;

$this->branch = 'HEAD';

$this->command = ($command) ? $command : $this->buildCommand();
}

/**
Expand Down Expand Up @@ -106,6 +104,8 @@ public function setCommand(Command $command)
*/
public function getCommand()
{
if (!$this->command) $this->command = $this->buildCommand();

return $this->command;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public function setGitDir($dir, $check = true)
throw new Exception("Directory $dir does not exist");
}
$this->gitDir = $dir;
$this->command->chdir($dir);
if ($this->command) $this->command->chdir($dir);
return $this;
}

Expand All @@ -164,13 +164,16 @@ public function setBranch($branch)
throw new InvalidArgumentException('string', 0);
}

$oldBranch = $this->branch;
$oldArg = $this->command->searchArgument($oldBranch);
if (!$oldArg) {
throw new Exception("Couldn't change the command to new branch. Was the Command object modified?");
if ($this->command) {
$oldBranch = $this->branch;
$oldArg = $this->command->searchArgument($oldBranch);
if (!$oldArg) {
throw new Exception("Couldn't change the command to new branch. Was the Command object modified?");
}

$newArg = new Argument($branch);
$this->command->replaceArgument($oldArg, $newArg);
}
$newArg = new Argument($branch);
$this->command->replaceArgument($oldArg, $newArg);

$this->branch = $branch;
return $this;
Expand All @@ -183,7 +186,8 @@ public function setBranch($branch)
*/
public function parse()
{
$result = $this->command->run();
$command = $this->getCommand();
$result = $command->run();
$log = $result->getStdOut();

$buffer = array();
Expand Down