Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add leading message to raised errors' #276

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 41 additions & 13 deletions nbgitpuller/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -125,8 +147,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)

Expand Down