From 021c1e479e860a2d884769be610e396df59662e5 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Mon, 1 Jul 2013 01:38:19 +0200 Subject: [PATCH] git-config settings were not being fetched when a git directory was set. It was only working if gitinspector was invoked inside a git directory. --- gitinspector/config.py | 33 +++++++++++++++++++-------------- gitinspector/gitinspector.py | 9 ++++++--- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/gitinspector/config.py b/gitinspector/config.py index d336064..d510390 100644 --- a/gitinspector/config.py +++ b/gitinspector/config.py @@ -23,11 +23,16 @@ import filtering import format import interval import missing +import os import subprocess -def __read_git_config__(variable, default_value): +def __read_git_config__(repo, variable, default_value): + previous_directory = os.getcwd() + os.chdir(repo) setting = subprocess.Popen("git config inspector." + variable, shell=True, bufsize=1, stdout=subprocess.PIPE).stdout + os.chdir(previous_directory) + try: setting = setting.readlines()[0] setting = setting.decode("utf-8", "replace").strip() @@ -48,35 +53,35 @@ def __read_git_config__(variable, default_value): return default_value def init(run): - missing.set_checkout_missing(__read_git_config__("checkout-missing", False)) - extensions.define(__read_git_config__("file-types", ",".join(extensions.get()))) + missing.set_checkout_missing(__read_git_config__(run.repo, "checkout-missing", False)) + extensions.define(__read_git_config__(run.repo, "file-types", ",".join(extensions.get()))) - exclude = __read_git_config__("exclude", None) + exclude = __read_git_config__(run.repo, "exclude", None) if exclude != None: filtering.add(exclude) - output_format = __read_git_config__("format", None) + output_format = __read_git_config__(run.repo, "format", None) if output_format != None: if not format.select(output_format): raise format.InvalidFormatError(_("specified output format not supported.")) - run.hard = __read_git_config__("hard", False) - run.list_file_types = __read_git_config__("list-file-types", False) - run.include_metrics = __read_git_config__("metrics", False) - run.responsibilities = __read_git_config__("responsibilities", False) - run.useweeks = __read_git_config__("weeks", False) + run.hard = __read_git_config__(run.repo, "hard", False) + run.list_file_types = __read_git_config__(run.repo, "list-file-types", False) + run.include_metrics = __read_git_config__(run.repo, "metrics", False) + run.responsibilities = __read_git_config__(run.repo, "responsibilities", False) + run.useweeks = __read_git_config__(run.repo, "weeks", False) - since = __read_git_config__("since", None) + since = __read_git_config__(run.repo, "since", None) if since != None: interval.set_since(since) - until = __read_git_config__("until", None) + until = __read_git_config__(run.repo, "until", None) if until != None: interval.set_until(until) - run.timeline = __read_git_config__("timeline", False) + run.timeline = __read_git_config__(run.repo, "timeline", False) - if __read_git_config__("grading", False): + if __read_git_config__(run.repo, "grading", False): run.include_metrics = True run.list_file_types = True run.responsibilities = True diff --git a/gitinspector/gitinspector.py b/gitinspector/gitinspector.py index d1b58d1..d0eb1f8 100755 --- a/gitinspector/gitinspector.py +++ b/gitinspector/gitinspector.py @@ -90,13 +90,18 @@ def __check_python_version__(): def main(): __run__ = Runner() - config.init(__run__) try: __opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:F:hHlmrTwx:", ["checkout-missing", "exclude=", "file-types=", "format=", "hard", "help", "list-file-types", "metrics", "responsibilities", "since=", "grading", "timeline", "until=", "version"]) + for arg in __args__: + __run__.repo = arg + + #We need the repo above to be set before we read the git config. + config.init(__run__) + for o, a in __opts__: if o in("-c", "--checkout-missing"): missing.set_checkout_missing(True) @@ -137,8 +142,6 @@ def main(): __run__.useweeks = True elif o in("-x", "--exclude"): filtering.add(a) - for arg in __args__: - __run__.repo = arg except (format.InvalidFormatError, getopt.error) as msg: print(sys.argv[0], "\b:", msg)