From 02494c5e155a7444bc492ef6352793188e59df1e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 07 2017 09:16:58 +0000 Subject: Catch exception raised when accessing the head of the repo When trying to diff a branch against master when master does not exist but the repo is not empty, pygit2 may raise an exception. Let's catch it and set the compare_branch to None as if the repo was empty. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/internal/__init__.py b/pagure/internal/__init__.py index c4637fe..f092a68 100644 --- a/pagure/internal/__init__.py +++ b/pagure/internal/__init__.py @@ -272,7 +272,10 @@ def get_pull_request_ready_branch(): if not repo_obj.is_empty and repo_obj.listall_branches() > 1: if not parent_repo_obj.is_empty \ and not parent_repo_obj.head_is_unborn: - compare_branch = repo_obj.head.shorthand + try: + compare_branch = repo_obj.head.shorthand + except pygit2.GitError: + compare_branch = None else: compare_branch = None