GitElephant
GitElephant copied to clipboard
Returns the number of commits behind and ahead between two branches
Hi guys,
for a small project I'm working on, using GitElephant
, I want to display the number of commits behind and ahead between the current branch and the origin one.
For now, I do something like this :
private function getAheadBehindCommitsCount(Branch $branch)
{
$branchName = $branch->getName();
try {
$output = $branch->getRepository()
->getCaller()
->execute("rev-list --left-right --count origin/$branchName...$branchName")
->getOutput()
;
preg_match_all('!\d+!', $output, $matches);
} catch (\RuntimeException $e) {
return ['-', '-'];
}
return $matches[0];
}
I thought that this feature could be added to this library.
This could be changed by providing two branch objects instead of one (but what about the origin
?) / or the branch names directly.
To be honest, I have found the Git command on stackoverflow, I don't know if it is the best way to retrieve this informations, I'm not a Git expert.
Is this kind of feature in the scope of this library ?
Sure! Feel free to open a PR