Skip to content

Commit e36dcd0

Browse files
committed
Ensure keywords are not lost if packages are renamed
Only redo the keywords if the PV changes over the git mv operation.
1 parent a53745e commit e36dcd0

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/pkgdev/mangle.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ def keywords_remove_stable(kws):
8484
kws = sorted(mo.group("keywords").split(), key=keywords_sort_key)
8585
# Only remove stable keywords on new ebuild creations
8686
# For our purposes, renames are also new ebuild creations
87-
if change.status in ("A", "R"):
87+
print(change.atom.version)
88+
# print(change.atom.revision)
89+
if change.status == 'A':
90+
kws = keywords_remove_stable(kws)
91+
if change.status == 'R' \
92+
and change.old is not None \
93+
and change.old.version != change.atom.version:
8894
kws = keywords_remove_stable(kws)
8995
new_kw = " ".join(kws)
9096
if not mo.group("quote"):

tests/scripts/test_pkgdev_commit.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ def commit(args):
10701070

10711071
# Keyword mangling when adding new ebuilds
10721072
ebuild_path = repo.create_ebuild("cat/pkg-1", keywords=("arm64", "x86", "~amd64", "-sparc"))
1073-
commit(["-a", "-m", "version bump (no removal)"])
1073+
commit(["-a", "-m", "version bump (type A, without removal)"])
10741074
with open(ebuild_path) as f:
10751075
lines = f.read().splitlines()
10761076
mo = keywords_regex.match(lines[-1])
@@ -1079,12 +1079,29 @@ def commit(args):
10791079
# Keyword mangling when adding and removing ebuilds simultaniously (git interpreted as rename)
10801080
git_repo.remove(ebuild_path, commit=False)
10811081
ebuild_path = repo.create_ebuild("cat/pkg-2", keywords=("arm64", "x86", "~amd64", "-sparc"))
1082-
commit(["-a", "-m", "version bump (no removal)"])
1082+
commit(["-a", "-m", "version bump (type R, with removal)"])
10831083
with open(ebuild_path) as f:
10841084
lines = f.read().splitlines()
10851085
mo = keywords_regex.match(lines[-1])
10861086
assert mo.group("keywords") == "~amd64 ~arm64 -sparc ~x86"
10871087

1088+
# Keyword mangling when moving a package to another category
1089+
ebuild_path = repo.create_ebuild("oldcat/oldname-0", keywords=("arm64", "x86", "~amd64", "-sparc"))
1090+
git_repo.add_all("oldcat/oldname-0")
1091+
os.mkdir(os.path.join(git_repo.path, 'newcat'))
1092+
os.mkdir(os.path.join(git_repo.path, 'newcat/newname'))
1093+
git_repo.move(
1094+
pjoin(git_repo.path, "oldcat/oldname/oldname-0.ebuild"),
1095+
pjoin(git_repo.path, "newcat/newname/newname-0.ebuild"),
1096+
commit=False,
1097+
)
1098+
commit(["-a", "-m", "rename package (type R, but no PV change)"])
1099+
with open(os.path.join(git_repo.path, "newcat/newname/newname-0.ebuild")) as f:
1100+
lines = f.read().splitlines()
1101+
mo = keywords_regex.match(lines[-1])
1102+
assert mo.group("keywords") == "~amd64 arm64 -sparc x86"
1103+
1104+
10881105
def test_scan(self, capsys, repo, make_git_repo):
10891106
git_repo = make_git_repo(repo.location)
10901107
repo.create_ebuild("cat/pkg-0")

0 commit comments

Comments
 (0)