diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj index 0a02bcb..8824a8d 100644 --- a/GitX.xcodeproj/project.pbxproj +++ b/GitX.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ F50FE0E30E07BE9600854FCD /* PBGitRevisionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F50FE0E20E07BE9600854FCD /* PBGitRevisionCell.m */; }; F513085B0E0740F2000C8BCD /* PBQLOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = F513085A0E0740F2000C8BCD /* PBQLOutlineView.m */; }; F5140DC90E8A8EB20091E9F3 /* RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = F5140DC80E8A8EB20091E9F3 /* RoundedRectangle.m */; }; + F523CEB60ED3399200DDD714 /* PBGitIndexController.m in Sources */ = {isa = PBXBuildFile; fileRef = F523CEB50ED3399200DDD714 /* PBGitIndexController.m */; }; F52BCE030E84208300AA3741 /* PBGitHistoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F52BCE020E84208300AA3741 /* PBGitHistoryView.xib */; }; F52BCE070E84211300AA3741 /* PBGitHistoryController.m in Sources */ = {isa = PBXBuildFile; fileRef = F52BCE060E84211300AA3741 /* PBGitHistoryController.m */; }; F53C4DF70E97FC630022AD59 /* PBGitBinary.m in Sources */ = {isa = PBXBuildFile; fileRef = F53C4DF60E97FC630022AD59 /* PBGitBinary.m */; }; @@ -141,6 +142,8 @@ F513085A0E0740F2000C8BCD /* PBQLOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBQLOutlineView.m; sourceTree = ""; }; F5140DC70E8A8EB20091E9F3 /* RoundedRectangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoundedRectangle.h; sourceTree = ""; }; F5140DC80E8A8EB20091E9F3 /* RoundedRectangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoundedRectangle.m; sourceTree = ""; }; + F523CEB40ED3399100DDD714 /* PBGitIndexController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitIndexController.h; sourceTree = ""; }; + F523CEB50ED3399200DDD714 /* PBGitIndexController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitIndexController.m; sourceTree = ""; }; F52BCE020E84208300AA3741 /* PBGitHistoryView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PBGitHistoryView.xib; sourceTree = ""; }; F52BCE050E84211300AA3741 /* PBGitHistoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitHistoryController.h; sourceTree = ""; }; F52BCE060E84211300AA3741 /* PBGitHistoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitHistoryController.m; sourceTree = ""; }; @@ -503,6 +506,8 @@ F59116E80E843BCB0072CCB1 /* PBGitCommitController.m */, F5E927FA0E883F0700056E75 /* PBWebChangesController.h */, F5E927FB0E883F0700056E75 /* PBWebChangesController.m */, + F523CEB40ED3399100DDD714 /* PBGitIndexController.h */, + F523CEB50ED3399200DDD714 /* PBGitIndexController.m */, ); name = Commit; sourceTree = ""; @@ -671,6 +676,7 @@ F5FC41F40EBCBD4300191D80 /* PBGitXProtocol.m in Sources */, F574A2850EAE2EAC003F2CB1 /* PBRefController.m in Sources */, F5FC43FE0EBD08EE00191D80 /* PBRefMenuItem.m in Sources */, + F523CEB60ED3399200DDD714 /* PBGitIndexController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PBChangedFile.h b/PBChangedFile.h index 2141e59..4641a4d 100644 --- a/PBChangedFile.h +++ b/PBChangedFile.h @@ -19,21 +19,22 @@ typedef enum { NSString *path; BOOL hasCachedChanges; BOOL hasUnstagedChanges; - __weak PBGitRepository *repository; + + // Index and HEAD stuff, to be used to revert changes + NSString *commitBlobSHA; + NSString *commitBlobMode; + PBChangedFileStatus status; } -@property (readonly) NSString *path; +@property (copy) NSString *path, *commitBlobSHA, *commitBlobMode; @property (assign) PBChangedFileStatus status; @property (assign) BOOL hasCachedChanges; @property (assign) BOOL hasUnstagedChanges; + - (NSImage *)icon; -- (NSString *)cachedChangesAmend:(BOOL)amend; -- (NSString *)unstagedChanges; +- (NSString *)indexInfo; -- (void) stageChanges; -- (void) unstageChangesAmend:(BOOL)amend; - -- (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r; +- (id) initWithPath:(NSString *)p; @end diff --git a/PBChangedFile.m b/PBChangedFile.m index 39cedd6..e2bb7e8 100644 --- a/PBChangedFile.m +++ b/PBChangedFile.m @@ -11,39 +11,25 @@ @implementation PBChangedFile -@synthesize path, status, hasCachedChanges, hasUnstagedChanges; +@synthesize path, status, hasCachedChanges, hasUnstagedChanges, commitBlobSHA, commitBlobMode; -- (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r +- (id) initWithPath:(NSString *)p { + if (![super init]) + return nil; + path = p; - repository = r; return self; } -- (NSString *) cachedChangesAmend:(BOOL) amend +- (NSString *)indexInfo { - if (amend) - return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"HEAD^", @"--", path, nil]]; - - return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"--", path, nil]]; + if (!self.commitBlobSHA) + return [NSString stringWithFormat:@"0 0000000000000000000000000000000000000000\t%@\0", self.path]; + else + return [NSString stringWithFormat:@"%@ %@\t%@\0", self.commitBlobMode, self.commitBlobSHA, self.path]; } -- (NSString *)unstagedChanges -{ - if (status == NEW) { - NSStringEncoding encoding; - NSError *error = nil; - NSString *contents = [NSString stringWithContentsOfFile:[[repository workingDirectory] stringByAppendingPathComponent:path] usedEncoding:&encoding error:&error]; - if (error) - return nil; - - return contents; - } - - return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", path, nil]]; -} - - - (NSImage *) icon { NSString *filename; @@ -62,45 +48,6 @@ return [[NSImage alloc] initByReferencingFile: p]; } -- (void) stageChanges -{ - if (status == DELETED) - [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"rm", path, nil]]; - else - [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"add", path, nil]]; - - self.hasUnstagedChanges = NO; - self.hasCachedChanges = YES; -} - -- (void) unstageChangesAmend:(BOOL) amend -{ - if (amend) - [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"HEAD^", @"--", path, nil]]; - else - [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"--", path, nil]]; - self.hasCachedChanges = NO; - self.hasUnstagedChanges = YES; -} - -- (void) forceRevertChanges -{ - [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", @"--", path, nil]]; - self.hasUnstagedChanges = NO; -} - -- (void) revertChanges -{ - int ret = [[NSAlert alertWithMessageText:@"Revert changes" - defaultButton:nil - alternateButton:@"Cancel" - otherButton:nil - informativeTextWithFormat:@"Are you sure you wish to revert the changes in '%@'?\n\n You cannot undo this operation.", path] runModal]; - - if (ret == NSAlertDefaultReturn) - [self forceRevertChanges]; -} - + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector { return NO; diff --git a/PBFileChangesTableView.h b/PBFileChangesTableView.h index 9a0d035..8dd6ba5 100644 --- a/PBFileChangesTableView.h +++ b/PBFileChangesTableView.h @@ -10,8 +10,6 @@ @interface PBFileChangesTableView : NSTableView { - id controller; } -@property (retain) id controller; @end diff --git a/PBFileChangesTableView.m b/PBFileChangesTableView.m index 91e776e..60c28a7 100644 --- a/PBFileChangesTableView.m +++ b/PBFileChangesTableView.m @@ -7,17 +7,14 @@ // #import "PBFileChangesTableView.h" -#import "PBGitCommitController.h" @implementation PBFileChangesTableView -@synthesize controller; - #pragma mark NSTableView overrides - (NSMenu *)menuForEvent:(NSEvent *)theEvent { - if (controller) - return [(PBGitCommitController *)controller menuForTable: self]; + if ([self delegate]) + return [[self delegate] menuForTable: self]; return nil; } diff --git a/PBGitCommitController.h b/PBGitCommitController.h index 53768f6..575b17e 100644 --- a/PBGitCommitController.h +++ b/PBGitCommitController.h @@ -17,21 +17,18 @@ IBOutlet NSTextView *commitMessageView; IBOutlet NSArrayController *unstagedFilesController; IBOutlet NSArrayController *cachedFilesController; - NSString *status; + IBOutlet id indexController; IBOutlet id webController; + NSString *status; + // We use busy as a count of active processes. // You can increase it when your process start // And decrease it after you have finished. int busy; BOOL amend; - IBOutlet PBIconAndTextCell* unstagedButtonCell; - IBOutlet PBIconAndTextCell* cachedButtonCell; - - IBOutlet NSTableView *unstagedTable; - IBOutlet NSTableView *cachedTable; } @property (retain) NSMutableArray *files; @@ -44,8 +41,6 @@ - (void) readUnstagedFiles:(NSNotification *)notification; - (void) stageHunk: (NSString *)hunk reverse:(BOOL)reverse; -- (NSMenu *) menuForTable:(NSTableView *)table; - - (IBAction) refresh:(id) sender; - (IBAction) commit:(id) sender; @end diff --git a/PBGitCommitController.m b/PBGitCommitController.m index 93c2b53..fe46670 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -17,18 +17,6 @@ - (void)awakeFromNib { [super awakeFromNib]; - self.busy = 0; - - amend = NO; - - [unstagedButtonCell setAction:@selector(rowClicked:)]; - [cachedButtonCell setAction:@selector(rowClicked:)]; - - [unstagedTable setDoubleAction:@selector(tableClicked:)]; - [cachedTable setDoubleAction:@selector(tableClicked:)]; - - [unstagedTable setController: self]; - [self refresh:self]; [commitMessageView setTypingAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Monaco" size:12.0] forKey:NSFontAttributeName]]; @@ -133,7 +121,7 @@ for (NSString *line in lines) { if ([line length] == 0) continue; - PBChangedFile *file =[[PBChangedFile alloc] initWithPath:line andRepository:repository]; + PBChangedFile *file =[[PBChangedFile alloc] initWithPath:line]; file.status = NEW; file.hasCachedChanges = NO; file.hasUnstagedChanges = YES; @@ -155,15 +143,22 @@ } even = 0; + NSString *mode = [[fileStatus objectAtIndex:0] substringFromIndex:1]; + NSString *sha = [fileStatus objectAtIndex:2]; + BOOL isNew = YES; // If the file is already added, we shouldn't add it again // but rather update it to incorporate our changes for (PBChangedFile *file in files) { if ([file.path isEqualToString:line]) { - if (cached) + if (cached) { + file.commitBlobSHA = sha; + file.commitBlobMode = mode; file.hasCachedChanges = YES; + } else file.hasUnstagedChanges = YES; + isNew = NO; break; } @@ -172,12 +167,17 @@ if (!isNew) continue; - PBChangedFile *file = [[PBChangedFile alloc] initWithPath:line andRepository:repository]; + PBChangedFile *file = [[PBChangedFile alloc] initWithPath:line]; if ([[fileStatus objectAtIndex:4] isEqualToString:@"D"]) file.status = DELETED; + else if([[fileStatus objectAtIndex:0] isEqualToString:@":000000"]) + file.status = NEW; else file.status = MODIFIED; + file.commitBlobSHA = sha; + file.commitBlobMode = mode; + file.hasCachedChanges = cached; file.hasUnstagedChanges = !cached; @@ -279,60 +279,6 @@ self.amend = NO; } -- (void) tableClicked:(NSTableView *) tableView -{ - NSUInteger selectionIndex = [[tableView selectedRowIndexes] firstIndex]; - NSArrayController *controller = [tableView tag] == 0 ? unstagedFilesController : cachedFilesController; - PBChangedFile *selectedItem = [[controller arrangedObjects] objectAtIndex:selectionIndex]; - - if ([tableView tag] == 0) - [selectedItem stageChanges]; - else - [selectedItem unstageChangesAmend:amend]; - -} - -- (void) rowClicked:(NSCell *)sender -{ - NSTableView *tableView = (NSTableView *)[sender controlView]; - if([tableView numberOfSelectedRows] != 1) - return; - [self tableClicked: tableView]; -} - -- (void)tableView:(NSTableView*)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)tableColumn row:(int)rowIndex -{ - [[tableColumn dataCell] setImage:[[[(([tableView tag] == 0) ? unstagedFilesController : cachedFilesController) arrangedObjects] objectAtIndex:rowIndex] icon]]; -} - -- (NSMenu *) menuForTable:(NSTableView *)table -{ - NSUInteger selectionIndex = [[table selectedRowIndexes] firstIndex]; - PBChangedFile *selectedItem = [[unstagedFilesController arrangedObjects] objectAtIndex:selectionIndex]; - - NSMenu *a = [[NSMenu alloc] init]; - NSMenuItem *stageItem = [[NSMenuItem alloc] initWithTitle:@"Stage Changes" action:@selector(stageChanges) keyEquivalent:@""]; - [stageItem setTarget:selectedItem]; - [a addItem:stageItem]; - - // Do not add "revert" options for untracked files - if (selectedItem.status == NEW) - return a; - - NSMenuItem *revertItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes…" action:@selector(revertChanges) keyEquivalent:@""]; - [revertItem setTarget:selectedItem]; - [revertItem setAlternate:NO]; - [a addItem:revertItem]; - - NSMenuItem *revertForceItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes" action:@selector(forceRevertChanges) keyEquivalent:@""]; - [revertForceItem setTarget:selectedItem]; - [revertForceItem setAlternate:YES]; - [revertForceItem setKeyEquivalentModifierMask:NSAlternateKeyMask]; - [a addItem:revertForceItem]; - - return a; -} - - (void) stageHunk:(NSString *)hunk reverse:(BOOL)reverse { NSMutableArray *array = [NSMutableArray arrayWithObjects:@"apply", @"--cached", nil]; diff --git a/PBGitCommitView.xib b/PBGitCommitView.xib index 57beb45..9dd1770 100644 --- a/PBGitCommitView.xib +++ b/PBGitCommitView.xib @@ -48,7 +48,7 @@ 1044 - + 6 System controlColor @@ -678,6 +678,22 @@ 1.600000e+01 1.000000e+02 + + + 292 + {{264, 10}, {169, 17}} + + YES + + 68288064 + 272630784 + Label + + + + + + {852, 432} @@ -706,6 +722,7 @@ description path icon + commitBlobSHA YES @@ -830,6 +847,9 @@ YES + + PBGitIndexController + @@ -962,38 +982,6 @@ 156 - - - delegate - - - - 178 - - - - delegate - - - - 179 - - - - cachedButtonCell - - - - 210 - - - - unstagedButtonCell - - - - 211 - commit: @@ -1042,22 +1030,6 @@ 222 - - - unstagedTable - - - - 223 - - - - cachedTable - - - - 224 - viewToolbar @@ -1090,6 +1062,126 @@ 253 + + + indexController + + + + 256 + + + + commitController + + + + 257 + + + + delegate + + + + 258 + + + + delegate + + + + 259 + + + + unstagedFilesController + + + + 260 + + + + stagedFilesController + + + + 261 + + + + indexController + + + + 262 + + + + stagedTable + + + + 263 + + + + unstagedTable + + + + 264 + + + + stagedButtonCell + + + + 265 + + + + unstagedButtonCell + + + + 266 + + + + rowClicked: + + + + 268 + + + + rowClicked: + + + + 269 + + + + value: selection.commitBlobSHA + + + + + + value: selection.commitBlobSHA + value + selection.commitBlobSHA + 2 + + + 274 + @@ -1128,6 +1220,7 @@ + @@ -1410,6 +1503,25 @@ + + 254 + + + + + 270 + + + YES + + + + + + 271 + + + @@ -1444,6 +1556,9 @@ 240.IBPluginDependency 247.IBPluginDependency 248.IBPluginDependency + 254.IBPluginDependency + 270.IBPluginDependency + 271.IBPluginDependency 42.IBPluginDependency 45.IBPluginDependency 46.IBPluginDependency @@ -1453,6 +1568,7 @@ 54.IBPluginDependency 55.IBPluginDependency 56.IBPluginDependency + 57.CustomClassName 57.IBPluginDependency 81.IBPluginDependency 86.IBPluginDependency @@ -1492,11 +1608,15 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin PBFileChangesTableView com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + PBFileChangesTableView com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1523,7 +1643,7 @@ - 253 + 275 @@ -1539,10 +1659,6 @@ PBFileChangesTableView NSTableView - - controller - id - IBProjectSource PBFileChangesTableView.h @@ -1568,24 +1684,18 @@ YES YES - cachedButtonCell cachedFilesController - cachedTable commitMessageView - unstagedButtonCell + indexController unstagedFilesController - unstagedTable webController YES - PBIconAndTextCell NSArrayController - NSTableView NSTextView - PBIconAndTextCell + id NSArrayController - NSTableView id @@ -1594,6 +1704,50 @@ PBGitCommitController.h + + PBGitIndexController + NSObject + + YES + + YES + rowClicked: + tableClicked: + + + YES + NSCell + NSTableView + + + + YES + + YES + commitController + stagedButtonCell + stagedFilesController + stagedTable + unstagedButtonCell + unstagedFilesController + unstagedTable + + + YES + PBGitCommitController + PBIconAndTextCell + NSArrayController + NSTableView + PBIconAndTextCell + NSArrayController + NSTableView + + + + IBProjectSource + PBGitIndexController.h + + PBIconAndTextCell NSTextFieldCell @@ -1631,12 +1785,14 @@ YES cachedFilesController controller + indexController unstagedFilesController YES NSArrayController PBGitCommitController + id NSArrayController diff --git a/PBGitIndexController.h b/PBGitIndexController.h new file mode 100644 index 0000000..4cd18a5 --- /dev/null +++ b/PBGitIndexController.h @@ -0,0 +1,32 @@ +// +// PBGitIndexController.h +// GitX +// +// Created by Pieter de Bie on 18-11-08. +// Copyright 2008 Pieter de Bie. All rights reserved. +// + +#import +#import "PBGitCommitController.h" +#import "PBChangedFile.h" + +@interface PBGitIndexController : NSObject { + IBOutlet NSArrayController *stagedFilesController, *unstagedFilesController; + IBOutlet PBGitCommitController *commitController; + + IBOutlet PBIconAndTextCell* unstagedButtonCell; + IBOutlet PBIconAndTextCell* stagedButtonCell; + + IBOutlet NSTableView *unstagedTable; + IBOutlet NSTableView *stagedTable; +} + +- (void) stageFiles:(NSArray *)files; +- (void) unstageFiles:(NSArray *)files; + +- (IBAction) rowClicked:(NSCell *) sender; +- (IBAction) tableClicked:(NSTableView *)tableView; + +- (NSString *) stagedChangesForFile:(PBChangedFile *)file; +- (NSString *) unstagedChangesForFile:(PBChangedFile *)file; +@end diff --git a/PBGitIndexController.m b/PBGitIndexController.m new file mode 100644 index 0000000..3591b97 --- /dev/null +++ b/PBGitIndexController.m @@ -0,0 +1,205 @@ +// +// PBGitIndexController.m +// GitX +// +// Created by Pieter de Bie on 18-11-08. +// Copyright 2008 Pieter de Bie. All rights reserved. +// + +#import "PBGitIndexController.h" +#import "PBChangedFile.h" + +@implementation PBGitIndexController + +- (void)awakeFromNib +{ + [unstagedTable setDoubleAction:@selector(tableClicked:)]; + [stagedTable setDoubleAction:@selector(tableClicked:)]; + + [unstagedTable setTarget:self]; + [stagedTable setTarget:self]; +} + +- (void) stageFiles:(NSArray *)files +{ + NSMutableString *input = [NSMutableString string]; + + for (PBChangedFile *file in files) { + [input appendFormat:@"%@\0", file.path]; + } + + int ret = 1; + [commitController.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"--add", @"--remove", @"-z", @"--stdin", nil] + inputString:input retValue:&ret]; + + if (ret) + { + NSLog(@"Error when updating index. Retvalue: %i", ret); + return; + } + + for (PBChangedFile *file in files) + { + file.hasUnstagedChanges = NO; + file.hasCachedChanges = YES; + } +} + +- (void) unstageFiles:(NSArray *)files +{ + NSMutableString *input = [NSMutableString string]; + + for (PBChangedFile *file in files) { + [input appendString:[file indexInfo]]; + } + + int ret = 1; + [commitController.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"-z", @"--index-info", nil] + inputString:input retValue:&ret]; + + if (ret) + { + NSLog(@"Error when updating index. Retvalue: %i", ret); + return; + } + + for (PBChangedFile *file in files) + { + file.hasUnstagedChanges = YES; + file.hasCachedChanges = NO; + } +} + +# pragma mark Displaying diffs + +- (NSString *) stagedChangesForFile:(PBChangedFile *)file +{ + NSString *indexPath = [@":0:" stringByAppendingString:file.path]; + + if (file.status == NEW) + return [commitController.repository outputForArguments:[NSArray arrayWithObjects:@"show", indexPath, nil]]; + + return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", file.commitBlobSHA, indexPath, nil]]; +} + +- (NSString *)unstagedChangesForFile:(PBChangedFile *)file +{ + if (file.status == NEW) { + NSStringEncoding encoding; + NSError *error = nil; + NSString *contents = [NSString stringWithContentsOfFile:[[commitController.repository workingDirectory] stringByAppendingPathComponent:file.path] + usedEncoding:&encoding error:&error]; + if (error) + return nil; + + return contents; + } + + return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", file.path, nil]]; +} + +//- (void) forceRevertChanges +//{ +// [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", @"--", file.path, nil]]; +// self.hasUnstagedChanges = NO; +//} +// +//- (void) revertChanges +//{ +// int ret = [[NSAlert alertWithMessageText:@"Revert changes" +// defaultButton:nil +// alternateButton:@"Cancel" +// otherButton:nil +// informativeTextWithFormat:@"Are you sure you wish to revert the changes in '%@'?\n\n You cannot undo this operation.", path] runModal]; +// +// if (ret == NSAlertDefaultReturn) +// [self forceRevertChanges]; +//} + + +# pragma mark Context Menu methods +- (NSMenu *) menuForTable:(NSTableView *)table +{ + NSMenu *menu = [[NSMenu alloc] init]; + + // Unstaged changes + if ([table tag] == 0) { + NSArray *selectedFiles = [unstagedFilesController selectedObjects]; + + NSMenuItem *stageItem = [[NSMenuItem alloc] initWithTitle:@"Stage Changes" action:@selector(stageFilesAction:) keyEquivalent:@""]; + [stageItem setTarget:self]; + [stageItem setRepresentedObject:selectedFiles]; + [menu addItem:stageItem]; + } + else if ([table tag] == 1) { + NSArray *selectedFiles = [stagedFilesController selectedObjects]; + + NSMenuItem *unstageItem = [[NSMenuItem alloc] initWithTitle:@"Unstage Changes" action:@selector(unstageFilesAction:) keyEquivalent:@""]; + [unstageItem setTarget:self]; + [unstageItem setRepresentedObject:selectedFiles]; + [menu addItem:unstageItem]; + } + + // Do not add "revert" options for untracked files + // if (selectedItem.status == NEW) + // return a; + // + // NSMenuItem *revertItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes…" action:@selector(revertChanges) keyEquivalent:@""]; + // [revertItem setTarget:selectedItem]; + // [revertItem setAlternate:NO]; + // [a addItem:revertItem]; + // + // NSMenuItem *revertForceItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes" action:@selector(forceRevertChanges) keyEquivalent:@""]; + // [revertForceItem setTarget:selectedItem]; + // [revertForceItem setAlternate:YES]; + // [revertForceItem setKeyEquivalentModifierMask:NSAlternateKeyMask]; + // [a addItem:revertForceItem]; + + return menu; +} + +- (void) stageFilesAction:(id) sender +{ + [self stageFiles:[sender representedObject]]; +} + +- (void) unstageFilesAction:(id) sender +{ + [self unstageFiles:[sender representedObject]]; +} + +# pragma mark TableView icon delegate +- (void)tableView:(NSTableView*)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)tableColumn row:(int)rowIndex +{ + id controller = [tableView tag] == 0 ? unstagedFilesController : stagedFilesController; + [[tableColumn dataCell] setImage:[[[controller arrangedObjects] objectAtIndex:rowIndex] icon]]; +} + +- (void) tableClicked:(NSTableView *) tableView +{ + NSArrayController *controller = [tableView tag] == 0 ? unstagedFilesController : stagedFilesController; + + NSIndexSet *selectionIndexes = [tableView selectedRowIndexes]; + NSArray *files = [[controller arrangedObjects] objectsAtIndexes:selectionIndexes]; + if ([tableView tag] == 0) + [self stageFiles:files]; + else + [self unstageFiles:files]; +} + +- (void) rowClicked:(NSCell *)sender +{ + NSTableView *tableView = (NSTableView *)[sender controlView]; + if([tableView numberOfSelectedRows] != 1) + return; + [self tableClicked: tableView]; +} + +# pragma mark WebKit Accessibility + ++ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector +{ + return NO; +} + +@end diff --git a/PBGitRepository.m b/PBGitRepository.m index a017b16..fb8079b 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -367,7 +367,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; { return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments - inDir: self.fileURL.path + inDir:[self workingDirectory] inputString:input retValue: ret]; } diff --git a/PBWebChangesController.h b/PBWebChangesController.h index dd7af8d..796f2b4 100644 --- a/PBWebChangesController.h +++ b/PBWebChangesController.h @@ -15,6 +15,7 @@ IBOutlet NSArrayController *unstagedFilesController; IBOutlet NSArrayController *cachedFilesController; IBOutlet PBGitCommitController *controller; + IBOutlet id indexController; PBChangedFile *selectedFile; BOOL selectedFileIsCached; @@ -23,4 +24,5 @@ - (void) refresh; - (void) setStateMessage:(NSString *)state; +- (void) showMultiple:(NSArray *)files; @end diff --git a/PBWebChangesController.m b/PBWebChangesController.m index fe88f90..7afc1b6 100644 --- a/PBWebChangesController.m +++ b/PBWebChangesController.m @@ -24,6 +24,7 @@ - (void) didLoad { + [[self script] setValue:indexController forKey:@"IndexController"]; [self refresh]; } diff --git a/html/views/commit/commit.js b/html/views/commit/commit.js index 845620b..60516f5 100644 --- a/html/views/commit/commit.js +++ b/html/views/commit/commit.js @@ -2,7 +2,7 @@ var showNewFile = function(file) { $('title').innerHTML = "New file: " + file.path; - var contents = file.unstagedChanges(); + var contents = IndexController.unstagedChangesForFile_(file); if (!contents) { notify("Can not display changes (Binary file?)", -1); return; @@ -36,11 +36,11 @@ var showFileChanges = function(file, cached) { var changes; if (cached) { $("title").innerHTML = "Staged changes for " + file.path; - changes = file.cachedChangesAmend_(Controller.amend()); + changes = IndexController.stagedChangesForFile_(file); } else { $("title").innerHTML = "Unstaged changes for " + file.path; - changes = file.unstagedChanges(); + changes = IndexController.unstagedChangesForFile_(file); } if (changes == "") {