git fetch + tests

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
2022-07-27 00:18:13 +02:00
parent 7689572edb
commit 54ed1ded30
2 changed files with 83 additions and 0 deletions

View File

@@ -95,6 +95,7 @@ class RepoTool:
_initialized: bool = False
_bare: bool = False
_path: str = ""
_last_fetch_data = []
def __init__(self, path: str):
log.info(f"Initializing repository at {path}")
@@ -121,6 +122,16 @@ class RepoTool:
def path(self) -> str:
return self._path
def __check_initialized(self):
def inner(*args):
fake_self: RepoTool = args[0]
if not fake_self._initialized:
log.critical(f"Repo {fake_self.path} is not initialized!")
return False
return self(*args)
return inner
def clone(self, url: str) -> bool:
if self._initialized:
log.warning(f"Trying to clone to initialized repository!")
@@ -132,3 +143,21 @@ class RepoTool:
self._bare = self._repo.bare
return True
@__check_initialized
def fetch(self) -> bool:
log.info("Fetching repo state")
if not len(self._repo.remotes):
log.warning(f"Repo: {self._path} does not contain any remotes!")
return False
# fetch all remotes
remote = self._repo.remotes[0]
log.debug(f"Fetching remote: {remote.name} url: {next(remote.urls)}")
self._last_fetch_data = remote.fetch(
"+refs/heads/*:refs/heads/*",
progress = GitRemoteProgress(),
kill_after_timeout = 60,
prune = True
)
log.debug("Fetch finished!")
return True