Class SubmoduleWalk

  • All Implemented Interfaces:
    AutoCloseable

    public class SubmoduleWalk
    extends Object
    implements AutoCloseable
    Walker that visits all submodule entries found in a tree
    • Method Detail

      • forIndex

        public static SubmoduleWalk forIndex​(Repository repository)
                                      throws IOException
        Create a generator to walk over the submodule entries currently in the index The .gitmodules file is read from the index.
        Parameters:
        repository - a Repository object.
        Returns:
        generator over submodule index entries. The caller is responsible for calling close().
        Throws:
        IOException
      • forPath

        public static SubmoduleWalk forPath​(Repository repository,
                                            AnyObjectId treeId,
                                            String path)
                                     throws IOException
        Create a generator and advance it to the submodule entry at the given path
        Parameters:
        repository - a Repository object.
        treeId - the root of a tree containing both a submodule at the given path and .gitmodules at the root.
        path - a String object.
        Returns:
        generator at given path. The caller is responsible for calling close(). Null if no submodule at given path.
        Throws:
        IOException
      • forPath

        public static SubmoduleWalk forPath​(Repository repository,
                                            AbstractTreeIterator iterator,
                                            String path)
                                     throws IOException
        Create a generator and advance it to the submodule entry at the given path
        Parameters:
        repository - a Repository object.
        iterator - the root of a tree containing both a submodule at the given path and .gitmodules at the root.
        path - a String object.
        Returns:
        generator at given path. The caller is responsible for calling close(). Null if no submodule at given path.
        Throws:
        IOException
      • getSubmoduleDirectory

        public static File getSubmoduleDirectory​(Repository parent,
                                                 String path)
        Get submodule directory
        Parameters:
        parent - the Repository.
        path - submodule path
        Returns:
        directory
      • getSubmoduleRepository

        public static Repository getSubmoduleRepository​(Repository parent,
                                                        String path)
                                                 throws IOException
        Get submodule repository
        Parameters:
        parent - the Repository.
        path - submodule path
        Returns:
        repository or null if repository doesn't exist
        Throws:
        IOException
      • getSubmoduleRepository

        public static Repository getSubmoduleRepository​(File parent,
                                                        String path)
                                                 throws IOException
        Get submodule repository at path
        Parameters:
        parent - the parent
        path - submodule path
        Returns:
        repository or null if repository doesn't exist
        Throws:
        IOException
      • getSubmoduleRepository

        public static Repository getSubmoduleRepository​(File parent,
                                                        String path,
                                                        FS fs)
                                                 throws IOException
        Get submodule repository at path, using the specified file system abstraction
        Parameters:
        parent -
        path -
        fs - the file system abstraction to be used
        Returns:
        repository or null if repository doesn't exist
        Throws:
        IOException
        Since:
        4.10
      • getSubmoduleRepository

        public static Repository getSubmoduleRepository​(File parent,
                                                        String path,
                                                        FS fs,
                                                        BaseRepositoryBuilder<?,​? extends Repository> builder)
                                                 throws IOException
        Get submodule repository at path, using the specified file system abstraction and the specified builder
        Parameters:
        parent - Repository that contains the submodule
        path - of the working tree of the submodule
        fs - FS to use
        builder - BaseRepositoryBuilder to use to build the submodule repository
        Returns:
        the Repository of the submodule, or null if it doesn't exist
        Throws:
        IOException - on errors
        Since:
        5.6
      • getSubmoduleRemoteUrl

        public static String getSubmoduleRemoteUrl​(Repository parent,
                                                   String url)
                                            throws IOException
        Resolve submodule repository URL.

        This handles relative URLs that are typically specified in the '.gitmodules' file by resolving them against the remote URL of the parent repository.

        Relative URLs will be resolved against the parent repository's working directory if the parent repository has no configured remote URL.

        Parameters:
        parent - parent repository
        url - absolute or relative URL of the submodule repository
        Returns:
        resolved URL
        Throws:
        IOException
      • setModulesConfig

        public SubmoduleWalk setModulesConfig​(Config config)
        Set the config used by this walk. This method need only be called if constructing a walk manually instead of with one of the static factory methods above.
        Parameters:
        config - .gitmodules config object
        Returns:
        this generator
      • setRootTree

        public SubmoduleWalk setRootTree​(AbstractTreeIterator tree)
        Set the tree used by this walk for finding .gitmodules.

        The root tree is not read until the first submodule is encountered by the walk.

        This method need only be called if constructing a walk manually instead of with one of the static factory methods above.

        Parameters:
        tree - tree containing .gitmodules
        Returns:
        this generator
      • setRootTree

        public SubmoduleWalk setRootTree​(AnyObjectId id)
                                  throws IOException
        Set the tree used by this walk for finding .gitmodules.

        The root tree is not read until the first submodule is encountered by the walk.

        This method need only be called if constructing a walk manually instead of with one of the static factory methods above.

        Parameters:
        id - ID of a tree containing .gitmodules
        Returns:
        this generator
        Throws:
        IOException
      • containsGitModulesFile

        public static boolean containsGitModulesFile​(Repository repository)
                                              throws IOException
        Checks whether the working tree contains a .gitmodules file. That's a hint that the repo contains submodules.
        Parameters:
        repository - the repository to check
        Returns:
        true if the working tree contains a .gitmodules file, false otherwise. Always returns false for bare repositories.
        Throws:
        IOException
        CorruptObjectException - if any.
        Since:
        3.6
      • reset

        public SubmoduleWalk reset()
        Reset generator and start new submodule walk
        Returns:
        this generator
      • getDirectory

        public File getDirectory()
        Get directory that will be the root of the submodule's local repository
        Returns:
        submodule repository directory
      • next

        public boolean next()
                     throws IOException
        Advance to next submodule in the index tree. The object id and path of the next entry can be obtained by calling getObjectId() and getPath().
        Returns:
        true if entry found, false otherwise
        Throws:
        IOException
      • getPath

        public String getPath()
        Get path of current submodule entry
        Returns:
        path
      • getObjectId

        public ObjectId getObjectId()
        Get object id of current submodule entry
        Returns:
        object id
      • getRepository

        public Repository getRepository()
                                 throws IOException
        Get repository for current submodule entry
        Returns:
        repository or null if non-existent
        Throws:
        IOException
      • getHead

        public ObjectId getHead()
                         throws IOException
        Get commit id that HEAD points to in the current submodule's repository
        Returns:
        object id of HEAD reference
        Throws:
        IOException
      • getHeadRef

        public String getHeadRef()
                          throws IOException
        Get ref that HEAD points to in the current submodule's repository
        Returns:
        ref name, null on failures
        Throws:
        IOException
      • close

        public void close()

        Release any resources used by this walker's reader.

        Specified by:
        close in interface AutoCloseable
        Since:
        4.0