-
Notifications
You must be signed in to change notification settings - Fork 455
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
Attempted workaround for git worktree issue #965
Conversation
efce319
to
479eb72
Compare
It looks to me like this works for git ratchet. But it looks like it probably doesn't work for
|
Ah, we do set the line endings manually to UNIX (as a workaround for some other issue), so I guess that's why it was enough for us. The code in |
I'd love a PR which figures it out. But I'm also happy to merge this PR as-is if the changelog makes clear that git worktrees are fixed only for |
What it appears has happened is, So there's this static Repository createRepo(File dir) throws IOException {
return FileRepositoryBuilder.create(getDotGitDir(dir, Constants.DOT_GIT));
} But in FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.findGitDir(projectDir); which is using the library itself to find the git directory (I'm guessing that what So it might be that replacing this logic somehow with a call to Maybe we just move |
Sounds great! |
Working at it but it is a bit of a mess because |
OK, I did some investigation around JGit's static File getDotGitDir(File projectDir) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.findGitDir(projectDir);
return resolveRealGitDirIfWorktreeDir(builder.getGitDir());
} And then the workaround: static File resolveRealGitDirIfWorktreeDir(File dir) {
File pointerFile = new File(dir, "gitdir");
if (pointerFile.isFile()) {
try {
String content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim();
return new File(content);
} catch (IOException e) {
System.err.println("failed to parse git meta: " + e.getMessage());
return dir;
}
} else {
return dir;
}
} And that method is also what |
Unifies logic in `GitRatchet` and `GitAttributesLineEndings` for finding the `.git` directory, into a new `GitWorkarounds` class, so both of these can now have the same workaround code for dealing with JGit not supporting worktrees. The actual workaround works by using `FileRepositoryBuilder` to find what it thinks is the `.git` directory, and then looking inside that to see if it contains a file called `gitdir`, which indicates the location of the true `.git` directory in the case of a git worktree. For issue diffplug#75 or my issue diffplug#964
479eb72
to
ccbff37
Compare
Amazing! |
Published in |
Git supports using the same local repository for multiple checked-out worktrees. JGit does not fully support this, so we have to do some workarounds for it to work. The previous workaround provided by diffplug#965 did not take `commondir` into consideration, which is the location of a few files. More details are available at: https://git-scm.com/docs/git-worktree#_details
Git supports using the same local repository for multiple checked-out worktrees. JGit does not fully support this, so we have to do some workarounds for it to work. The previous workaround provided by diffplug#965 did not take `commondir` into consideration, which is the location of a few files.
Git supports using the same local repository for multiple checked-out worktrees. JGit does not fully support this, so we have to do some workarounds for it to work. The previous workaround provided by diffplug#965 did not take `commondir` into consideration, which is the location of a few files.
Git supports using the same local repository for multiple checked-out worktrees. JGit does not fully support this, so we have to do some workarounds for it to work. The previous workaround provided by diffplug#965 did not take `commondir` into consideration, which is the location of a few files.
Git supports using the same local repository for multiple checked-out worktrees. JGit does not fully support this, so we have to do some workarounds for it to work. The previous workaround provided by diffplug#965 did not take `commondir` into consideration, which is the location of a few files.
If the directory found as the git dir contains a file called
gitdir
, attempts to resolve it to find the actual git directory.(Not quite sure how to unit test because it's not like I can use JGit to create a worktree for the test given that it doesn't support the feature!)
For issue #75 or my issue #964