Skip to content

Commit

Permalink
vcs/git: improve logging for issue debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed May 6, 2022
1 parent 0d418fc commit 3a305d2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/poetry/vcs/git/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@ def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo:

remote_refs = cls._fetch_remote_refs(url=url, local=local)

logger.debug(
"Cloning <c2>%s</> at '<c2>%s</>' to <c1>%s</>", url, refspec.key, target
)

try:
refspec.resolve(remote_refs=remote_refs)
except KeyError: # branch / ref does not exist
raise PoetrySimpleConsoleException(
f"Failed to clone {url} at '{refspec.key}'"
f"Failed to clone {url} at '{refspec.key}', verify ref exists on"
" remote."
)

# ensure local HEAD matches remote
Expand Down Expand Up @@ -274,13 +279,26 @@ def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo:
# this implies the ref we need does not exist or is invalid
if isinstance(e, KeyError):
# the local copy is at a bad state, lets remove it
logger.debug(
"Removing local clone (<c1>%s</>) of repository as it is in a"
" broken state.",
local.path,
)
remove_directory(local.path, force=True)

if isinstance(e, AssertionError) and "Invalid object name" not in str(e):
raise

logger.debug(
"\nRequested ref (<c2>%s</c2>) was not fetched to local copy and cannot"
" be used. The following error was raised:\n\n\t<warning>%s</>",
refspec.key,
e,
)

raise PoetrySimpleConsoleException(
f"Failed to clone {url} at '{refspec.key}'"
f"Failed to clone {url} at '{refspec.key}', verify ref exists on"
" remote."
)

return local
Expand Down

0 comments on commit 3a305d2

Please sign in to comment.