Skip to content

Commit 2b3e769

Browse files
committed
Renamed GIT_PYTHON_INITERR to GIT_PYTHON_REFRESH
Renamed and cleaned up variable names.
1 parent 4aa750a commit 2b3e769

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

git/cmd.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -226,52 +226,61 @@ def refresh(cls, path=None):
226226
(3) explicitly set via git.refresh.
227227
""")
228228

229+
# revert to whatever the old_git was
230+
cls.GIT_PYTHON_GIT_EXECUTABLE = old_git
231+
229232
if old_git is None:
230233
# on the first refresh (when GIT_PYTHON_GIT_EXECUTABLE is
231-
# None) we only warn the user and simply set the default
232-
# executable
233-
cls.GIT_PYTHON_GIT_EXECUTABLE = cls.git_exec_name
234+
# None) we only are quiet, warn, or error depending on the
235+
# GIT_PYTHON_REFRESH value
236+
237+
# determine what the user wants to happen during the initial
238+
# refresh we expect GIT_PYTHON_REFRESH to either be unset or
239+
# be one of the following values:
240+
# 0|q|quiet|s|silence
241+
# 1|w|warn|warning
242+
# 2|r|raise|e|error
234243

235-
# determine what the user wanted to happen
236-
# we expect GIT_PYTHON_INITERR to either be unset or be one of
237-
# the following values:
238-
# q|quiet|s|silence
239-
# w|warn|warning
240-
# r|raise|e|error
241-
initerr_quiet = ["q", "quiet", "s", "silence"]
242-
initerr_warn = ["w", "warn", "warning"]
243-
initerr_raise = ["r", "raise", "e", "error"]
244-
245-
initerr = os.environ.get("GIT_PYTHON_INITERR", "warn").lower()
246-
if initerr in initerr_quiet:
244+
mode = os.environ.get("GIT_PYTHON_REFRESH", "raise").lower()
245+
246+
quiet = ["0", "q", "quiet", "s", "silence", "n", "none"]
247+
warn = ["1", "w", "warn", "warning"]
248+
error = ["2", "e", "error", "r", "raise"]
249+
250+
if mode in quiet:
247251
pass
248-
elif initerr in initerr_warn:
252+
elif mode in warn:
249253
print(dedent("""\
250254
WARNING: %s
251255
All git commands will error until this is rectified.
252256
253257
This initial warning can be silenced in the future by setting the environment variable:
254-
export GIT_PYTHON_NOWARN=true
258+
export GIT_PYTHON_REFRESH=quiet
255259
""") % err)
256-
elif initerr in initerr_raise:
260+
elif mode in error:
257261
raise ImportError(err)
258262
else:
259263
err = dedent("""\
260-
GIT_PYTHON_INITERR environment variable has been set but it has been set with an invalid value.
264+
GIT_PYTHON_REFRESH environment variable has been set but it has been set with an invalid value.
261265
262266
Use only the following values:
263-
(1) q|quiet|s|silence: for no warning or exception
264-
(2) w|warn|warning: for a printed warning
265-
(3) r|raise|e|error: for a raised exception
266-
""")
267+
(1) {quiet}: for no warning or exception
268+
(2) {warn}: for a printed warning
269+
(3) {error}: for a raised exception
270+
""").format(
271+
quiet="|".join(quiet),
272+
warn="|".join(warn),
273+
error="|".join(error))
267274
raise ImportError(err)
268275

276+
# we get here if this was the init refresh and the refresh mode
277+
# was not error, go ahead and set the GIT_PYTHON_GIT_EXECUTABLE
278+
# such that we discern the difference between a first import
279+
# and a second import
280+
cls.GIT_PYTHON_GIT_EXECUTABLE = cls.git_exec_name
269281
else:
270282
# after the first refresh (when GIT_PYTHON_GIT_EXECUTABLE
271-
# is no longer None) we raise an exception and reset the
272-
# GIT_PYTHON_GIT_EXECUTABLE to whatever the value was
273-
# previously
274-
cls.GIT_PYTHON_GIT_EXECUTABLE = old_git
283+
# is no longer None) we raise an exception
275284
raise GitCommandNotFound("git", err)
276285

277286
return has_git

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy