diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-12-23 21:03:25 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-12-23 21:18:27 +0100 |
commit | 7b297b719f1a0318b07675dab186cb2ab6459bc5 (patch) | |
tree | 3b2fa5318a4ceec340567bbd9c183ec59582b241 | |
parent | 62c368cb83eb6a7b9e9dc14bb8701d15279afb3a (diff) |
GitRepository: allow to check cleaniness of arbitrary paths
-rw-r--r-- | gbp/git/repository.py | 19 | ||||
-rw-r--r-- | tests/doctests/test_GitRepository.py | 6 |
2 files changed, 20 insertions, 5 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 644fc7b4..c7d22764 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -791,25 +791,32 @@ class GitRepository(object): args += [commit, '--'] self._git_command("reset", args) - def _status(self, porcelain, ignore_untracked): + def _status(self, porcelain, ignore_untracked, paths): args = GitArgs() args.add_true(ignore_untracked, '-uno') args.add_true(porcelain, '--porcelain') + if paths is None: + paths = [] + elif isinstance(paths, six.string_types): + paths = [paths] + out, ret = self._git_getoutput('status', - args.args, + args.args + paths, extra_env={'LC_ALL': 'C'}) if ret: raise GitRepositoryError("Can't get repository status") return out - def is_clean(self, ignore_untracked=False): + def is_clean(self, ignore_untracked=False, paths=None): """ Does the repository contain any uncommitted modifications? @param ignore_untracked: whether to ignore untracked files when checking the repository status @type ignore_untracked: C{bool} + @param paths: only check changes on paths + @type paths: C{list} of C{stings} @return: C{True} if the repository is clean, C{False} otherwise and Git's status message @rtype: C{tuple} @@ -818,11 +825,13 @@ class GitRepository(object): return (True, '') out = self._status(porcelain=True, - ignore_untracked=ignore_untracked) + ignore_untracked=ignore_untracked, + paths=paths) if out: # Get a more helpful error message. out = self._status(porcelain=False, - ignore_untracked=ignore_untracked) + ignore_untracked=ignore_untracked, + paths=paths) return (False, "".join(out)) else: return (True, '') diff --git a/tests/doctests/test_GitRepository.py b/tests/doctests/test_GitRepository.py index a5d6c534..e353df84 100644 --- a/tests/doctests/test_GitRepository.py +++ b/tests/doctests/test_GitRepository.py @@ -90,6 +90,12 @@ def test_add_files(): ... os.path.join(repo.path, "testfile")) >>> repo.is_clean()[0] False + >>> repo.is_clean('doesnotexist')[0] + True + >>> repo.is_clean(paths='testfile')[0] + False + >>> repo.is_clean(paths=['doesnotexist', 'testfile'])[0] + False >>> repo.is_clean(ignore_untracked=True)[0] True >>> repo.add_files(repo.path, force=True) |