From dec201d3bec65de3ff9e25b9122de1cc25803209 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Sun, 10 Jan 2016 16:51:09 -0600 Subject: [PATCH] Some windows path errors if os.environ doesn't contain all values --- git/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/git/__init__.py b/git/__init__.py index 2fcf3854..003ed6a4 100644 --- a/git/__init__.py +++ b/git/__init__.py @@ -132,8 +132,8 @@ def find_binary(cmd): # /usr/local/bin:/usr/local/git/bin if os.name == 'nt': extra_paths = ( - os.path.join(os.environ["ProgramFiles"], "Git", "bin"), - os.path.join(os.environ["ProgramFiles(x86)"], "Git", "bin"), + os.path.join(os.environ.get("ProgramFiles", ""), "Git", "bin"), + os.path.join(os.environ.get("ProgramFiles(x86)", ""), "Git", "bin"), ) else: extra_paths = ( @@ -205,7 +205,10 @@ def run(self): except OSError as e: callback = sublime.error_message if e.errno == 2: - output = "{cmd} binary could not be found in PATH\n\nConsider using the {cmd_setting}_command setting for the Git plugin\n\nPATH is: {path}".format(cmd=self.command[0], cmd_setting=self.command[0].replace('-', '_'), path=os.environ['PATH']) + global _has_warned + if not _has_warned: + _has_warned = True + output = "{cmd} binary could not be found in PATH\n\nConsider using the {cmd_setting}_command setting for the Git plugin\n\nPATH is: {path}".format(cmd=self.command[0], cmd_setting=self.command[0].replace('-', '_'), path=os.environ['PATH']) else: output = e.strerror finally: