@@ -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
0 commit comments