From 8a4b7b32aad912ec69eb08228fd791722593e5db Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Mon, 27 Jun 2022 13:34:36 +0100 Subject: [PATCH 1/2] Try adding error-outputs to resolve_default_branch --- nbgitpuller/pull.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nbgitpuller/pull.py b/nbgitpuller/pull.py index 2b74b4b4..84c041d9 100644 --- a/nbgitpuller/pull.py +++ b/nbgitpuller/pull.py @@ -125,8 +125,14 @@ def resolve_default_branch(self): refs, heads, branch_name = ref.split("/", 2) return branch_name raise ValueError(f"default branch not found in {self.git_url}") - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as e: + sout = e.stdout if e.stdout else '' + serr = e.stderr if e.stderr else '' m = f"Problem accessing HEAD branch: {self.git_url}" + if sout: + m = f"{m}: {sout}" + if serr: + m = f"{m}; {serr}" logging.exception(m) raise ValueError(m) From 73daf2903f7678179af6b5fcd615acad5ab043e5 Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Mon, 27 Jun 2022 14:53:51 +0100 Subject: [PATCH 2/2] Add git failure checks to 'branch_exists' method --- nbgitpuller/pull.py | 46 +++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/nbgitpuller/pull.py b/nbgitpuller/pull.py index 84c041d9..0f6a9f03 100644 --- a/nbgitpuller/pull.py +++ b/nbgitpuller/pull.py @@ -86,18 +86,40 @@ def branch_exists(self, branch): This checks to make sure the branch we are told to access exists in the repo """ - heads = subprocess.run( - ["git", "ls-remote", "--heads", "--", self.git_url], - capture_output=True, - text=True, - check=True - ) - tags = subprocess.run( - ["git", "ls-remote", "--tags", "--", self.git_url], - capture_output=True, - text=True, - check=True - ) + try: + heads = subprocess.run( + ["git", "ls-remote", "--heads", "--", self.git_url], + capture_output=True, + text=True, + check=True + ) + except subprocess.CalledProcessError as e: + sout = e.stdout if e.stdout else '' + serr = e.stderr if e.stderr else '' + m = f"Problem checking known branches: {self.git_url}" + if sout: + m = f"{m}: {sout}" + if serr: + m = f"{m}; {serr}" + logging.exception(m) + raise ValueError(m) + try: + tags = subprocess.run( + ["git", "ls-remote", "--tags", "--", self.git_url], + capture_output=True, + text=True, + check=True + ) + except subprocess.CalledProcessError as e: + sout = e.stdout if e.stdout else '' + serr = e.stderr if e.stderr else '' + m = f"Problem checking known tags: {self.git_url}" + if sout: + m = f"{m}: {sout}" + if serr: + m = f"{m}; {serr}" + logging.exception(m) + raise ValueError(m) lines = heads.stdout.splitlines() + tags.stdout.splitlines() branches = [] for line in lines: