diff options
m--------- | lib/git/ext/gitdb | 0 | ||||
-rw-r--r-- | lib/git/index/base.py | 54 | ||||
-rw-r--r-- | test/git/test_index.py | 7 |
3 files changed, 34 insertions, 27 deletions
diff --git a/lib/git/ext/gitdb b/lib/git/ext/gitdb -Subproject d3a0037dd5a11459985e7dc4b6819f6292f20c1 +Subproject e3d5ad195d9dfa46af3d931f9769e965e337daf diff --git a/lib/git/index/base.py b/lib/git/index/base.py index 96cd6e40..fb23b1b7 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -1066,44 +1066,58 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # END paths handling assert "Should not reach this point" - @post_clear_cache @default_index def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwargs): - """ - Reset the index to reflect the tree at the given commit. This will not + """Reset the index to reflect the tree at the given commit. This will not adjust our HEAD reference as opposed to HEAD.reset by default. - ``commit`` + :param commit: Revision, Reference or Commit specifying the commit we should represent. If you want to specify a tree only, use IndexFile.from_tree and overwrite the default index. - ``working_tree`` + :param 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 ! - ``head`` + :param head: If True, the head will be set to the given commit. This is False by default, but if True, this method behaves like HEAD.reset. - ``**kwargs`` + :param kwargs: Additional keyword arguments passed to git-reset - Returns - self - """ - cur_head = self.repo.head - prev_commit = cur_head.commit - - # reset to get the tree/working copy - cur_head.reset(commit, index=True, working_tree=working_tree, paths=paths, **kwargs) - - # put the head back, possibly - if not head: - cur_head.reset(prev_commit, index=False, working_tree=False) - # END reset head + :return: self """ + # currently we have to use the git command to set the working copy. + # Otherwise we can use our own one + if working_tree: + cur_head = self.repo.head + prev_commit = cur_head.commit + + cur_head.reset(commit, index=True, working_tree=working_tree, paths=paths, **kwargs) + + # put the head back, possibly + if not head: + self.repo.head.commit = prev_commit + + self._delete_entries_cache() + else: + # what we actually want to do is to merge the tree into our existing + # index, which is what git-read-tree does + new_inst = type(self).from_tree(self.repo, commit) + self.entries = new_inst.entries + self.write() + + #new_inst = type(self).new(self.repo, self.repo.commit(commit).tree) + #self.entries = new_inst.entries + #self.write() + # self.repo.git.update_index(ignore_missing=True, refresh=True, q=True) + + if head: + self.repo.head.commit = self.repo.commit(commit) + # END handle working tree return self diff --git a/test/git/test_index.py b/test/git/test_index.py index 09b49aaa..e9f99f04 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -578,11 +578,6 @@ class TestIndex(TestBase): @with_rw_repo('HEAD') def test_compare_write_tree(self, rw_repo): - def write_tree(index): - tree_sha = index.write_tree().sha - return Tree(index.repo, tree_sha, 0, '') - # END git cmd write tree - # write all trees and compare them # its important to have a few submodules in there too max_count = 25 @@ -593,8 +588,6 @@ class TestIndex(TestBase): count += 1 index = rw_repo.index.reset(commit) orig_tree = commit.tree - new_git_tree = write_tree(index) - assert new_git_tree == orig_tree assert index.write_tree() == orig_tree # END for each commit |