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.
This commit is contained in:
Adam Waldenberg 2013-07-01 01:38:19 +02:00
parent ce98a2ed70
commit 021c1e479e
2 changed files with 25 additions and 17 deletions

View file

@ -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

View file

@ -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)