Gracefully handle non-git-repo path (Fixes issue 44).

Error out gracefully when gitinspector is called with a path that does not
point to a git repository, instead of printing a stack trace.

Signed-off-by: Christian Kastner <debian@kvr.at>
Signed-off-by: Adam Waldenberg <adam.waldenberg@ejwa.se>
This commit is contained in:
Christian Kastner 2014-11-08 21:49:56 +01:00 committed by Adam Waldenberg
parent 68a6e90228
commit e3b4857eb6
1 changed files with 6 additions and 3 deletions

View File

@ -33,9 +33,12 @@ def get_basedir_git():
global __git_basedir__
if not __git_basedir__:
isbare = subprocess.Popen("git rev-parse --is-bare-repository", shell=True, bufsize=1,
stdout=subprocess.PIPE).stdout
isbare = isbare.readlines()
sp = subprocess.Popen("git rev-parse --is-bare-repository", shell=True, bufsize=1,
stdout=subprocess.PIPE, stderr=open(os.devnull, "w"))
isbare = sp.stdout.readlines()
sp.wait()
if sp.returncode != 0:
sys.exit("Error processing git repository at \"%s\"" % os.getcwd())
isbare = (isbare[0].decode("utf-8", "replace").strip() == "true")
absolute_path = ""