Skip to content

Commit

Permalink
fix: bump pkgrel if the local version is newer than remote
Browse files Browse the repository at this point in the history
In case of VCS packages, if PKGBUILD contains older version, the pkgrel
remains the same during the rebuild process. This fix bumps pkgrel in
any case if the local version is newer than the remote
  • Loading branch information
arcan1s committed Sep 23, 2024
1 parent db89ad4 commit 5173371
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/ahriman/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,10 @@ def next_pkgrel(self, local_version: str | None) -> str | None:
if local_version is None:
return None # local version not found, keep upstream pkgrel

epoch, pkgver, _ = parse_version(self.version)
local_epoch, local_pkgver, local_pkgrel = parse_version(local_version)

if epoch != local_epoch or pkgver != local_pkgver:
return None # epoch or pkgver are different, keep upstream pkgrel
if vercmp(self.version, local_version) > 0:
return None # upstream version is newer than local one, keep upstream pkgrel

*_, local_pkgrel = parse_version(local_version)
if "." in local_pkgrel:
major, minor = local_pkgrel.rsplit(".", maxsplit=1)
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/ahriman/core/build_tools/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ def test_init_bump_pkgrel_skip(task_ahriman: Task, mocker: MockerFixture) -> Non
"""
must keep pkgrel if version is different from provided
"""
task_ahriman.package.version = "2.0.0-1"
mocker.patch("ahriman.models.package.Package.from_build", return_value=task_ahriman.package)
mocker.patch("ahriman.core.build_tools.sources.Sources.load", return_value="sha")
write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write")

assert task_ahriman.init(Path("ahriman"), [], f"2:{task_ahriman.package.version}") == "sha"
assert task_ahriman.init(Path("ahriman"), [], "1.0.0-1") == "sha"
write_mock.assert_not_called()
6 changes: 3 additions & 3 deletions tests/ahriman/models/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,11 @@ def test_next_pkgrel(package_ahriman: Package) -> None:
assert package_ahriman.next_pkgrel(package_ahriman.version) == "1.2.2"

package_ahriman.version = "1:1.0.0-1"
assert package_ahriman.next_pkgrel("1:1.0.1-1") is None
assert package_ahriman.next_pkgrel("2:1.0.0-1") is None
assert package_ahriman.next_pkgrel("1:1.0.1-1") == "1.1"
assert package_ahriman.next_pkgrel("2:1.0.0-1") == "1.1"

package_ahriman.version = "1.0.0-1.1"
assert package_ahriman.next_pkgrel("1.0.1-2") is None
assert package_ahriman.next_pkgrel("1.0.1-2") == "2.1"
assert package_ahriman.next_pkgrel("1.0.0-2") == "2.1"

package_ahriman.version = "1.0.0-2"
Expand Down

0 comments on commit 5173371

Please sign in to comment.