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

Git root dir does not work for worktrees #564

Open
blakehurlburt opened this issue Feb 11, 2022 · 3 comments
Open

Git root dir does not work for worktrees #564

blakehurlburt opened this issue Feb 11, 2022 · 3 comments
Labels

Comments

@blakehurlburt
Copy link

When using a worktree, gradle tasks run into the following error:

java.nio.file.FileSystemException: <worktree directory>/.git/config: Not a directory
        at com.palantir.gradle.gitversion.GitVersionPlugin.gitRepo(GitVersionPlugin.java:73)
        at com.palantir.gradle.gitversion.GitVersionPlugin.apply(GitVersionPlugin.java:36)
        at com.palantir.gradle.gitversion.GitVersionPlugin.apply(GitVersionPlugin.java:29)

Similar for

java.nio.file.FileSystemException: <worktree directory>/.git/refs/HEAD: Not a directory
        at com.palantir.gradle.gitversion.VersionDetailsImpl.isRepoEmpty(VersionDetailsImpl.java:102)
        at com.palantir.gradle.gitversion.VersionDetailsImpl.expensiveComputeRawDescription(VersionDetailsImpl.java:74)
        at com.palantir.gradle.gitversion.VersionDetailsImpl.description(VersionDetailsImpl.java:67)
        at com.palantir.gradle.gitversion.VersionDetailsImpl.getVersion(VersionDetailsImpl.java:47)

        at com.palantir.gradle.gitversion.VersionDetailsImpl.isRepoEmpty(VersionDetailsImpl.java:102)
        at com.palantir.gradle.gitversion.VersionDetailsImpl.expensiveComputeRawDescription(VersionDetailsImpl.java:74)
        at com.palantir.gradle.gitversion.VersionDetailsImpl.description(VersionDetailsImpl.java:67)
        at com.palantir.gradle.gitversion.VersionDetailsImpl.getVersion(VersionDetailsImpl.java:47)

private static File scanForRootGitDir(File currentRoot) {
File gitDir = new File(currentRoot, ".git");
if (gitDir.exists()) {
return gitDir;
}
// stop at the root directory, return non-existing File object;
if (currentRoot.getParentFile() == null) {
return gitDir;
}
// look in parent directory;
return scanForRootGitDir(currentRoot.getParentFile());
}

This seems to assume the .git file in the repo is always a git dir, which is not true for worktrees.

The correct solution is to use the command git rev-parse --git-dir for the worktree-specific git dir, and git rev-parse --git-common-dir for the shared git dir for all worktrees in the checkout.

@drgeb
Copy link

drgeb commented Mar 2, 2022

I am observing the same issue! Is there a workaround for this ?

@vokiel-too
Copy link

vokiel-too commented Mar 21, 2022

This exact issue happens using git submodules: https://git-scm.com/book/en/v2/Git-Tools-Submodules

I imagine it's related to worktrees as well having .git files with references to the parent .git folder. I was having a hard time with the difference in naming.

@puchengy
Copy link

puchengy commented Feb 3, 2023

I am also seeing the issue! Could you fix the issue? Thanks!

@CRogers CRogers mentioned this issue Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants