Skip to content

Commit 3ba6535

Browse files
committed
Use libgit2 to find the workdir directly, instead of Objective-Git
Fixes #140
1 parent 795876d commit 3ba6535

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Classes/git/GitRepoFinder.m

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@ @implementation GitRepoFinder
1212

1313
+ (NSURL*)workDirForURL:(NSURL*)fileURL;
1414
{
15-
GTRepository* repo = [[GTRepository alloc] initWithURL:fileURL
16-
error:nil];
17-
NSURL* result = repo.fileURL;
15+
if (!fileURL.isFileURL)
16+
{
17+
return nil;
18+
}
19+
git_repository* repo = nil;
20+
git_repository_open_ext(&repo, fileURL.path.UTF8String, GIT_REPOSITORY_OPEN_CROSS_FS, NULL);
21+
if (!repo)
22+
{
23+
return nil;
24+
}
25+
const char* workdir = git_repository_workdir(repo);
26+
NSURL* result = nil;
27+
if (workdir)
28+
{
29+
result = [NSURL fileURLWithPath:[NSString stringWithUTF8String:workdir]];
30+
}
31+
git_repository_free(repo); repo = nil;
1832
return result;
1933
}
2034

Classes/gitx.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void handleGitXSearch(NSURL *repositoryURL, NSMutableArray *arguments)
320320
NSString *pwd = [[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"];
321321

322322
NSURL* pwdURL = [NSURL fileURLWithPath:pwd];
323-
NSURL* repoURL = [GitRepoFinder workDirForURL:pwdURL];
323+
NSURL* repoURL = [GitRepoFinder fileURLForURL:pwdURL];
324324
return repoURL;
325325

326326
}

0 commit comments

Comments
 (0)