diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-23 17:55:33 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-23 18:12:58 +0200 |
commit | 13a26d4f9c22695033040dfcd8c76fd94187035b (patch) | |
tree | c6211517e1b73d98837b4d04d930fb76a81af4e3 /lib/git/index.py | |
parent | 81d8788d40867f4e5cf3016ef219473951a7f6ed (diff) | |
download | gitpython-13a26d4f9c22695033040dfcd8c76fd94187035b.tar.gz |
Implemented index.reset method including test
Diffstat (limited to 'lib/git/index.py')
-rw-r--r-- | lib/git/index.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/git/index.py b/lib/git/index.py index 754c9f15..111dc8d2 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -528,13 +528,13 @@ class IndexFile(LazyMixin, diff.Diffable): Note: This is a possibly dangerious operations as it will discard your changes - to index.endtries + to index.entries Returns self """ del(self.entries) - self.entries + # allows to lazily reread on demand return self def write_tree(self): @@ -623,7 +623,7 @@ class IndexFile(LazyMixin, diff.Diffable): raise NotImplementedError("todo") @default_index - def reset(self, commit='HEAD', working_tree=False, **kwargs): + def reset(self, commit='HEAD', working_tree=False, paths=None, **kwargs): """ Reset the index to reflect the tree at the given commit. This will not adjust our HEAD reference as opposed to HEAD.reset. @@ -636,11 +636,23 @@ class IndexFile(LazyMixin, diff.Diffable): ``working_tree`` If True, the files in the working tree will reflect the changed index. If False, the working tree will not be touched + Please note that changes to the working copy will be discarded without + warning ! ``**kwargs`` Additional keyword arguments passed to git-reset + + Returns + self """ - raise NotImplementedError("todo: use git-read-tree if there is no working tree to update") + head = self.repo.head + prev_commit = head.commit + + # reset to get the tree/working copy + head.reset(commit, index=True, working_tree=working_tree, paths=paths, **kwargs) + # put the head back + head.reset(prev_commit, index=False, working_tree=False) + return self @default_index def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwargs): |