# Buggy code
def repo_needs_merge(self):
    """Check for unmerged commits from remote repository."""
    return self.repository.needs_merge()


# Traceback (weblate.vcs.base.RepositoryException)
celery-main stderr | [2020-02-03 09:01:29,989: INFO/MainProcess] Received task: weblate.utils.tasks.heartbeat[c1c419aa-da0a-4a6d-ae33-f93d3251244c]
uwsgi stderr | ERROR Internal Server Error: /projects/<some_project>/<some_compnent>/
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.7/dist-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.7/dist-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/weblate/trans/views/basic.py", line 218, in show_component
'alerts': obj.all_alerts,
File "/usr/local/lib/python3.7/dist-packages/weblate/trans/util.py", line 268, in render
return django_render(request, template, context, status=status)
File "/usr/local/lib/python3.7/dist-packages/django/shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "/usr/local/lib/python3.7/dist-packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
File "/usr/local/lib/python3.7/dist-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/loader_tags.py", line 188, in render
return template.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 173, in render
return self._render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/loader_tags.py", line 188, in render
return template.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 173, in render
return self._render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/defaulttags.py", line 511, in render
values = {key: val.resolve(context) for key, val in self.extra_context.items()}
File "/usr/local/lib/python3.7/dist-packages/django/template/defaulttags.py", line 511, in <dictcomp>
values = {key: val.resolve(context) for key, val in self.extra_context.items()}
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 670, in resolve
obj = self.var.resolve(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 795, in resolve
value = self._resolve_lookup(context)
File "/usr/local/lib/python3.7/dist-packages/django/template/base.py", line 857, in _resolve_lookup
current = current()
File "/usr/local/lib/python3.7/dist-packages/weblate/trans/models/component.py", line 683, in get_last_remote_commit
return self.repository.get_revision_info(self.repository.last_remote_revision)
File "/usr/local/lib/python3.7/dist-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.7/dist-packages/weblate/vcs/base.py", line 216, in last_remote_revision
self._cmd_last_remote_revision, needs_lock=False, merge_err=False
File "/usr/local/lib/python3.7/dist-packages/weblate/vcs/base.py", line 183, in execute
args, self.path, fullcmd=fullcmd, local=self.local, merge_err=merge_err
File "/usr/local/lib/python3.7/dist-packages/weblate/vcs/base.py", line 173, in _popen
raise RepositoryException(retcode, output)
weblate.vcs.base.RepositoryException: fatal: ambiguous argument '@{upstream}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
(128)

# Fixed code
def repo_needs_merge(self):
    """Check for unmerged commits from remote repository."""
    try:
        return self.repository.needs_merge()
    except RepositoryException as error:
        report_error(cause="Could check merge needed")
        self.add_alert("MergeFailure", error=self.error_text(error))
        return False