@@ -1066,44 +1066,58 @@ def handle_stderr(proc, iter_checked_out_files):
1066
1066
# END paths handling
1067
1067
assert "Should not reach this point"
1068
1068
1069
- @post_clear_cache
1070
1069
@default_index
1071
1070
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
1074
1072
adjust our HEAD reference as opposed to HEAD.reset by default.
1075
1073
1076
- `` commit``
1074
+ :param commit:
1077
1075
Revision, Reference or Commit specifying the commit we should represent.
1078
1076
If you want to specify a tree only, use IndexFile.from_tree and overwrite
1079
1077
the default index.
1080
1078
1081
- `` working_tree``
1079
+ :param working_tree:
1082
1080
If True, the files in the working tree will reflect the changed index.
1083
1081
If False, the working tree will not be touched
1084
1082
Please note that changes to the working copy will be discarded without
1085
1083
warning !
1086
1084
1087
- `` head``
1085
+ :param head:
1088
1086
If True, the head will be set to the given commit. This is False by default,
1089
1087
but if True, this method behaves like HEAD.reset.
1090
1088
1091
- ``** kwargs``
1089
+ :param kwargs:
1092
1090
Additional keyword arguments passed to git-reset
1093
1091
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
1107
1121
1108
1122
return self
1109
1123
0 commit comments