diff options
author | Zaar Hai <haizaar@haizaar.com> | 2016-08-01 14:33:43 +0300 |
---|---|---|
committer | Zaar Hai <haizaar@haizaar.com> | 2016-08-01 14:33:43 +0300 |
commit | c3c70daba7a3d195d22ded363c9915b5433ce054 (patch) | |
tree | d197c17e7d1b0d00824fdc0804e8dde7d4a235e9 /git | |
parent | 4896fa2ccbd84553392e2a74af450d807e197783 (diff) | |
download | gitpython-c3c70daba7a3d195d22ded363c9915b5433ce054.tar.gz |
is_dirty supports path. Fixes #482.
Diffstat (limited to 'git')
-rw-r--r-- | git/repo/base.py | 11 | ||||
-rw-r--r-- | git/test/test_repo.py | 18 |
2 files changed, 25 insertions, 4 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index 282dfc15..5d0a6d30 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -585,7 +585,7 @@ class Repo(object): doc="Retrieve a list of alternates paths or set a list paths to be used as alternates") def is_dirty(self, index=True, working_tree=True, untracked_files=False, - submodules=True): + submodules=True, path=None): """ :return: ``True``, the repository is considered dirty. By default it will react @@ -600,6 +600,8 @@ class Repo(object): default_args = ['--abbrev=40', '--full-index', '--raw'] if not submodules: default_args.append('--ignore-submodules') + if path: + default_args.append(path) if index: # diff index against HEAD if isfile(self.index.path) and \ @@ -612,7 +614,7 @@ class Repo(object): return True # END working tree handling if untracked_files: - if len(self._get_untracked_files(ignore_submodules=not submodules)): + if len(self._get_untracked_files(path, ignore_submodules=not submodules)): return True # END untracked files return False @@ -633,9 +635,10 @@ class Repo(object): consider caching it yourself.""" return self._get_untracked_files() - def _get_untracked_files(self, **kwargs): + def _get_untracked_files(self, *args, **kwargs): # make sure we get all files, no only untracked directores - proc = self.git.status(porcelain=True, + proc = self.git.status(*args, + porcelain=True, untracked_files=True, as_process=True, **kwargs) diff --git a/git/test/test_repo.py b/git/test/test_repo.py index fc8125fa..7ccd173e 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -271,6 +271,24 @@ class TestRepo(TestBase): assert self.rorepo.is_dirty() is False self.rorepo._bare = orig_val + @with_rw_repo('HEAD') + def test_is_dirty_with_path(self, rwrepo): + assert rwrepo.is_dirty(path="git") is False + + with open(os.path.join(rwrepo.working_dir, "git", "util.py"), "at") as f: + f.write("junk") + assert rwrepo.is_dirty(path="git") is True + assert rwrepo.is_dirty(path="doc") is False + + rwrepo.git.add(os.path.join("git", "util.py")) + assert rwrepo.is_dirty(index=False, path="git") is False + assert rwrepo.is_dirty(path="git") is True + + with open(os.path.join(rwrepo.working_dir, "doc", "no-such-file.txt"), "wt") as f: + f.write("junk") + assert rwrepo.is_dirty(path="doc") is False + assert rwrepo.is_dirty(untracked_files=True, path="doc") is True + def test_head(self): assert self.rorepo.head.reference.object == self.rorepo.active_branch.object |