From e4f767f7c9a2c4a2f01d0345820bf7b500a1f834 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 27 Jun 2014 08:36:29 +0300 Subject: GitRepository/has_submodules: add treeish argument For defining a Git treeish which to look into, instead of the current working copy. Signed-off-by: Markus Lehtonen --- gbp/git/repository.py | 13 +++++++++---- tests/04_test_submodules.py | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 797c8c0..689430f 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -1736,18 +1736,23 @@ class GitRepository(object): #{ Submodules - def has_submodules(self): + def has_submodules(self, treeish=None): """ Does the repo have any submodules? + @param treeish: look into treeish + @type treeish: C{str} @return: C{True} if the repository has any submodules, C{False} otherwise @rtype: C{bool} """ - if os.path.exists(os.path.join(self.path, '.gitmodules')): + if treeish: + try: + self.show('%s:.gitmodules' % treeish) + except GitRepositoryError: + return False return True - else: - return False + return os.path.exists(os.path.join(self.path, '.gitmodules')) def add_submodule(self, repo_path): diff --git a/tests/04_test_submodules.py b/tests/04_test_submodules.py index a18f8b5..deb389d 100644 --- a/tests/04_test_submodules.py +++ b/tests/04_test_submodules.py @@ -87,6 +87,8 @@ def test_add_submodule(): def test_has_submodules(): """Check for submodules""" ok_(REPO.has_submodules()) + ok_(REPO.has_submodules('HEAD')) + ok_(not REPO.has_submodules('HEAD^')) def test_get_submodules(): -- cgit v1.2.3