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

cweagans / composer-patches / 4110992550

pending completion
4110992550

Pull #447

github

GitHub
Merge eaa8ee760 into a4b573156
Pull Request #447: 2.x WIP (don't merge yet)

457 of 457 new or added lines in 28 files covered. (100.0%)

456 of 570 relevant lines covered (80.0%)

3.29 hits per line

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

92.0
/src/Patcher/GitPatcher.php
1
<?php
2

3
namespace cweagans\Composer\Patcher;
4

5
use cweagans\Composer\Patch;
6
use Composer\IO\IOInterface;
7

8
class GitPatcher extends PatcherBase
9
{
10
    protected string $tool = 'git';
11

12
    public function apply(Patch $patch, string $path): bool
13
    {
14
        // If the path isn't a git repo, don't even try.
15
        // @see https://stackoverflow.com/a/27283285
16
        if (!is_dir($path . '/.git')) {
6✔
17
            return false;
5✔
18
        }
19

20
        // Dry run first.
21
        $status = $this->executeCommand(
1✔
22
            '%s -C %s apply --check --verbose -p%s %s',
1✔
23
            $this->patchTool(),
1✔
24
            $path,
1✔
25
            $patch->depth,
1✔
26
            $patch->localPath
1✔
27
        );
1✔
28
        if (str_starts_with($this->executor->getErrorOutput(), 'Skipped')) {
1✔
29
            // Git will indicate success but silently skip patches in some scenarios.
30
            //
31
            // @see https://github.com/cweagans/composer-patches/pull/165
32
            $status = false;
×
33
        }
34

35
        // If the check failed, then don't proceed with actually applying the patch.
36
        if (!$status) {
1✔
37
            return false;
×
38
        }
39

40
        // Otherwise, we can try to apply the patch.
41
        return $this->executeCommand(
1✔
42
            '%s -C %s apply -p%s %s',
1✔
43
            $this->patchTool(),
1✔
44
            $path,
1✔
45
            $patch->depth,
1✔
46
            $patch->localPath
1✔
47
        );
1✔
48
    }
49

50
    public function canUse(): bool
51
    {
52
        $output = "";
5✔
53
        $result = $this->executor->execute($this->patchTool() . ' --version', $output);
5✔
54
        $usable = ($result === 0);
5✔
55

56
        $this->io->write(self::class . " usable: " . ($usable ? "yes" : "no"), true, IOInterface::DEBUG);
5✔
57

58
        return $usable;
5✔
59
    }
60
}
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

© 2025 Coveralls, Inc