Files
gitx/PBDiffWindowController.m
T
Nathan Kinsinger c19d2c8058 Add Diff to contextual menus
- added to menus for refs, commits, and files
    - show a message when there are no changes
2010-03-13 22:16:24 -07:00

55 lines
1.4 KiB
Objective-C

//
// PBDiffWindowController.m
// GitX
//
// Created by Pieter de Bie on 13-10-08.
// Copyright 2008 Pieter de Bie. All rights reserved.
//
#import "PBDiffWindowController.h"
#import "PBGitRepository.h"
#import "PBGitCommit.h"
@implementation PBDiffWindowController
@synthesize diff;
- (id) initWithDiff:(NSString *)aDiff
{
if (![super initWithWindowNibName:@"PBDiffWindow"])
return nil;
diff = aDiff;
return self;
}
+ (void) showDiffWindowWithFiles:(NSArray *)filePaths fromCommit:(PBGitCommit *)startCommit diffCommit:(PBGitCommit *)diffCommit
{
if (!startCommit)
return;
if (!diffCommit)
diffCommit = [startCommit.repository headCommit];
NSString *commitSelector = [NSString stringWithFormat:@"%@..%@", [startCommit realSha], [diffCommit realSha]];
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"diff", commitSelector, nil];
if (filePaths) {
[arguments addObject:@"--"];
[arguments addObjectsFromArray:filePaths];
}
int retValue;
NSString *diff = [startCommit.repository outputInWorkdirForArguments:arguments retValue:&retValue];
if (retValue) {
NSLog(@"diff failed with retValue: %d for command: '%@' output: '%@'", retValue, [arguments componentsJoinedByString:@" "], diff);
return;
}
PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:[diff copy]];
[diffController showWindow:nil];
}
@end