diff --git a/hgitaly/branch.py b/hgitaly/branch.py
index 32b0304d753bad5a40b23edec96d8f83fc36bd88_aGdpdGFseS9icmFuY2gucHk=..141dab178a071cba1e78753025932179e3a634b3_aGdpdGFseS9icmFuY2gucHk= 100644
--- a/hgitaly/branch.py
+++ b/hgitaly/branch.py
@@ -104,6 +104,9 @@
     :return: a :class:`changectx` or ``None`` if there's no changeset for
              the given ``gl_branch``.
     """
+    if not len(repo):
+        return None
+
     gl_branches = gitlab_branches(repo)
     if gl_branches is not GITLAB_BRANCHES_MISSING:
         sha = gl_branches.get(gl_branch)
@@ -165,6 +168,9 @@
       instance, ignoring lookup errors. If ``False``, yield targets as
       hexadecimal node ids.
     """
+    if not len(repo):
+        return
+
     gl_branches = gitlab_branches(repo)
     if gl_branches is not GITLAB_BRANCHES_MISSING:
         for branch, sha in gl_branches.items():
diff --git a/hgitaly/service/tests/test_mercurial_repository.py b/hgitaly/service/tests/test_mercurial_repository.py
index 32b0304d753bad5a40b23edec96d8f83fc36bd88_aGdpdGFseS9zZXJ2aWNlL3Rlc3RzL3Rlc3RfbWVyY3VyaWFsX3JlcG9zaXRvcnkucHk=..141dab178a071cba1e78753025932179e3a634b3_aGdpdGFseS9zZXJ2aWNlL3Rlc3RzL3Rlc3RfbWVyY3VyaWFsX3JlcG9zaXRvcnkucHk= 100644
--- a/hgitaly/service/tests/test_mercurial_repository.py
+++ b/hgitaly/service/tests/test_mercurial_repository.py
@@ -420,6 +420,7 @@
 
 def test_push_unexpected_error(push_fixture):
     wrapper, target_wrapper, push = push_fixture
+    wrapper.commit_file('foo')
 
     # we don't have many ways to trigger internal errors when
     # monkeypatch can't work (server is not in the same process):