Skip to content

No support for git submodules #200

Closed

Description

@chris114782

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.

Activity

  1. chris114782 commented on Mar 1, 2023

    @chris114782
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions