Skip to content

Commit

Permalink
git-pw: Recurse with newer versions of GitPython
Browse files Browse the repository at this point in the history
Ander noticed we didn't actually recurse, and that

    commit 7403987
    Author: Damien Lespiau <damien.lespiau@intel.com>
    Date:   Wed Nov 11 12:42:05 2015 +0000

    git-pw: Make git-pw work with older versions of GitPython

was too hopeful in its expectations (I swear it was true at the time?
but may have been fooled).

v2: Use git.__version__ to decide when to include the
    search_parent_directories named argument.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Apr 13, 2016
1 parent 2dc322d commit 2742b76
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion git-pw/git-pw
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,27 @@ class GitPatchwork(object):
def __init__(self):
self.cmd = Command()

def _git_python_version(self):
# remove anything after a first space ('0.3.2 RC1' -> '0.3.2')
version = git.__version__.split()[0]
# return (major, minor, path)
return tuple(map(int, version.split('.')))

def _create_repo(self, path):
# we want to recurse through parent directories:
# - early versions of GitPython's Repo constructor doesn't have the
# search_parent_directories named argument, but do recurse
# - at some point, GitPython introduced said argument and defaults
# to non-recursive. Only try that if the first call fails to
# create the repo object
if self._git_python_version() >= (0, 3, 5):
return git.Repo(os.getcwd(), search_parent_directories=True)
else:
return git.Repo(os.getcwd())

def setup(self):
try:
self.repo = git.Repo(os.getcwd())
self.repo = self._create_repo(os.getcwd())
except git.exc.InvalidGitRepositoryError:
if self.cmd.need_git_repo:
die('Not a git repository.')
Expand Down

0 comments on commit 2742b76

Please sign in to comment.