Skip to content

Commit 2cad550

Browse files
committed
Starting port to ObjectiveGit.framework from wrappers around command-line git
1 parent 91e7d06 commit 2cad550

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

PBGitRepository.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
9191
- (NSString *) projectName;
9292
- (NSString *)gitIgnoreFilename;
9393
- (BOOL)isBareRepository;
94+
+ (BOOL)isBareRepository:(NSURL*)repositoryURL;
95+
9496

9597
- (void) reloadRefs;
9698
- (void) addRef:(PBGitRef *)ref fromParameters:(NSArray *)params;
@@ -139,4 +141,5 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
139141
@property (assign) PBGitRevSpecifier *currentBranch;
140142
@property (assign) NSInteger currentBranchFilter;
141143
@property (retain) NSMutableDictionary* refs;
144+
142145
@end

PBGitRepository.m

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#import "PBHistorySearchController.h"
2323
#import "PBGitRepositoryWatcher.h"
2424

25+
26+
#import <ObjectiveGit/GTRepository.h>
27+
#import <ObjectiveGit/git2/repository.h>
28+
2529
NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
2630

2731
@implementation PBGitRepository
@@ -39,21 +43,28 @@ - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError *
3943
return NO;
4044
}
4145

42-
+ (BOOL) isBareRepository: (NSString*) path
46+
+ (BOOL) isBareRepository: (NSURL*) url
4347
{
44-
return [[PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:[NSArray arrayWithObjects:@"rev-parse", @"--is-bare-repository", nil] inDir:path] isEqualToString:@"true"];
48+
NSError* pError;
49+
GTRepository* gitRepo = [[GTRepository alloc] initWithURL:url error:&pError];
50+
51+
return gitRepo && git_repository_is_bare([gitRepo repo]);
52+
}
53+
54+
- (BOOL) isBareRepository
55+
{
56+
return [PBGitRepository isBareRepository:[self fileURL]];
4557
}
4658

4759
+ (NSURL *)gitDirForURL:(NSURL *)repositoryURL;
4860
{
4961
if (![PBGitBinary path])
5062
return nil;
5163

52-
NSString* repositoryPath = [repositoryURL path];
53-
54-
if ([self isBareRepository:repositoryPath])
64+
if ([self isBareRepository:repositoryURL])
5565
return repositoryURL;
5666

67+
NSString* repositoryPath = [repositoryURL path];
5768
// Use rev-parse to find the .git dir for the repository being opened
5869
int retValue = 1;
5970
NSString *newPath = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:[NSArray arrayWithObjects:@"rev-parse", @"--git-dir", nil] inDir:repositoryPath retValue:&retValue];
@@ -79,7 +90,7 @@ + (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
7990
NSURL* gitDirURL = [self gitDirForURL:repositoryURL];
8091
NSString* repositoryPath = [gitDirURL path];
8192

82-
if (![self isBareRepository:repositoryPath]) {
93+
if (![PBGitRepository isBareRepository:repositoryURL]) {
8394
repositoryURL = [NSURL fileURLWithPath:[[repositoryURL path] stringByDeletingLastPathComponent]];
8495
}
8596

@@ -209,15 +220,6 @@ - (NSString*)gitIgnoreFilename
209220
return [[self workingDirectory] stringByAppendingPathComponent:@".gitignore"];
210221
}
211222

212-
- (BOOL)isBareRepository
213-
{
214-
if([self workingDirectory]) {
215-
return [PBGitRepository isBareRepository:[self workingDirectory]];
216-
} else {
217-
return true;
218-
}
219-
}
220-
221223
// Overridden to create our custom window controller
222224
- (void)makeWindowControllers
223225
{

0 commit comments

Comments
 (0)