From 01bdbfaba19f614c5ae7306e120706e64f1d48d8 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Sun, 1 Nov 2015 17:19:46 +0100 Subject: [PATCH] basedir.get_basedir_git() now takes an optional path argument. This enables us to change the working directory for the git commands in the function upon request. This change is in preparation of the completion of #24. --- gitinspector/basedir.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gitinspector/basedir.py b/gitinspector/basedir.py index e68e143..ae3619b 100644 --- a/gitinspector/basedir.py +++ b/gitinspector/basedir.py @@ -27,7 +27,13 @@ def get_basedir(): else: return os.path.dirname(os.path.realpath(__file__)) -def get_basedir_git(): +def get_basedir_git(path=None): + previous_directory = None + + if path != None: + previous_directory = os.getcwd() + os.chdir(path) + bare_command = subprocess.Popen(["git", "rev-parse", "--is-bare-repository"], bufsize=1, stdout=subprocess.PIPE, stderr=open(os.devnull, "w")) @@ -51,4 +57,7 @@ def get_basedir_git(): if len(absolute_path) == 0: sys.exit(_("Unable to determine absolute path of git repository.")) + if path != None: + os.chdir(previous_directory) + return absolute_path[0].decode("utf-8", "replace").strip()