Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support worktrees in latest libgit2 in -[GTRepository fileURL] #626

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion External/libgit2
Submodule libgit2 updated 314 files
28 changes: 27 additions & 1 deletion ObjectiveGit/GTRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,33 @@ - (NSURL *)fileURL {
// bare repository, you may be looking for gitDirectoryURL
if (path == NULL) return nil;

return [NSURL fileURLWithPath:@(path) isDirectory:YES];
NSString *pathString = @(path);
NSURL *fileURL = [NSURL fileURLWithPath:pathString isDirectory:YES];

if ([fileURL baseURL]) {
// This might be a relative path because we've loaded a worktree
// In this case we need to see if we can find the parent repository to construct an absolute URL
git_buf root = {0};

int error = git_repository_discover(&root, [[[self gitDirectoryURL] URLByDeletingLastPathComponent] fileSystemRepresentation], false, NULL);

if (!error) {
git_repository *repository;

if (git_repository_open(&repository, root.ptr) == 0) {
const char *workdir = git_repository_workdir(repository);
NSString *workdirString = [NSString stringWithUTF8String:workdir];

fileURL = [NSURL fileURLWithPath:pathString isDirectory:YES relativeToURL:[NSURL fileURLWithPath:workdirString]];

git_repository_free(repository);
}
}

git_buf_free(&root);
}

return fileURL;
}

- (NSURL *)gitDirectoryURL {
Expand Down