Permalink
Browse files

PBGitIndex: Migrate discardChanges to the GitIndex

  • Loading branch information...
1 parent e17b454 commit 3dc312ff2e5971e528c89da63946cc2f67820558 @pieter committed Sep 13, 2009
Showing with 25 additions and 16 deletions.
  1. +1 −0 PBGitIndex.h
  2. +22 −0 PBGitIndex.m
  3. +2 −16 PBGitIndexController.m
View
1 PBGitIndex.h
@@ -60,6 +60,7 @@ extern NSString *PBGitIndexAmendMessageAvailable;
// Inter-file changes:
- (BOOL)stageFiles:(NSArray *)stageFiles;
- (BOOL)unstageFiles:(NSArray *)unstageFiles;
+- (void)discardChangesForFiles:(NSArray *)discardFiles;
// Intra-file changes
- (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
View
22 PBGitIndex.m
@@ -302,6 +302,28 @@ - (BOOL)unstageFiles:(NSArray *)unstageFiles
return YES;
}
+- (void)discardChangesForFiles:(NSArray *)discardFiles
+{
+ NSArray *paths = [discardFiles valueForKey:@"path"];
+ NSString *input = [paths componentsJoinedByString:@"\0"];
+
+ NSArray *arguments = [NSArray arrayWithObjects:@"checkout-index", @"--index", @"--quiet", @"--force", @"-z", @"--stdin", nil];
+
+ int ret = 1;
+ [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:[workingDirectory path] inputString:input retValue:&ret];
+
+ if (ret) {
+ // TODO: Post failed notification
+ // [[commitController.repository windowController] showMessageSheet:@"Discarding changes failed" infoText:[NSString stringWithFormat:@"Discarding changes failed with error code %i", ret]];
+ return;
+ }
+
+ for (PBChangedFile *file in discardFiles)
+ file.hasUnstagedChanges = NO;
+
+ [self postIndexChange];
+}
+
- (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
{
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"apply", nil];
View
18 PBGitIndexController.m
@@ -71,7 +71,7 @@ - (void) ignoreFiles:(NSArray *)files
- (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
{
- if(!force) {
+ if (!force) {
int ret = [[NSAlert alertWithMessageText:@"Discard changes"
defaultButton:nil
alternateButton:@"Cancel"
@@ -81,21 +81,7 @@ - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
return;
}
- NSArray *paths = [files valueForKey:@"path"];
- NSString *input = [paths componentsJoinedByString:@"\0"];
-
- NSArray *arguments = [NSArray arrayWithObjects:@"checkout-index", @"--index", @"--quiet", @"--force", @"-z", @"--stdin", nil];
- int ret = 1;
- [commitController.repository outputForArguments:arguments inputString:input retValue:&ret];
- if (ret) {
- [[commitController.repository windowController] showMessageSheet:@"Discarding changes failed" infoText:[NSString stringWithFormat:@"Discarding changes failed with error code %i", ret]];
- return;
- }
-
- for (PBChangedFile *file in files)
- file.hasUnstagedChanges = NO;
-
- // TODO: Post index update
+ [commitController.index discardChangesForFiles:files];
}
# pragma mark Context Menu methods

0 comments on commit 3dc312f

Please sign in to comment.