Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Since we are using NSDocument now it’s best to use the document fileU…

…RL to store the .git path.
  • Loading branch information...
commit 3998ffece25cb1d2066d974d06a67f1c8b5109cc 1 parent b85a205
Ciarán Walsh ciaran authored
Showing with 25 additions and 13 deletions.
  1. +0 −1  PBGitRepository.h
  2. +25 −12 PBGitRepository.m
1  PBGitRepository.h
View
@@ -12,7 +12,6 @@
extern NSString* PBGitRepositoryErrorDomain;
@interface PBGitRepository : NSDocument {
- NSString* path;
PBGitRevList* revisionList;
}
37 PBGitRepository.m
View
@@ -17,7 +17,7 @@
@implementation PBGitRepository
-@synthesize path, revisionList;
+@synthesize revisionList;
static NSString* gitPath;
+ (void) initialize
@@ -58,7 +58,7 @@ - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError *
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
{
- self.path = nil;
+ BOOL success = NO;
if (![fileWrapper isDirectory]) {
if (outError) {
@@ -70,14 +70,17 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
NSString* repositoryPath = [[self fileURL] path];
if ([repositoryPath hasSuffix:@".git"]) {
- self.path = repositoryPath;
+ [self setFileURL:[NSURL fileURLWithPath:repositoryPath]];
+ success = YES;
} else {
// Use rev-parse to find the .git dir for the repository being opened
NSString* newPath = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"rev-parse", @"--git-dir", nil] inDir:repositoryPath];
if ([newPath isEqualToString:@".git"]) {
- self.path = [repositoryPath stringByAppendingPathComponent:@".git"];
+ [self setFileURL:[NSURL fileURLWithPath:[repositoryPath stringByAppendingPathComponent:@".git"]]];
+ success = YES;
} else if ([newPath length] > 0) {
- self.path = newPath;
+ [self setFileURL:[NSURL fileURLWithPath:newPath]];
+ success = YES;
} else if (outError) {
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [fileWrapper filename]]
forKey:NSLocalizedRecoverySuggestionErrorKey];
@@ -85,12 +88,22 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
}
}
- if (self.path) {
+ if (success) {
revisionList = [[PBGitRevList alloc] initWithRepository:self andRevListParameters:[NSArray array]];
}
}
- return self.path != nil;
+ return success;
+}
+
+// The fileURL the document keeps is to the .git dir, but that’s pretty
+// useless for display in the window title bar, so we show the directory above
+- (NSString*)displayName
+{
+ NSString* displayName = self.fileURL.path.lastPathComponent;
+ if ([displayName isEqualToString:@".git"])
+ displayName = [self.fileURL.path stringByDeletingLastPathComponent].lastPathComponent;
+ return displayName;
}
// Overridden to create our custom window controller
@@ -110,16 +123,16 @@ + (PBGitRepository*) repositoryWithPath:(NSString*) path
- (PBGitRepository*) initWithPath: (NSString*) p
{
if ([p hasSuffix:@".git"])
- self.path = p;
+ [self setFileURL:[NSURL fileURLWithPath:p]];
else {
NSString* newPath = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"rev-parse", @"--git-dir", nil] inDir:p];
if ([newPath isEqualToString:@".git"])
- self.path = [p stringByAppendingPathComponent:@".git"];
+ [self setFileURL:[NSURL fileURLWithPath:[p stringByAppendingPathComponent:@".git"]]];
else
- self.path = newPath;
+ [self setFileURL:[NSURL fileURLWithPath:newPath]];
}
- NSLog(@"Git path is: %@", self.path);
+ NSLog(@"Git path is: %@", self.fileURL);
revisionList = [[PBGitRevList alloc] initWithRepository:self andRevListParameters:[NSArray array]];
return self;
}
@@ -127,7 +140,7 @@ - (PBGitRepository*) initWithPath: (NSString*) p
- (NSFileHandle*) handleForArguments:(NSArray *)args
{
- NSString* gitDirArg = [@"--git-dir=" stringByAppendingString:path];
+ NSString* gitDirArg = [@"--git-dir=" stringByAppendingString:self.fileURL.path];
NSMutableArray* arguments = [NSMutableArray arrayWithObject: gitDirArg];
[arguments addObjectsFromArray: args];
return [PBEasyPipe handleForCommand:gitPath withArgs:arguments];
Please sign in to comment.
Something went wrong with that request. Please try again.