git: use smarter way for checking if repo is empty. This doesn't spam logs with some dulwich exceptions, we shouldn't really care about here.`

This commit is contained in:
Marcin Kuzminski 2018-08-11 14:20:58 +02:00
parent b1bfdeb6ba
commit 9effaef334
2 changed files with 6 additions and 4 deletions

View file

@ -177,9 +177,9 @@ class GitRepository(BaseRepository):
# we must check if this repo is not empty, since later command
# fails if it is. And it's cheaper to ask than throw the subprocess
# errors
try:
self._remote.head()
except KeyError:
head = self._remote.head(show_exc=False)
if not head:
return []
rev_filter = ['--branches', '--tags']

View file

@ -2206,7 +2206,9 @@ class Repository(Base, BaseModel):
if cs_cache is None:
# use no-cache version here
scm_repo = self.scm_instance(cache=False, config=config)
if scm_repo:
empty = scm_repo.is_empty()
if not empty:
cs_cache = scm_repo.get_commit(
pre_load=["author", "date", "message", "parents"])
else: