-
Notifications
You must be signed in to change notification settings - Fork 68
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
validate that git is installed before executing any command. #3568
Conversation
demisto_sdk/__main__.py
Outdated
logger = logging.getLogger("demisto-sdk") | ||
handle_deprecated_args(ctx.args) | ||
|
||
config.configuration = Configuration() | ||
import dotenv | ||
|
||
# make sure that git is installed before using any command. | ||
try: | ||
subprocess.check_output(["git", "--version"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See GitUtil, we (re)raise InvalidGitRepositoryError
, better handle it there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
however, we have several places that we just the Repo
class from github-python and not the GitUtil
object.
In order words we do not use only the GitUtil
class for git stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not possible to do it in GitUtil
as we import git
module in __main__.py
and if git is not installed, its not possible to import git
at all, an ImportError
exception will be raised.
The SDK crashes over it
Traceback (most recent call last):
File "/usr/local/bin/demisto-sdk", line 5, in <module>
from demisto_sdk.__main__ import main
File "/usr/local/lib/python3.10/site-packages/demisto_sdk/__main__.py", line 11, in <module>
import git
File "/usr/local/lib/python3.10/site-packages/git/__init__.py", line 91, in <module>
raise ImportError("Failed to initialize: {0}".format(_exc)) from _exc
ImportError: Failed to initialize: Bad git executable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically it crashes when the first git
imported is reached (which happens in __main__.py
)
e6ca092
to
648bcdc
Compare
…ustom_error_message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice
repo = None | ||
if content_path := os.getenv("DEMISTO_SDK_CONTENT_PATH"): | ||
git_util = GitUtil(Path(content_path)) | ||
logger.debug(f"Using content path: {content_path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.debug(f"Using content path: {content_path}") |
let's move the log line into the GitUtil
constructor, f"GitUtil: using {content_path=}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't use logger in GitUtil due to circular import :(
we have standard to use the logger from demisto_sdk.commands.common.logger
?
or may i use the logger from logging module..
i prefer to keep our standards
…ustom_error_message
…ustom_error_message
…ustom_error_message
Pull Request Test Coverage Report for Build d8ebd8bc-7655-4401-8f31-5c017b0dfead
💛 - Coveralls |
Related Issues
fixes: https://jira-hq.paloaltonetworks.local/browse/XSUP-27651
Description
GitUtil
class and notRepo
class to manage git operations anymore.git.repo
, but instead useGitUtil
class