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

Returns the number of commits behind and ahead between two branches #112

Open
fsevestre opened this issue Mar 26, 2017 · 1 comment
Open

Comments

@fsevestre
Copy link

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 ?

geek-merlin added a commit to machbarmacher/GitElephant that referenced this issue Aug 6, 2017
geek-merlin added a commit to machbarmacher/GitElephant that referenced this issue Aug 6, 2017
geek-merlin added a commit to machbarmacher/GitElephant that referenced this issue Aug 6, 2017
geek-merlin added a commit to machbarmacher/GitElephant that referenced this issue Aug 6, 2017
@GenieTim
Copy link
Collaborator

GenieTim commented Sep 7, 2018

Sure! Feel free to open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants