Skip to content

Commit 04db47d

Browse files
committed
Merge commit 'origin/master'
* commit 'origin/master': CommitController: Don't turn of off automatic rearranging PBGitRepository: Clean up the readFromURL: method PBGitRepository: Fix opening of large directories due to bug in NSFileWrapper. PBGitIndexController: Renamed "Revert" to "Discard" CommitController: Reject merges HistoryController: Add "Open Files" menu item WebHistoryView: Also use the tree context menu HistoryController: Use a programatically created context menu WebHistoryController: Refactor menu search to be recursive HistoryController: Add some marks PBGitHistory: Add "Show in Finder" to files Display context menu in the history tree to show related commits History fileview: select current item on rightclick PBGitConfig: Add missing sentinel Remove use of deprecated stringWithCString HistoryView: only add parents if parents array exists keyboardNavigation: Fix keys 'c' and 'v' from webView Site: add link to Twitter Conflicts: PBGitHistoryView.xib PBGitIndexController.m
2 parents 3ee50de + 64182ea commit 04db47d

14 files changed

+203
-80
lines changed

PBGitBinary.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ + (void) initialize
6666

6767
// Try to find the path of the Git binary
6868
char* path = getenv("GIT_PATH");
69-
if (path && [self acceptBinary:[NSString stringWithCString:path]])
69+
if (path && [self acceptBinary:[NSString stringWithUTF8String:path]])
7070
return;
7171

7272
// No explicit path. Try it with "which"

PBGitCommitController.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ - (void) doneProcessingIndex
201201

202202
- (void) readOtherFiles:(NSNotification *)notification;
203203
{
204-
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];
205204
NSArray *lines = [self linesFromNotification:notification];
206205
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithCapacity:[lines count]];
207206
// We fake this files status as good as possible.
@@ -324,6 +323,11 @@ - (void) commitFailedBecause:(NSString *)reason
324323

325324
- (IBAction) commit:(id) sender
326325
{
326+
if ([[NSFileManager defaultManager] fileExistsAtPath:[repository.fileURL.path stringByAppendingPathComponent:@"MERGE_HEAD"]]) {
327+
[[repository windowController] showMessageSheet:@"Cannot commit merges" infoText:@"GitX cannot commit merges yet. Please commit your changes from the command line."];
328+
return;
329+
}
330+
327331
if ([[cachedFilesController arrangedObjects] count] == 0) {
328332
[[repository windowController] showMessageSheet:@"No changes to commit" infoText:@"You must first stage some changes before committing"];
329333
return;

PBGitConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (void) setValue:(id)value forKeyPath:(NSString *)path
7979

8080
// Check if it exists globally. In that case, write it as a global
8181

82-
NSArray *arguments = [NSArray arrayWithObjects:@"config", @"--global", @"--get", path];
82+
NSArray *arguments = [NSArray arrayWithObjects:@"config", @"--global", @"--get", path, nil];
8383
int ret;
8484
[PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:nil retValue:&ret];
8585
if (!ret) // It exists globally

PBGitHistoryController.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
- (IBAction) openSelectedFile: sender;
4343
- (void) updateQuicklookForce: (BOOL) force;
4444

45+
// Context menu methods
46+
- (NSMenu *)contextMenuForTreeView;
47+
- (NSArray *)menuItemsForPaths:(NSArray *)paths;
48+
- (void)showCommitsFromTree:(id)sender;
49+
- (void)showInFinderAction:(id)sender;
50+
- (void)openFilesAction:(id)sender;
51+
4552
- (void) copyCommitInfo;
4653

4754
- (BOOL) hasNonlinearPath;

PBGitHistoryController.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ - (void) removeView
208208
[super removeView];
209209
}
210210

211+
#pragma mark Table Column Methods
211212
- (NSMenu *)tableColumnMenu
212213
{
213214
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Table columns menu"];
@@ -223,4 +224,76 @@ - (NSMenu *)tableColumnMenu
223224
return menu;
224225
}
225226

227+
#pragma mark Tree Context Menu Methods
228+
229+
- (void)showCommitsFromTree:(id)sender
230+
{
231+
// TODO: Enable this from webview as well!
232+
233+
NSMutableArray *filePaths = [NSMutableArray arrayWithObjects:@"HEAD", @"--", NULL];
234+
[filePaths addObjectsFromArray:[sender representedObject]];
235+
236+
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithParameters:filePaths];
237+
238+
repository.currentBranch = [repository addBranch:revSpec];
239+
}
240+
241+
- (void)showInFinderAction:(id)sender
242+
{
243+
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
244+
NSString *path;
245+
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
246+
247+
for (NSString *filePath in [sender representedObject]) {
248+
path = [workingDirectory stringByAppendingPathComponent:filePath];
249+
[ws selectFile: path inFileViewerRootedAtPath:path];
250+
}
251+
252+
}
253+
254+
- (void)openFilesAction:(id)sender
255+
{
256+
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
257+
NSString *path;
258+
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
259+
260+
for (NSString *filePath in [sender representedObject]) {
261+
path = [workingDirectory stringByAppendingPathComponent:filePath];
262+
[ws openFile:path];
263+
}
264+
}
265+
266+
267+
- (NSMenu *)contextMenuForTreeView
268+
{
269+
NSArray *filePaths = [[treeController selectedObjects] valueForKey:@"fullPath"];
270+
271+
NSMenu *menu = [[NSMenu alloc] init];
272+
for (NSMenuItem *item in [self menuItemsForPaths:filePaths])
273+
[menu addItem:item];
274+
return menu;
275+
}
276+
277+
- (NSArray *)menuItemsForPaths:(NSArray *)paths
278+
{
279+
BOOL multiple = [paths count] != 1;
280+
NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show history of files" : @"Show history of file"
281+
action:@selector(showCommitsFromTree:)
282+
keyEquivalent:@""];
283+
NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder"
284+
action:@selector(showInFinderAction:)
285+
keyEquivalent:@""];
286+
NSMenuItem *openFilesItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Open Files" : @"Open File"
287+
action:@selector(openFilesAction:)
288+
keyEquivalent:@""];
289+
290+
NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, openFilesItem, nil];
291+
for (NSMenuItem *item in menuItems) {
292+
[item setTarget:self];
293+
[item setRepresentedObject:paths];
294+
}
295+
296+
return menuItems;
297+
}
298+
226299
@end

PBGitHistoryView.xib

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
1111
<integer value="237"/>
12-
<integer value="27"/>
12+
<integer value="2"/>
1313
</object>
1414
<object class="NSArray" key="IBDocument.PluginDependencies">
1515
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -2953,7 +2953,7 @@
29532953
</object>
29542954
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29552955
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2956-
<string>{{178, 79}, {852, 432}}</string>
2956+
<string>{{358, 67}, {852, 432}}</string>
29572957
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29582958
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29592959
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2988,7 +2988,7 @@
29882988
</object>
29892989
</object>
29902990
<nil key="sourceID"/>
2991-
<int key="maxID">274</int>
2991+
<int key="maxID">286</int>
29922992
</object>
29932993
<object class="IBClassDescriber" key="IBDocument.Classes">
29942994
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3028,6 +3028,8 @@
30283028
<string>setDetailedView:</string>
30293029
<string>setRawView:</string>
30303030
<string>setTreeView:</string>
3031+
<string>showCommitsFromTree:</string>
3032+
<string>showInFinderAction:</string>
30313033
<string>toggleQuickView:</string>
30323034
</object>
30333035
<object class="NSMutableArray" key="dict.values">
@@ -3038,6 +3040,8 @@
30383040
<string>id</string>
30393041
<string>id</string>
30403042
<string>id</string>
3043+
<string>id</string>
3044+
<string>id</string>
30413045
</object>
30423046
</object>
30433047
<object class="NSMutableDictionary" key="outlets">
@@ -3048,6 +3052,7 @@
30483052
<string>commitList</string>
30493053
<string>fileBrowser</string>
30503054
<string>searchField</string>
3055+
<string>treeContextMenu</string>
30513056
<string>treeController</string>
30523057
<string>webView</string>
30533058
</object>
@@ -3057,6 +3062,7 @@
30573062
<string>NSTableView</string>
30583063
<string>NSOutlineView</string>
30593064
<string>NSSearchField</string>
3065+
<string>NSMenu</string>
30603066
<string>NSTreeController</string>
30613067
<string>id</string>
30623068
</object>

PBGitIndexController.m

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -157,36 +157,33 @@ - (NSString *)unstagedChangesForFile:(PBChangedFile *)file
157157
return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-files", [self contextParameter], @"--", file.path, nil]];
158158
}
159159

160-
- (void) forceRevertChangesForFiles:(NSArray *)files
160+
- (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
161161
{
162+
if(!force) {
163+
int ret = [[NSAlert alertWithMessageText:@"Discard changes"
164+
defaultButton:nil
165+
alternateButton:@"Cancel"
166+
otherButton:nil
167+
informativeTextWithFormat:@"Are you sure you wish to discard the changes to this file?\n\nYou cannot undo this operation."] runModal];
168+
if (ret != NSAlertDefaultReturn)
169+
return;
170+
}
171+
162172
NSArray *paths = [files valueForKey:@"path"];
163173
NSString *input = [paths componentsJoinedByString:@"\0"];
164174

165175
NSArray *arguments = [NSArray arrayWithObjects:@"checkout-index", @"--index", @"--quiet", @"--force", @"-z", @"--stdin", nil];
166176
int ret = 1;
167177
[commitController.repository outputForArguments:arguments inputString:input retValue:&ret];
168178
if (ret) {
169-
[[commitController.repository windowController] showMessageSheet:@"Reverting changes failed" infoText:[NSString stringWithFormat:@"Reverting changes failed with error code %i", ret]];
179+
[[commitController.repository windowController] showMessageSheet:@"Discarding changes failed" infoText:[NSString stringWithFormat:@"Discarding changes failed with error code %i", ret]];
170180
return;
171181
}
172182

173183
for (PBChangedFile *file in files)
174184
file.hasUnstagedChanges = NO;
175185
}
176186

177-
- (void) revertChangesForFiles:(NSArray *)files
178-
{
179-
int ret = [[NSAlert alertWithMessageText:@"Revert changes"
180-
defaultButton:nil
181-
alternateButton:@"Cancel"
182-
otherButton:nil
183-
informativeTextWithFormat:@"Are you sure you wish to revert changes?\n\nYou cannot undo this operation."] runModal];
184-
185-
if (ret == NSAlertDefaultReturn)
186-
[self forceRevertChangesForFiles:files];
187-
}
188-
189-
190187
# pragma mark Context Menu methods
191188
- (BOOL) allSelectedCanBeIgnored:(NSArray *)selectedFiles
192189
{
@@ -244,19 +241,19 @@ - (NSMenu *) menuForTable:(NSTableView *)table
244241
if (!file.hasUnstagedChanges)
245242
return menu;
246243

247-
NSMenuItem *revertItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes…" action:@selector(revertFilesAction:) keyEquivalent:@""];
248-
[revertItem setTarget:self];
249-
[revertItem setAlternate:NO];
250-
[revertItem setRepresentedObject:selectedFiles];
244+
NSMenuItem *discardItem = [[NSMenuItem alloc] initWithTitle:@"Discard changes" action:@selector(discardFilesAction:) keyEquivalent:@""];
245+
[discardItem setTarget:self];
246+
[discardItem setAlternate:NO];
247+
[discardItem setRepresentedObject:selectedFiles];
251248

252-
[menu addItem:revertItem];
249+
[menu addItem:discardItem];
253250

254-
NSMenuItem *revertForceItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes" action:@selector(forceRevertFilesAction:) keyEquivalent:@""];
255-
[revertForceItem setTarget:self];
256-
[revertForceItem setAlternate:YES];
257-
[revertForceItem setRepresentedObject:selectedFiles];
258-
[revertForceItem setKeyEquivalentModifierMask:NSAlternateKeyMask];
259-
[menu addItem:revertForceItem];
251+
NSMenuItem *discardForceItem = [[NSMenuItem alloc] initWithTitle:@"Discard changes" action:@selector(forceDiscardFilesAction:) keyEquivalent:@""];
252+
[discardForceItem setTarget:self];
253+
[discardForceItem setAlternate:YES];
254+
[discardForceItem setRepresentedObject:selectedFiles];
255+
[discardForceItem setKeyEquivalentModifierMask:NSAlternateKeyMask];
256+
[menu addItem:discardForceItem];
260257

261258
return menu;
262259
}
@@ -288,18 +285,18 @@ - (void) ignoreFilesAction:(id) sender
288285
[commitController refresh:NULL];
289286
}
290287

291-
- (void) revertFilesAction:(id) sender
288+
- (void)discardFilesAction:(id) sender
292289
{
293290
NSArray *selectedFiles = [sender representedObject];
294291
if ([selectedFiles count] > 0)
295-
[self revertChangesForFiles:selectedFiles];
292+
[self discardChangesForFiles:selectedFiles force:FALSE];
296293
}
297294

298-
- (void) forceRevertFilesAction:(id) sender
295+
- (void)forceDiscardFilesAction:(id) sender
299296
{
300297
NSArray *selectedFiles = [sender representedObject];
301298
if ([selectedFiles count] > 0)
302-
[self forceRevertChangesForFiles:selectedFiles];
299+
[self discardChangesForFiles:selectedFiles force:TRUE];
303300
}
304301

305302
- (void) showInFinderAction:(id) sender

PBGitRepository.m

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ + (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
7272
return repositoryURL;
7373
}
7474

75-
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
75+
// NSFileWrapper is broken and doesn't work when called on a directory containing a large number of directories and files.
76+
//because of this it is safer to implement readFromURL than readFromFileWrapper.
77+
//Because NSFileManager does not attempt to recursively open all directories and file when fileExistsAtPath is called
78+
//this works much better.
79+
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
7680
{
77-
BOOL success = NO;
78-
7981
if (![PBGitBinary path])
8082
{
8183
if (outError) {
@@ -86,30 +88,32 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
8688
return NO;
8789
}
8890

89-
if (![fileWrapper isDirectory]) {
91+
BOOL isDirectory = FALSE;
92+
[[NSFileManager defaultManager] fileExistsAtPath:[absoluteURL path] isDirectory:&isDirectory];
93+
if (!isDirectory) {
9094
if (outError) {
91-
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Reading files is not supported.", [fileWrapper filename]]
92-
forKey:NSLocalizedRecoverySuggestionErrorKey];
93-
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
94-
}
95-
} else {
96-
NSURL* gitDirURL = [PBGitRepository gitDirForURL:[self fileURL]];
97-
if (gitDirURL) {
98-
[self setFileURL:gitDirURL];
99-
success = YES;
100-
} else if (outError) {
101-
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [fileWrapper filename]]
102-
forKey:NSLocalizedRecoverySuggestionErrorKey];
95+
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:@"Reading files is not supported."
96+
forKey:NSLocalizedRecoverySuggestionErrorKey];
10397
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
10498
}
99+
return NO;
100+
}
105101

106-
if (success) {
107-
[self setup];
108-
[self readCurrentBranch];
102+
103+
NSURL* gitDirURL = [PBGitRepository gitDirForURL:[self fileURL]];
104+
if (!gitDirURL) {
105+
if (outError) {
106+
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [self fileName]]
107+
forKey:NSLocalizedRecoverySuggestionErrorKey];
108+
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
109109
}
110+
return NO;
110111
}
111112

112-
return success;
113+
[self setFileURL:gitDirURL];
114+
[self setup];
115+
[self readCurrentBranch];
116+
return YES;
113117
}
114118

115119
- (void) setup

PBQLOutlineView.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ - (NSArray *)outlineView:(NSOutlineView *)outlineView namesOfPromisedFilesDroppe
5858
return fileNames;
5959
}
6060

61+
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
62+
{
63+
if ([theEvent type] == NSRightMouseDown)
64+
{
65+
// get the current selections for the outline view.
66+
NSIndexSet *selectedRowIndexes = [self selectedRowIndexes];
67+
68+
// select the row that was clicked before showing the menu for the event
69+
NSPoint mousePoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
70+
int row = [self rowAtPoint:mousePoint];
71+
72+
// figure out if the row that was just clicked on is currently selected
73+
if ([selectedRowIndexes containsIndex:row] == NO)
74+
[self selectRow:row byExtendingSelection:NO];
75+
}
76+
77+
return [controller contextMenuForTreeView];
78+
}
79+
6180
/* Implemented to satisfy datasourcee protocol */
6281
- (BOOL) outlineView: (NSOutlineView *)ov
6382
isItemExpandable: (id)item { return NO; }

0 commit comments

Comments
 (0)