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

eliashaeussler / version-bumper / 25880688608

14 May 2026 07:23PM UTC coverage: 86.276% (-2.2%) from 88.43%
25880688608

Pull #138

github

eliashaeussler
[!!!][FEATURE] Allow Git tagging without modified files
Pull Request #138: [!!!][FEATURE] Allow Git tagging without modified files

41 of 77 new or added lines in 7 files covered. (53.25%)

1163 of 1348 relevant lines covered (86.28%)

5.04 hits per line

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

0.0
/src/Helper/GitHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/version-bumper".
7
 *
8
 * Copyright (C) 2024-2026 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\VersionBumper\Helper;
25

26
use EliasHaeussler\VersionBumper\Exception;
27
use EliasHaeussler\VersionBumper\Version;
28
use GitElephant\Objects;
29
use GitElephant\Repository;
30

31
/**
32
 * GitHelper.
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-3.0-or-later
36
 */
37
final class GitHelper
38
{
39
    /**
40
     * @throws Exception\CannotFetchGitTag
41
     */
NEW
42
    public static function fetchTag(string $tagName, Repository $repository): ?Objects\Tag
×
43
    {
44
        try {
NEW
45
            return $repository->getTag($tagName);
×
NEW
46
        } catch (\Exception $exception) {
×
NEW
47
            throw new Exception\CannotFetchGitTag($tagName, $exception);
×
48
        }
49
    }
50

51
    /**
52
     * @throws Exception\CannotFetchLatestGitTag
53
     * @throws Exception\VersionIsNotSupported
54
     */
NEW
55
    public static function fetchLatestVersionTag(Repository $repository): ?Objects\Tag
×
56
    {
57
        try {
58
            /** @var list<Objects\Tag> $tags */
NEW
59
            $tags = $repository->getTags();
×
NEW
60
        } catch (\Exception $exception) {
×
NEW
61
            throw new Exception\CannotFetchLatestGitTag($exception);
×
62
        }
63

64
        // Drop all non-version tags
NEW
65
        $tags = array_filter(
×
NEW
66
            $tags,
×
NEW
67
            static fn (Objects\Tag $tag) => VersionHelper::isValidVersion($tag->getName()),
×
NEW
68
        );
×
69

70
        // Early return if no version tags are left
NEW
71
        if ([] === $tags) {
×
NEW
72
            return null;
×
73
        }
74

75
        // Sort version tags by descending version number
NEW
76
        usort(
×
NEW
77
            $tags,
×
NEW
78
            static function (Objects\Tag $a, Objects\Tag $b) {
×
NEW
79
                $a = Version\Version::fromFullVersion($a->getName());
×
NEW
80
                $b = Version\Version::fromFullVersion($b->getName());
×
81

NEW
82
                return version_compare($a->full(), $b->full());
×
NEW
83
            },
×
NEW
84
        );
×
85

NEW
86
        return array_pop($tags);
×
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc