@@ -191,13 +191,15 @@ def __setstate__(self, d):
191191
192192 # Provide the full path to the git executable. Otherwise it assumes git is in the path
193193 _git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE"
194+ _refresh_env_var = "GIT_PYTHON_REFRESH"
194195 GIT_PYTHON_GIT_EXECUTABLE = None
195196 # note that the git executable is actually found during the refresh step in
196197 # the top level __init__
197198
198199 @classmethod
199200 def refresh (cls , path = None ):
200- """This gets called by the refresh function (see the top level __init__).
201+ """This gets called by the refresh function (see the top level
202+ __init__).
201203 """
202204 # discern which path to refresh with
203205 if path is not None :
@@ -214,17 +216,21 @@ def refresh(cls, path=None):
214216 try :
215217 cls ().version ()
216218 has_git = True
217- except GitCommandNotFound :
219+ except (GitCommandNotFound , PermissionError ):
220+ # - a GitCommandNotFound error is spawned by ourselves
221+ # - a PermissionError is spawned if the git executable provided
222+ # cannot be executed for whatever reason
218223 pass
219224
220225 # warn or raise exception if test failed
221226 if not has_git :
222227 err = dedent ("""\
223- Bad git executable. The git executable must be specified in one of the following ways:
224- (1) be included in your $PATH, or
225- (2) be set via $GIT_PYTHON_GIT_EXECUTABLE, or
226- (3) explicitly set via git.refresh.
227- """ )
228+ Bad git executable.
229+ The git executable must be specified in one of the following ways:
230+ - be included in your $PATH
231+ - be set via $%s
232+ - explicitly set via git.refresh()
233+ """ ) % cls ._git_exec_env_var
228234
229235 # revert to whatever the old_git was
230236 cls .GIT_PYTHON_GIT_EXECUTABLE = old_git
@@ -241,36 +247,53 @@ def refresh(cls, path=None):
241247 # 1|w|warn|warning
242248 # 2|r|raise|e|error
243249
244- mode = os .environ .get ("GIT_PYTHON_REFRESH" , "raise" ).lower ()
250+ mode = os .environ .get (cls . _refresh_env_var , "raise" ).lower ()
245251
246- quiet = ["0 " , "q" , "quiet " , "s" , "silence " , "n" , "none " ]
247- warn = ["1 " , "w" , "warn " , "warning " ]
248- error = ["2 " , "e" , "error " , "r" , "raise " ]
252+ quiet = ["quiet " , "q" , "silence " , "s" , "none " , "n" , "0 " ]
253+ warn = ["warn " , "w" , "warning " , "1 " ]
254+ error = ["error " , "e" , "raise " , "r" , "2 " ]
249255
250256 if mode in quiet :
251257 pass
252- elif mode in warn :
253- print ( dedent ("""\
254- WARNING: %s
258+ elif mode in warn or mode in error :
259+ err = dedent ("""\
260+ %s
255261 All git commands will error until this is rectified.
256262
257- This initial warning can be silenced in the future by setting the environment variable:
258- export GIT_PYTHON_REFRESH=quiet
259- """ ) % err )
260- elif mode in error :
261- raise ImportError (err )
263+ This initial warning can be silenced or aggravated in the future by setting the
264+ $%s environment variable. Use one of the following values:
265+ - %s: for no warning or exception
266+ - %s: for a printed warning
267+ - %s: for a raised exception
268+
269+ Example:
270+ export %s=%s
271+ """ ) % (
272+ err ,
273+ cls ._refresh_env_var ,
274+ "|" .join (quiet ),
275+ "|" .join (warn ),
276+ "|" .join (error ),
277+ cls ._refresh_env_var ,
278+ quiet [0 ])
279+
280+ if mode in warn :
281+ print ("WARNING: %s" % err )
282+ else :
283+ raise ImportError (err )
262284 else :
263285 err = dedent ("""\
264- GIT_PYTHON_REFRESH environment variable has been set but it has been set with an invalid value.
286+ %s environment variable has been set but it has been set with an invalid value.
265287
266288 Use only the following values:
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 ))
289+ - %s: for no warning or exception
290+ - %s: for a printed warning
291+ - %s: for a raised exception
292+ """ ) % (
293+ cls ._refresh_env_var ,
294+ "|" .join (quiet ),
295+ "|" .join (warn ),
296+ "|" .join (error ))
274297 raise ImportError (err )
275298
276299 # we get here if this was the init refresh and the refresh mode
0 commit comments