22
22
#import " PBHistorySearchController.h"
23
23
#import " PBGitRepositoryWatcher.h"
24
24
25
+
26
+ #import < ObjectiveGit/GTRepository.h>
27
+ #import < ObjectiveGit/git2/repository.h>
28
+
25
29
NSString * PBGitRepositoryErrorDomain = @" GitXErrorDomain" ;
26
30
27
31
@implementation PBGitRepository
@@ -39,21 +43,28 @@ - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError *
39
43
return NO ;
40
44
}
41
45
42
- + (BOOL ) isBareRepository : (NSString *) path
46
+ + (BOOL ) isBareRepository : (NSURL *) url
43
47
{
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 ]];
45
57
}
46
58
47
59
+ (NSURL *)gitDirForURL : (NSURL *)repositoryURL ;
48
60
{
49
61
if (![PBGitBinary path ])
50
62
return nil ;
51
63
52
- NSString * repositoryPath = [repositoryURL path ];
53
-
54
- if ([self isBareRepository: repositoryPath])
64
+ if ([self isBareRepository: repositoryURL])
55
65
return repositoryURL;
56
66
67
+ NSString * repositoryPath = [repositoryURL path ];
57
68
// Use rev-parse to find the .git dir for the repository being opened
58
69
int retValue = 1 ;
59
70
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;
79
90
NSURL * gitDirURL = [self gitDirForURL: repositoryURL];
80
91
NSString * repositoryPath = [gitDirURL path ];
81
92
82
- if (![self isBareRepository: repositoryPath ]) {
93
+ if (![PBGitRepository isBareRepository: repositoryURL ]) {
83
94
repositoryURL = [NSURL fileURLWithPath: [[repositoryURL path ] stringByDeletingLastPathComponent ]];
84
95
}
85
96
@@ -209,15 +220,6 @@ - (NSString*)gitIgnoreFilename
209
220
return [[self workingDirectory ] stringByAppendingPathComponent: @" .gitignore" ];
210
221
}
211
222
212
- - (BOOL )isBareRepository
213
- {
214
- if ([self workingDirectory ]) {
215
- return [PBGitRepository isBareRepository: [self workingDirectory ]];
216
- } else {
217
- return true ;
218
- }
219
- }
220
-
221
223
// Overridden to create our custom window controller
222
224
- (void )makeWindowControllers
223
225
{
0 commit comments