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 messages for repo error #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
14 changes: 9 additions & 5 deletions git_version/templatetags/git_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

@register.simple_tag
def current_commit(path):
repo = Repo(path)
commit = repo.commit()
chash = commit.hexsha
repo.__del__()
return chash
try:
repo = Repo(path)
commit = repo.commit()
chash = commit.hexsha
repo.__del__()
return chash
except Exception:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except Exception:
except Exception as e:

Is there a specific reason not to print the actual exception message? Was that too verbose?

print(f"git_version - trouble with repo path {path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(f"git_version - trouble with repo path {path}")
logger.debug(f"Failed to find current commit for {path}")

Can you replace the print statement with a logger call as described in https://docs.djangoproject.com/en/3.2/topics/logging/#using-logging? That's probably more appropriate for something published as a library.

Just for the sake of completeness, this would also need

import logging
logger = logging.getLogger(__name__)

somewhere at the start of the file

return "no git?"

@register.simple_tag
def current_commit_short(path):
Expand Down