@@ -108,34 +108,13 @@ - (void)discardSubmoduleAtPath:(NSString*)path resetIndex:(BOOL)resetIndex {
108108}
109109
110110- (void )stageAllChangesForFile : (NSString *)path {
111- return [self stageAllChangesForFiles: @[ path ]];
112- }
113-
114- - (void )stageAllChangesForFiles : (NSArray <NSString*>*)paths {
115111 NSError * error;
116- NSMutableArray * existingFiles = [NSMutableArray array ];
117- NSMutableArray * nonExistingFiles = [NSMutableArray array ];
118- for (NSString * path in paths) {
119- if ([[NSFileManager defaultManager ] fileExistsAtPath: [self .repository absolutePathForFile: path]]) {
120- [existingFiles addObject: path];
121- } else {
122- [nonExistingFiles addObject: path];
123- }
124- }
125-
126- if (existingFiles.count > 0 ) {
127- if (![self .repository addFilesToIndex: existingFiles error: &error]) {
128- [self presentError: error];
129- }
130- }
131-
132- if (nonExistingFiles.count > 0 ) {
133- if (![self .repository removeFilesFromIndex: nonExistingFiles error: &error]) {
134- [self presentError: error];
135- }
112+ BOOL fileExists = [[NSFileManager defaultManager ] fileExistsAtPath: [self .repository absolutePathForFile: path] followLastSymlink: NO ];
113+ if ((fileExists && [self .repository addFileToIndex: path error: &error]) || (!fileExists && [self .repository removeFileFromIndex: path error: &error])) {
114+ [self .repository notifyRepositoryChanged ];
115+ } else {
116+ [self presentError: error];
136117 }
137-
138- [self .repository notifyRepositoryChanged ];
139118}
140119
141120- (void )stageSelectedChangesForFile : (NSString *)path oldLines : (NSIndexSet *)oldLines newLines : (NSIndexSet *)newLines {
@@ -158,12 +137,8 @@ - (void)stageSelectedChangesForFile:(NSString*)path oldLines:(NSIndexSet*)oldLin
158137}
159138
160139- (void )unstageAllChangesForFile : (NSString *)path {
161- [self unstageAllChangesForFiles: @[ path ]];
162- }
163-
164- - (void )unstageAllChangesForFiles : (NSArray <NSString*>*)paths {
165140 NSError * error;
166- if ([self .repository resetFilesInIndexToHEAD: paths error: &error]) {
141+ if ([self .repository resetFileInIndexToHEAD: path error: &error]) {
167142 [self .repository notifyWorkingDirectoryChanged ];
168143 } else {
169144 [self presentError: error];
@@ -190,36 +165,18 @@ - (void)unstageSelectedChangesForFile:(NSString*)path oldLines:(NSIndexSet*)oldL
190165}
191166
192167- (BOOL )discardAllChangesForFile : (NSString *)path resetIndex : (BOOL )resetIndex error : (NSError **)error {
193- return [self discardAllChangesForFiles: @[ path ]
194- resetIndex: resetIndex
195- error: error];
196- }
197-
198- - (BOOL )discardAllChangesForFiles : (NSArray <NSString*>*)paths resetIndex : (BOOL )resetIndex error : (NSError **)error {
199168 BOOL success = NO ;
200169 if (resetIndex) {
201170 GCCommit* commit;
202- if ([self .repository lookupHEADCurrentCommit: &commit branch: NULL error: error] && [self .repository resetFilesInIndexToHEAD: paths error: error]) {
203- success = YES ;
204- for (NSString * path in paths) {
205- if (commit && [self .repository checkTreeForCommit: commit containsFile: path error: NULL ]) {
206- if (![self .repository safeDeleteFileIfExists: path error: error] && [self .repository checkoutFileFromIndex: path error: error]) {
207- return NO ;
208- }
209- } else {
210- if (![self .repository safeDeleteFileIfExists: path error: error]) {
211- return NO ;
212- }
213- }
171+ if ([self .repository lookupHEADCurrentCommit: &commit branch: NULL error: error] && [self .repository resetFileInIndexToHEAD: path error: error]) {
172+ if (commit && [self .repository checkTreeForCommit: commit containsFile: path error: NULL ]) {
173+ success = [self .repository safeDeleteFileIfExists: path error: error] && [self .repository checkoutFileFromIndex: path error: error];
174+ } else {
175+ success = [self .repository safeDeleteFile: path error: error];
214176 }
215177 }
216178 } else {
217- for (NSString * path in paths) {
218- if (![self .repository safeDeleteFileIfExists: path error: error]) {
219- return NO ;
220- }
221- }
222- success = [self .repository checkoutFilesFromIndex: paths error: error];
179+ success = [self .repository safeDeleteFileIfExists: path error: error] && [self .repository checkoutFileFromIndex: path error: error];
223180 }
224181 return success;
225182}
0 commit comments