protected function computeRebuildVersion($installPath, $branch)
    {
        $version = '';
        $branchPreg = preg_quote($branch);

        $process = new Process("cd $installPath; git describe --tags");
        $process->run();
        if ($process->isSuccessful()) {
            $lastTag = strtok($process->getOutput(), "\n");
            // Make sure the tag starts as Drupal formatted (for eg.
            // 7.x-1.0-alpha1) and if we are on a proper branch (ie. not master)
            // then it's on that branch.
            if (preg_match('/^(?<drupalversion>'.$branchPreg.'\.\d+(?:-[^-]+)?)(?<gitextra>-(?<numberofcommits>\d+-)g[0-9a-f]{7})?$/', $lastTag, $matches)) {
                if (isset($matches['gitextra'])) {
                    // If we found additional git metadata (in particular, number of commits)
                    // then use that info to build the version string.
                    $version = $matches['drupalversion'].'+'.$matches['numberofcommits'].'dev';
                } else {
                    // Otherwise, the branch tip is pointing to the same commit as the
                    // last tag on the branch, in which case we use the prior tag and
                    // add '+0-dev' to indicate we're still on a -dev branch.
                    $version = $lastTag.'+0-dev';
                }
            }
        }

        return $version;
    }