GitIndex: Add methods to stage and unstage files

These are mostly copies from PBGitIndexController, and
they can be refactored to a common method. I'm not sure of a name
for that yet, so I'll keep it like this for now :)
This commit is contained in:
Pieter de Bie
2009-09-13 02:33:26 +02:00
parent 64a52ad9e0
commit 35a4dc37e2
2 changed files with 68 additions and 2 deletions
+2 -2
View File
@@ -44,8 +44,8 @@
//- (void)commit;
// Inter-file changes:
//- (void)stageFiles:(NSArray *)files;
//- (void)unstageFiles:(NSArray *)files;
- (BOOL)stageFiles:(NSArray *)stageFiles;
- (BOOL)unstageFiles:(NSArray *)unstageFiles;
// Intra-file changes
//- (void)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
+66
View File
@@ -118,6 +118,71 @@
return parent;
}
- (BOOL)stageFiles:(NSArray *)stageFiles
{
// Input string for update-index
// This will be a list of filenames that
// should be updated. It's similar to
// "git add -- <files>
NSMutableString *input = [NSMutableString string];
for (PBChangedFile *file in stageFiles) {
[input appendFormat:@"%@\0", file.path];
}
int ret = 1;
[repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"--add", @"--remove", @"-z", @"--stdin", nil]
inputString:input
retValue:&ret];
if (ret) {
// FIXME: failed notification?
NSLog(@"Error when updating index. Retvalue: %i", ret);
return NO;
}
// TODO: Stop Tracking
for (PBChangedFile *file in stageFiles)
{
file.hasUnstagedChanges = NO;
file.hasStagedChanges = YES;
}
// TODO: Resume tracking
return YES;
}
// TODO: Refactor with above. What's a better name for this?
- (BOOL)unstageFiles:(NSArray *)unstageFiles
{
NSMutableString *input = [NSMutableString string];
for (PBChangedFile *file in unstageFiles) {
[input appendString:[file indexInfo]];
}
int ret = 1;
[repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"-z", @"--index-info", nil]
inputString:input
retValue:&ret];
if (ret)
{
// FIXME: Failed notification
NSLog(@"Error when updating index. Retvalue: %i", ret);
return NO;
}
// TODO: stop tracking
for (PBChangedFile *file in unstageFiles)
{
file.hasUnstagedChanges = YES;
file.hasStagedChanges = NO;
}
// TODO: resume tracking
return YES;
}
- (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines:(NSUInteger)context
{
NSString *parameter = [NSString stringWithFormat:@"-U%u", context];
@@ -147,6 +212,7 @@
return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-files", parameter, @"--", file.path, nil]];
}
# pragma mark WebKit Accessibility
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector