Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
Use Objective Git to get details of the head commit for a repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Abizern committed Sep 14, 2011
1 parent 71836df commit 43e2898
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 107 deletions.
6 changes: 5 additions & 1 deletion CommitViewer/AppDelegate.h
Expand Up @@ -14,7 +14,11 @@
}

@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, retain) GTCommit *commit;
@property (nonatomic, readonly) NSString *messageTitle;
@property (nonatomic, readonly) NSString *messageDetails;
@property (nonatomic, readonly) NSString *author;
@property (nonatomic, readonly) NSDate *date;


- (IBAction)openNewRepository:(id)sender;

Expand Down
37 changes: 34 additions & 3 deletions CommitViewer/AppDelegate.m
Expand Up @@ -11,6 +11,8 @@

@interface AppDelegate ()

@property (nonatomic, retain) GTCommit *commit;

- (NSURL *)repositoryURLForURL:(NSURL *)url;

@end
Expand All @@ -20,11 +22,36 @@ @implementation AppDelegate
@synthesize window;
@synthesize commit;

+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
NSSet *keySet = [NSSet setWithObjects:@"commit", nil];
if ([key isEqualToString:@"messageTitle"] || [key isEqualToString:@"messageDetails"] || [key isEqualToString:@"author"] || [key isEqualToString:@"date"]) {
return keySet;
}
return [super keyPathsForValuesAffectingValueForKey:key];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}

#pragma mark - non-synthesised accessors
// Annoying that I have to do this - I'll have to change GTCommit to use properties at some later stage.

- (NSString *)messageTitle {
return [self.commit messageTitle];
}

- (NSString *)messageDetails {
return [self.commit messageDetails];
}

- (NSString *)author {
return [self.commit author].name;
}

- (NSDate *)date {
return [self.commit commitDate];
}

- (IBAction)openNewRepository:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
Expand All @@ -33,9 +60,14 @@ - (IBAction)openNewRepository:(id)sender {
panel.showsHiddenFiles = YES;

[panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
NSLog(@"selected: %@", [self repositoryURLForURL:panel.URL]);
if (result == NSFileHandlingPanelCancelButton) {
return;
}
// I should do more error checking but thsi is only an example project ;)
GTRepository *repo = [GTRepository repositoryWithURL:[self repositoryURLForURL:panel.URL] error:NULL];
GTReference *head = [repo headReferenceWithError:NULL];
self.commit = (GTCommit *)[repo lookupObjectBySha:[head target] error:NULL];

}];

}
Expand Down Expand Up @@ -64,7 +96,6 @@ - (NSURL *)repositoryURLForURL:(NSURL *)url {
// If the URL is a folder, then it should contain a subfolder called '.git
NSString *kGit = @".git";
NSString *endPoint = [url lastPathComponent];
NSLog(@"Endpoint: %@", endPoint);

if ([[endPoint lowercaseString] hasSuffix:kGit]) {
return url;
Expand Down

0 comments on commit 43e2898

Please sign in to comment.