Instead of just looking for the existence of the .git directory in the
current directory, use 'git rev-parse --show-cdup' to figure out where
the root of the git repository is relatively to the current directory
(and raise an error if we're actually not in a git repository).
---
Is this what you had in mind? I didn't use '--is-bare-repository' as I'm
not sure what should be done depending on the result.
This works for me when I run git-buildpackage from within any directory
of a git repository, but maybe there are other cases I didn't consider.
--
Benoît Knecht
---
diff --git a/gbp/git.py b/gbp/git.py
index 9d5a318..a5ffcab 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -5,6 +5,7 @@
import re
import subprocess
+import os
import os.path
from command_wrappers import (GitAdd, GitRm, GitCheckoutBranch, GitInit,
GitCommand, copy_from)
from errors import GbpError
@@ -20,11 +21,14 @@ class GitRepository(object):
"""Represents a git repository at path"""
def __init__(self, path):
- try:
- os.stat(os.path.join(path,'.git'))
- except:
+ # Look for the relative path to the root of the git repository
+ values, exitcode = self.__git_getoutput("rev-parse", ["--show-cdup"])
+ # Raise an error if we're not in a git repository
+ if exitcode != 0:
raise GitRepositoryError
- self.path = os.path.abspath(path)
+ to_git_root = values[0].strip()
+ self.path = os.path.abspath(os.path.join(path, to_git_root))
+ os.chdir(self.path)
def __check_path(self):
if os.getcwd() != self.path:
--
1.7.2.3
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]