mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-10 02:36:29 +00:00
Fix problem with Repositories (#552)
* Fix problem with Repositories * Update git.py * Update git.py * Update git.py * Update git.py * Update git.py * Update git.py * Update git.py * Update git.py * Update git.py * Update git.py * Update git.py * fix lint * fix * reset origin * Git cleanup
This commit is contained in:
parent
63d3889d5c
commit
09df046fa8
@ -45,12 +45,13 @@ class GitRepo(CoreSysAttributes):
|
|||||||
async with self.lock:
|
async with self.lock:
|
||||||
try:
|
try:
|
||||||
_LOGGER.info("Load addon %s repository", self.path)
|
_LOGGER.info("Load addon %s repository", self.path)
|
||||||
self.repo = await self.sys_loop.run_in_executor(
|
self.repo = await self.sys_run_in_executor(
|
||||||
None, git.Repo, str(self.path))
|
git.Repo, str(self.path))
|
||||||
|
|
||||||
except (git.InvalidGitRepositoryError, git.NoSuchPathError,
|
except (git.InvalidGitRepositoryError, git.NoSuchPathError,
|
||||||
git.GitCommandError) as err:
|
git.GitCommandError) as err:
|
||||||
_LOGGER.error("Can't load %s repo: %s.", self.path, err)
|
_LOGGER.error("Can't load %s repo: %s.", self.path, err)
|
||||||
|
self._remove()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -62,7 +63,9 @@ class GitRepo(CoreSysAttributes):
|
|||||||
attribute: value
|
attribute: value
|
||||||
for attribute, value in (
|
for attribute, value in (
|
||||||
('recursive', True),
|
('recursive', True),
|
||||||
('branch', self.branch)
|
('branch', self.branch),
|
||||||
|
('depth', 1),
|
||||||
|
('shallow-submodules', True)
|
||||||
) if value is not None
|
) if value is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +79,7 @@ class GitRepo(CoreSysAttributes):
|
|||||||
except (git.InvalidGitRepositoryError, git.NoSuchPathError,
|
except (git.InvalidGitRepositoryError, git.NoSuchPathError,
|
||||||
git.GitCommandError) as err:
|
git.GitCommandError) as err:
|
||||||
_LOGGER.error("Can't clone %s repo: %s.", self.url, err)
|
_LOGGER.error("Can't clone %s repo: %s.", self.url, err)
|
||||||
|
self._remove()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -87,18 +91,43 @@ class GitRepo(CoreSysAttributes):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
|
_LOGGER.info("Update addon %s repository", self.url)
|
||||||
|
branch = self.repo.active_branch.name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_LOGGER.info("Pull addon %s repository", self.url)
|
# Download data
|
||||||
await self.sys_loop.run_in_executor(
|
await self.sys_run_in_executor(ft.partial(
|
||||||
None, self.repo.remotes.origin.pull)
|
self.repo.remotes.origin.fetch, **{
|
||||||
|
'update-shallow': True,
|
||||||
|
'depth': 1,
|
||||||
|
}))
|
||||||
|
|
||||||
|
# Jump on top of that
|
||||||
|
await self.sys_run_in_executor(ft.partial(
|
||||||
|
self.repo.git.reset, f"origin/{branch}", hard=True))
|
||||||
|
|
||||||
|
# Cleanup old data
|
||||||
|
await self.sys_run_in_executor(ft.partial(
|
||||||
|
self.repo.git.clean, "-xdf"))
|
||||||
|
|
||||||
except (git.InvalidGitRepositoryError, git.NoSuchPathError,
|
except (git.InvalidGitRepositoryError, git.NoSuchPathError,
|
||||||
git.GitCommandError) as err:
|
git.GitCommandError) as err:
|
||||||
_LOGGER.error("Can't pull %s repo: %s.", self.url, err)
|
_LOGGER.error("Can't update %s repo: %s.", self.url, err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _remove(self):
|
||||||
|
"""Remove a repository."""
|
||||||
|
if not self.path.is_dir():
|
||||||
|
return
|
||||||
|
|
||||||
|
def log_err(funct, path, _):
|
||||||
|
"""Log error."""
|
||||||
|
_LOGGER.warning("Can't remove %s", path)
|
||||||
|
|
||||||
|
shutil.rmtree(str(self.path), onerror=log_err)
|
||||||
|
|
||||||
|
|
||||||
class GitRepoHassIO(GitRepo):
|
class GitRepoHassIO(GitRepo):
|
||||||
"""HassIO addons repository."""
|
"""HassIO addons repository."""
|
||||||
@ -121,12 +150,6 @@ class GitRepoCustom(GitRepo):
|
|||||||
super().__init__(coresys, path, url)
|
super().__init__(coresys, path, url)
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
"""Remove a custom addon."""
|
"""Remove a custom repository."""
|
||||||
if self.path.is_dir():
|
_LOGGER.info("Remove custom addon repository %s", self.url)
|
||||||
_LOGGER.info("Remove custom addon repository %s", self.url)
|
self._remove()
|
||||||
|
|
||||||
def log_err(funct, path, _):
|
|
||||||
"""Log error."""
|
|
||||||
_LOGGER.warning("Can't remove %s", path)
|
|
||||||
|
|
||||||
shutil.rmtree(str(self.path), onerror=log_err)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user