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.
This commit is contained in:
Adam Waldenberg 2015-11-01 17:19:46 +01:00
parent 7f5b50cd0d
commit 01bdbfaba1
1 changed files with 10 additions and 1 deletions

View File

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