From cb0d8681ae37406356bb209e0efa08f03d76e01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Val=C3=AD=C4=8Dek?= Date: Thu, 4 Aug 2022 14:44:58 +0200 Subject: [PATCH] Fix some bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Václav Valíček --- repo_cloner/lib/detector.py | 11 ++++++++--- repo_cloner/lib/disk_stored_list.py | 7 +++++++ tests/lib/test_detector.py | 6 +++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/repo_cloner/lib/detector.py b/repo_cloner/lib/detector.py index b1b9db2..bccfeb0 100644 --- a/repo_cloner/lib/detector.py +++ b/repo_cloner/lib/detector.py @@ -187,9 +187,14 @@ class Detector: self._tags.remove(tag) keep_in_mind_commits: list = [] - for commit in list(new_tags.values()) + list(new_branches.values()): - if commit not in keep_in_mind_commits: - keep_in_mind_commits.append(commit) + for key, value in new_branches.items(): + if not value == self._branches.get(key): + 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 executed_count: int = 0 diff --git a/repo_cloner/lib/disk_stored_list.py b/repo_cloner/lib/disk_stored_list.py index d77bc50..e1ce74b 100644 --- a/repo_cloner/lib/disk_stored_list.py +++ b/repo_cloner/lib/disk_stored_list.py @@ -1,5 +1,7 @@ from typing import Optional import os +import logging +log = logging.getLogger("rc.lststor") class DiskStoredList: @@ -19,14 +21,18 @@ class DiskStoredList: self._load_from_file() def _load_from_file(self): + log.debug(f"DiskStoredList: loading") with open(self.__file, 'r') as f: for line in f.readlines(): line = line.strip() if len(line): self.__items.append(line) + log.debug(f"DiskStoredList: loaded {len(self.__items)}") + def append(self, line: str): with open(self.__file, 'a') as f: + log.debug(f"DiskStoredList: append {line}") self.__items.append(line) f.write(f"{line}\n") @@ -34,6 +40,7 @@ class DiskStoredList: return len(self.__items) def __contains__(self, line: str) -> bool: + log.debug(f"DiskStoredList: contains? {line}") return line in self.__items def __iter__(self): diff --git a/tests/lib/test_detector.py b/tests/lib/test_detector.py index 8bc860d..bc7a6b2 100644 --- a/tests/lib/test_detector.py +++ b/tests/lib/test_detector.py @@ -360,6 +360,11 @@ def test_run(tmp_path, caplog): 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 + """ + for x in executed: + print(x.dict) + """ + assert len(executed) == 24 assert sum(ex.is_tag for ex in executed) == 3 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")) for tag, commit in tags_new.items(): assert commit == refs.get(tag) -