• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mborne / git-manager / 20215951067

14 Dec 2025 11:39PM UTC coverage: 63.907% (+0.09%) from 63.816%
20215951067

push

github

web-flow
Merge pull request #39 from mborne/38-askpass

use GIT_ASKPASS to provide token as a password to git

14 of 27 new or added lines in 2 files covered. (51.85%)

193 of 302 relevant lines covered (63.91%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.0
/src/Git/Synchronizer.php
1
<?php
2

3
namespace MBO\GitManager\Git;
4

5
use Gitonomy\Git\Admin as GitAdmin;
6
use Gitonomy\Git\Repository as GitRepository;
7
use MBO\GitManager\Filesystem\LocalFilesystem;
8
use MBO\GitManager\Helpers\ProjectHelpers;
9
use MBO\RemoteGit\ProjectInterface;
10
use Psr\Log\LoggerInterface;
11

12
class Synchronizer
13
{
14
    public function __construct(
15
        private LocalFilesystem $localFilesystem,
16
        private string $askPassPath,
17
        private LoggerInterface $logger,
18
    ) {
19
        if (!is_executable($askPassPath)) {
1✔
NEW
20
            throw new \RuntimeException(sprintf("GIT_ASKPATH ('%s') is not runnable!", $askPassPath));
×
21
        }
22
    }
23

24
    public function fetchOrClone(ProjectInterface $project, ?string $token): void
25
    {
26
        /*
27
         * Inject token in url to clone repository
28
         */
29
        $projectUrl = $project->getHttpUrl();
1✔
30

31
        $env = [];
1✔
32
        if (!empty($token)) {
1✔
NEW
33
            $env['GIT_MANAGER_TOKEN'] = $token;
×
NEW
34
            $env['GIT_ASKPASS'] = $this->askPassPath;
×
NEW
35
            $env['GIT_TERMINAL_PROMPT'] = '0';
×
36
        }
37
        $options = [
1✔
38
            'environment_variables' => $env,
1✔
39
        ];
1✔
40

41
        /*
42
        * fetch or clone repository to localPath
43
        */
44
        $fullName = ProjectHelpers::getFullName($project);
1✔
45
        $localPath = $this->localFilesystem->getRootPath().'/'.$fullName;
1✔
46
        if (file_exists($localPath)) {
1✔
NEW
47
            $this->logger->debug(sprintf('%s already exists -> fetch and reset', $fullName));
×
NEW
48
            $gitRepository = new GitRepository($localPath, $options);
×
49
            // use token to fetch
NEW
50
            $gitRepository->run('remote', [
×
NEW
51
                'set-url',
×
NEW
52
                'origin',
×
NEW
53
                $projectUrl,
×
NEW
54
            ]);
×
55
            // update local repository
NEW
56
            $gitRepository->run('fetch', ['origin', '--prune', '--prune-tags']);
×
57
            // reset to default branch
NEW
58
            $gitRepository->run('reset', ['--hard', 'origin/'.$project->getDefaultBranch()]);
×
59
        } else {
60
            $this->logger->debug(sprintf("%s doesn't exists -> clone", $fullName));
1✔
61
            GitAdmin::cloneTo($localPath, $projectUrl, false, $options);
1✔
62
        }
63
    }
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc