redhataccess / pantheon-cmd

Pantheon CMD is an open source and freely distributed program for validating and building local previews of modular documentation.
GNU General Public License v3.0
2 stars 5 forks source link

PCMD exits with an error whenever run outside a Git repository #38

Closed adahms closed 3 years ago

adahms commented 3 years ago

Today, PCMD exits with the following error whenever run outside a Git repository -

Traceback (most recent call last):
  File "/usr/lib64/PantheonCMD/pcmd.py", line 14, in <module>
    from pcprvalidator import get_changed_files, get_all_modules, get_all_assemblies, get_undetermined_files, get_no_prefix_files
  File "/usr/lib64/PantheonCMD/pcprvalidator.py", line 10, in <module>
    current_branch = Repository('.').head.shorthand
  File "/usr/lib64/python3.6/site-packages/pygit2/repository.py", line 1210, in __init__
    path_backend = init_file_backend(path)
_pygit2.GitError: Repository not found at .

This is because the main file (pcmd.py) attempts to import some functions from pcprvalidate.py, which run the following line on load -

current_branch = Repository('.').head.shorthand

We should add some handling so that if it's run outside a Git repository, it silently fails or we tell the user it's not a valid place to run the script.

adahms commented 3 years ago

Hey @Levi-Leah - this one's on me.

I didn't think to check what happens outside a Git repo during testing of the merge request validator. Not a big problem because PCMD is designed to run inside a Git repo, but could be a good thing for us to add some handling to.

Levi-Leah commented 3 years ago

@adahms Didn’t think of that either. I’ll add some error handling