Fix some bugs

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
Václav Valíček 2022-08-04 14:44:58 +02:00
parent f75702439c
commit cb0d8681ae
Signed by: valicek
GPG Key ID: FF05BDCA0C73BB31
3 changed files with 20 additions and 4 deletions

View File

@ -187,9 +187,14 @@ class Detector:
self._tags.remove(tag) self._tags.remove(tag)
keep_in_mind_commits: list = [] keep_in_mind_commits: list = []
for commit in list(new_tags.values()) + list(new_branches.values()): for key, value in new_branches.items():
if commit not in keep_in_mind_commits: if not value == self._branches.get(key):
keep_in_mind_commits.append(commit) log.debug(f"Keep in mind branch: {key} -> {value}")
keep_in_mind_commits.append(value)
for key, value in new_tags.items():
if not value == self._tags.get(key):
log.debug(f"Keep in mind tag: {key} -> {value}")
keep_in_mind_commits.append(value)
# list commits # list commits
executed_count: int = 0 executed_count: int = 0

View File

@ -1,5 +1,7 @@
from typing import Optional from typing import Optional
import os import os
import logging
log = logging.getLogger("rc.lststor")
class DiskStoredList: class DiskStoredList:
@ -19,14 +21,18 @@ class DiskStoredList:
self._load_from_file() self._load_from_file()
def _load_from_file(self): def _load_from_file(self):
log.debug(f"DiskStoredList: loading")
with open(self.__file, 'r') as f: with open(self.__file, 'r') as f:
for line in f.readlines(): for line in f.readlines():
line = line.strip() line = line.strip()
if len(line): if len(line):
self.__items.append(line) self.__items.append(line)
log.debug(f"DiskStoredList: loaded {len(self.__items)}")
def append(self, line: str): def append(self, line: str):
with open(self.__file, 'a') as f: with open(self.__file, 'a') as f:
log.debug(f"DiskStoredList: append {line}")
self.__items.append(line) self.__items.append(line)
f.write(f"{line}\n") f.write(f"{line}\n")
@ -34,6 +40,7 @@ class DiskStoredList:
return len(self.__items) return len(self.__items)
def __contains__(self, line: str) -> bool: def __contains__(self, line: str) -> bool:
log.debug(f"DiskStoredList: contains? {line}")
return line in self.__items return line in self.__items
def __iter__(self): def __iter__(self):

View File

@ -360,6 +360,11 @@ def test_run(tmp_path, caplog):
assert "Branch doctrine removed in source, removing from detector" in caplog.text assert "Branch doctrine removed in source, removing from detector" in caplog.text
assert "Tag test-testu removed in source, removing from detector" in caplog.text assert "Tag test-testu removed in source, removing from detector" in caplog.text
"""
for x in executed:
print(x.dict)
"""
assert len(executed) == 24 assert len(executed) == 24
assert sum(ex.is_tag for ex in executed) == 3 assert sum(ex.is_tag for ex in executed) == 3
assert sum(ex.is_branch for ex in executed) == 2 assert sum(ex.is_branch for ex in executed) == 2
@ -377,4 +382,3 @@ def test_run(tmp_path, caplog):
refs = DiskStoredRefs(cache_dir.joinpath("detector", "tags")) refs = DiskStoredRefs(cache_dir.joinpath("detector", "tags"))
for tag, commit in tags_new.items(): for tag, commit in tags_new.items():
assert commit == refs.get(tag) assert commit == refs.get(tag)