Skip to content

Commit

Permalink
Use libgit2 to find the workdir directly, instead of Objective-Git
Browse files Browse the repository at this point in the history
Fixes #140
  • Loading branch information
rowanj committed Feb 4, 2013
1 parent 795876d commit 3ba6535
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions Classes/git/GitRepoFinder.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@ @implementation GitRepoFinder

+ (NSURL*)workDirForURL:(NSURL*)fileURL;
{
GTRepository* repo = [[GTRepository alloc] initWithURL:fileURL
error:nil];
NSURL* result = repo.fileURL;
if (!fileURL.isFileURL)
{
return nil;
}
git_repository* repo = nil;
git_repository_open_ext(&repo, fileURL.path.UTF8String, GIT_REPOSITORY_OPEN_CROSS_FS, NULL);
if (!repo)
{
return nil;
}
const char* workdir = git_repository_workdir(repo);
NSURL* result = nil;
if (workdir)
{
result = [NSURL fileURLWithPath:[NSString stringWithUTF8String:workdir]];
}
git_repository_free(repo); repo = nil;
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/gitx.m
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void handleGitXSearch(NSURL *repositoryURL, NSMutableArray *arguments)
NSString *pwd = [[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"];

NSURL* pwdURL = [NSURL fileURLWithPath:pwd];
NSURL* repoURL = [GitRepoFinder workDirForURL:pwdURL];
NSURL* repoURL = [GitRepoFinder fileURLForURL:pwdURL];
return repoURL;

}
Expand Down

0 comments on commit 3ba6535

Please sign in to comment.