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

ggshield does not handle absence of git correctly #329

Closed
agateau-gg opened this issue Aug 22, 2022 · 0 comments · Fixed by #432
Closed

ggshield does not handle absence of git correctly #329

agateau-gg opened this issue Aug 22, 2022 · 0 comments · Fixed by #432
Labels
status:confirmed This issue has been reviewed and confirmed type:bug Something isn't working type:techdebt Fix non-optimal code

Comments

@agateau-gg
Copy link
Collaborator

GitGuardian Shield Version

  • 1.13.0

Command executed

Start an Ubuntu 22.04 docker container: docker run -it --rm ubuntu:20.04

Install ggshield using pip:

apt update
apt install pip
pip install ggshield

Try to run ggshield:

# ggshield --help
Traceback (most recent call last):
  File "/usr/local/bin/ggshield", line 5, in <module>
    from ggshield.cmd.main import main
  File "/usr/local/lib/python3.10/dist-packages/ggshield/cmd/main.py", line 10, in <module>
    from ggshield.cmd.auth import auth_group
  File "/usr/local/lib/python3.10/dist-packages/ggshield/cmd/auth/__init__.py", line 3, in <module>
    from .login import login_cmd
  File "/usr/local/lib/python3.10/dist-packages/ggshield/cmd/auth/login.py", line 6, in <module>
    from ggshield.cmd.auth.utils import check_instance_has_enabled_flow
  File "/usr/local/lib/python3.10/dist-packages/ggshield/cmd/auth/utils.py", line 4, in <module>
    from ggshield.core.client import create_session
  File "/usr/local/lib/python3.10/dist-packages/ggshield/core/client.py", line 13, in <module>
    from .config import Config
  File "/usr/local/lib/python3.10/dist-packages/ggshield/core/config/__init__.py", line 2, in <module>
    from .config import Config
  File "/usr/local/lib/python3.10/dist-packages/ggshield/core/config/config.py", line 7, in <module>
    from ggshield.core.config.user_config import UserConfig
  File "/usr/local/lib/python3.10/dist-packages/ggshield/core/config/user_config.py", line 24, in <module>
    from ggshield.core.utils import api_to_dashboard_url
  File "/usr/local/lib/python3.10/dist-packages/ggshield/core/utils.py", line 14, in <module>
    from .git_shell import get_git_root, is_git_dir
  File "/usr/local/lib/python3.10/dist-packages/ggshield/core/git_shell.py", line 38, in <module>
    GIT_PATH = get_git_path(os.getcwd())
  File "/usr/local/lib/python3.10/dist-packages/ggshield/core/git_shell.py", line 21, in get_git_path
    raise Exception("unable to find git executable in PATH/PATHEXT")
Exception: unable to find git executable in PATH/PATHEXT

Describe the bug

ggshield assumes the git command is available at import time, and fails to start.

Expected behavior

At a minimum, ggshield should print a proper error message when git is not available, not a stack trace.

Ideally, ggshield should not require the git command unless it's necessary. Commands like secret scan docker or `secret scan archiveè do not require git to be available.

Tech details

Reworking git_shell.py to hide GIT_PATH and add a git() function should help.

@agateau-gg agateau-gg added type:bug Something isn't working status:confirmed This issue has been reviewed and confirmed type:techdebt Fix non-optimal code labels Aug 22, 2022
agateau-gg added a commit that referenced this issue Nov 25, 2022
Do not try to find git at import time. Look for it the first time we need
it.

Fixes #329
agateau-gg added a commit that referenced this issue Nov 25, 2022
Do not try to find git at import time. Look for it the first time we need
it.

Fixes #329
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:confirmed This issue has been reviewed and confirmed type:bug Something isn't working type:techdebt Fix non-optimal code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant