Skip to content

Adding setup for git executable #640

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

Merged
Prev Previous commit
Next Next commit
Expanded ability of import
Renamed GIT_PYTHON_NOWARN to GIT_PYTHON_INITERR and added values for
quiet import, warning import, and raise import. These respectively mean
that no message or error is printed if git is non-existent, a plain
warning is printed but the import succeeds, and an ImportError
exception is raised.
  • Loading branch information
kenodegard committed Jul 13, 2017
commit 3430bde60ae65b54c08ffa73de1f16643c7c3bfd
32 changes: 27 additions & 5 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,40 @@ def refresh(cls, path=None):
# executable
cls.GIT_PYTHON_GIT_EXECUTABLE = cls.git_exec_name

# test if the user didn't want a warning
nowarn = os.environ.get("GIT_PYTHON_NOWARN", "false")
nowarn = nowarn.lower() in ["t", "true", "y", "yes"]

if not nowarn:
# determine what the user wanted to happen
# we expect GIT_PYTHON_INITERR to either be unset or be one of
# the following values:
# q|quiet|s|silence
# w|warn|warning
# r|raise|e|error
initerr_quiet = ["q", "quiet", "s", "silence"]
initerr_warn = ["w", "warn", "warning"]
initerr_raise = ["r", "raise", "e", "error"]

initerr = os.environ.get("GIT_PYTHON_INITERR", "warn").lower()
if initerr in initerr_quiet:
pass
elif initerr in initerr_warn:
print(dedent("""\
WARNING: %s
All git commands will error until this is rectified.

This initial warning can be silenced in the future by setting the environment variable:
export GIT_PYTHON_NOWARN=true
""") % err)
elif initerr in initerr_raise:
raise ImportError(err)
else:
err = dedent("""\
GIT_PYTHON_INITERR environment variable has been set but it has been set with an invalid value.

Use only the following values:
(1) q|quiet|s|silence: for no warning or exception
(2) w|warn|warning: for a printed warning
(3) r|raise|e|error: for a raised exception
""")
raise ImportError(err)

else:
# after the first setup (when GIT_PYTHON_GIT_EXECUTABLE
# is no longer None) we raise an exception and reset the
Expand Down