Skip to content

Commit 58fb118

Browse files
committed
index.reset is now partly implemented using python, but in fact it resorts to using git-read-tree to keep the stat information when merging one tree in. After all this is what needed to be implemented in python as well
1 parent 402a6c2 commit 58fb118

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

lib/git/ext/gitdb

Submodule gitdb updated from d3a0037 to e3d5ad1

lib/git/index/base.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,44 +1066,58 @@ def handle_stderr(proc, iter_checked_out_files):
10661066
# END paths handling
10671067
assert "Should not reach this point"
10681068

1069-
@post_clear_cache
10701069
@default_index
10711070
def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwargs):
1072-
"""
1073-
Reset the index to reflect the tree at the given commit. This will not
1071+
"""Reset the index to reflect the tree at the given commit. This will not
10741072
adjust our HEAD reference as opposed to HEAD.reset by default.
10751073
1076-
``commit``
1074+
:param commit:
10771075
Revision, Reference or Commit specifying the commit we should represent.
10781076
If you want to specify a tree only, use IndexFile.from_tree and overwrite
10791077
the default index.
10801078
1081-
``working_tree``
1079+
:param working_tree:
10821080
If True, the files in the working tree will reflect the changed index.
10831081
If False, the working tree will not be touched
10841082
Please note that changes to the working copy will be discarded without
10851083
warning !
10861084
1087-
``head``
1085+
:param head:
10881086
If True, the head will be set to the given commit. This is False by default,
10891087
but if True, this method behaves like HEAD.reset.
10901088
1091-
``**kwargs``
1089+
:param kwargs:
10921090
Additional keyword arguments passed to git-reset
10931091
1094-
Returns
1095-
self
1096-
"""
1097-
cur_head = self.repo.head
1098-
prev_commit = cur_head.commit
1099-
1100-
# reset to get the tree/working copy
1101-
cur_head.reset(commit, index=True, working_tree=working_tree, paths=paths, **kwargs)
1102-
1103-
# put the head back, possibly
1104-
if not head:
1105-
cur_head.reset(prev_commit, index=False, working_tree=False)
1106-
# END reset head
1092+
:return: self """
1093+
# currently we have to use the git command to set the working copy.
1094+
# Otherwise we can use our own one
1095+
if working_tree:
1096+
cur_head = self.repo.head
1097+
prev_commit = cur_head.commit
1098+
1099+
cur_head.reset(commit, index=True, working_tree=working_tree, paths=paths, **kwargs)
1100+
1101+
# put the head back, possibly
1102+
if not head:
1103+
self.repo.head.commit = prev_commit
1104+
1105+
self._delete_entries_cache()
1106+
else:
1107+
# what we actually want to do is to merge the tree into our existing
1108+
# index, which is what git-read-tree does
1109+
new_inst = type(self).from_tree(self.repo, commit)
1110+
self.entries = new_inst.entries
1111+
self.write()
1112+
1113+
#new_inst = type(self).new(self.repo, self.repo.commit(commit).tree)
1114+
#self.entries = new_inst.entries
1115+
#self.write()
1116+
# self.repo.git.update_index(ignore_missing=True, refresh=True, q=True)
1117+
1118+
if head:
1119+
self.repo.head.commit = self.repo.commit(commit)
1120+
# END handle working tree
11071121

11081122
return self
11091123

test/git/test_index.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,6 @@ def make_paths():
578578

579579
@with_rw_repo('HEAD')
580580
def test_compare_write_tree(self, rw_repo):
581-
def write_tree(index):
582-
tree_sha = index.write_tree().sha
583-
return Tree(index.repo, tree_sha, 0, '')
584-
# END git cmd write tree
585-
586581
# write all trees and compare them
587582
# its important to have a few submodules in there too
588583
max_count = 25
@@ -593,8 +588,6 @@ def write_tree(index):
593588
count += 1
594589
index = rw_repo.index.reset(commit)
595590
orig_tree = commit.tree
596-
new_git_tree = write_tree(index)
597-
assert new_git_tree == orig_tree
598591
assert index.write_tree() == orig_tree
599592
# END for each commit
600593

0 commit comments

Comments
 (0)