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

No support for git submodules #200

Open
chris114782 opened this issue Mar 1, 2023 · 1 comment
Open

No support for git submodules #200

chris114782 opened this issue Mar 1, 2023 · 1 comment

Comments

@chris114782
Copy link

I'm trying to open a repository that is a submodule and it is failing as it expects .git to be a directory, not a reference to where the real .git directory is.

For a submodule, .git is a file containing gitdir: ./relative/path/to/real/.git/modules/path/to/submodule
Which is itself a standard .git directory.

Unfortunately if I attempt to reference it it considers the repository bare.

@chris114782
Copy link
Author

chris114782 commented Mar 1, 2023

In my limited testing, simply updating Repository::initDir to also accept $realGitDir . '/.git' as a file and then read the path of the gitdir out of that, and that seems to work but obviously I have not done anything beyond the most basic testing.

        if (false === $realGitDir) {
            throw new InvalidArgumentException(sprintf('Directory "%s" does not exist or is not a directory', $gitDir));
        } elseif (!is_dir($realGitDir)) {
            throw new InvalidArgumentException(sprintf('Directory "%s" does not exist or is not a directory', $realGitDir));
        } elseif (null === $workingDir && is_dir($realGitDir.'/.git')) {
            $workingDir = $realGitDir;
            $realGitDir = $realGitDir.'/.git';
        } elseif (null === $workingDir && file_exists($realGitDir.'/.git')) {
            $workingDir = $realGitDir;
            $gitFile = trim(file_get_contents($realGitDir . '/.git'));
            $parts = explode(':', $gitFile);
            if (trim($parts[0] ?? '') !== 'gitdir') {
                throw new InvalidArgumentException(sprintf('Directory "%s" has a .git file but is not a valid reference to a git directory', $realGitDir));
            }
            $realGitDir = realpath($realGitDir . DIRECTORY_SEPARATOR . trim($parts[1] ?? ''));
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant