Skip to content

Commit 3dc312f

Browse files
committed
PBGitIndex: Migrate discardChanges to the GitIndex
1 parent e17b454 commit 3dc312f

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

PBGitIndex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern NSString *PBGitIndexAmendMessageAvailable;
6060
// Inter-file changes:
6161
- (BOOL)stageFiles:(NSArray *)stageFiles;
6262
- (BOOL)unstageFiles:(NSArray *)unstageFiles;
63+
- (void)discardChangesForFiles:(NSArray *)discardFiles;
6364

6465
// Intra-file changes
6566
- (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;

PBGitIndex.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,28 @@ - (BOOL)unstageFiles:(NSArray *)unstageFiles
302302
return YES;
303303
}
304304

305+
- (void)discardChangesForFiles:(NSArray *)discardFiles
306+
{
307+
NSArray *paths = [discardFiles valueForKey:@"path"];
308+
NSString *input = [paths componentsJoinedByString:@"\0"];
309+
310+
NSArray *arguments = [NSArray arrayWithObjects:@"checkout-index", @"--index", @"--quiet", @"--force", @"-z", @"--stdin", nil];
311+
312+
int ret = 1;
313+
[PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:[workingDirectory path] inputString:input retValue:&ret];
314+
315+
if (ret) {
316+
// TODO: Post failed notification
317+
// [[commitController.repository windowController] showMessageSheet:@"Discarding changes failed" infoText:[NSString stringWithFormat:@"Discarding changes failed with error code %i", ret]];
318+
return;
319+
}
320+
321+
for (PBChangedFile *file in discardFiles)
322+
file.hasUnstagedChanges = NO;
323+
324+
[self postIndexChange];
325+
}
326+
305327
- (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
306328
{
307329
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"apply", nil];

PBGitIndexController.m

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ - (void) ignoreFiles:(NSArray *)files
7171

7272
- (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
7373
{
74-
if(!force) {
74+
if (!force) {
7575
int ret = [[NSAlert alertWithMessageText:@"Discard changes"
7676
defaultButton:nil
7777
alternateButton:@"Cancel"
@@ -81,21 +81,7 @@ - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
8181
return;
8282
}
8383

84-
NSArray *paths = [files valueForKey:@"path"];
85-
NSString *input = [paths componentsJoinedByString:@"\0"];
86-
87-
NSArray *arguments = [NSArray arrayWithObjects:@"checkout-index", @"--index", @"--quiet", @"--force", @"-z", @"--stdin", nil];
88-
int ret = 1;
89-
[commitController.repository outputForArguments:arguments inputString:input retValue:&ret];
90-
if (ret) {
91-
[[commitController.repository windowController] showMessageSheet:@"Discarding changes failed" infoText:[NSString stringWithFormat:@"Discarding changes failed with error code %i", ret]];
92-
return;
93-
}
94-
95-
for (PBChangedFile *file in files)
96-
file.hasUnstagedChanges = NO;
97-
98-
// TODO: Post index update
84+
[commitController.index discardChangesForFiles:files];
9985
}
10086

10187
# pragma mark Context Menu methods

0 commit comments

Comments
 (0)