Class SubmoduleWalk
- java.lang.Object
-
- org.eclipse.jgit.submodule.SubmoduleWalk
-
- All Implemented Interfaces:
AutoCloseable
public class SubmoduleWalk extends Object implements AutoCloseable
Walker that visits all submodule entries found in a tree
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSubmoduleWalk.IgnoreSubmoduleModeThe values for the config parameter submodule.<name>.ignore
-
Constructor Summary
Constructors Constructor Description SubmoduleWalk(Repository repository)Create submodule generator
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static booleancontainsGitModulesFile(Repository repository)Checks whether the working tree contains a .gitmodules file.static SubmoduleWalkforIndex(Repository repository)Create a generator to walk over the submodule entries currently in the index The.gitmodulesfile is read from the index.static SubmoduleWalkforPath(Repository repository, AnyObjectId treeId, String path)Create a generator and advance it to the submodule entry at the given pathstatic SubmoduleWalkforPath(Repository repository, AbstractTreeIterator iterator, String path)Create a generator and advance it to the submodule entry at the given pathStringgetConfigUpdate()Get the configured update field for current entry.StringgetConfigUrl()Get the configured remote URL for current entry.FilegetDirectory()Get directory that will be the root of the submodule's local repositoryObjectIdgetHead()Get commit id that HEAD points to in the current submodule's repositoryStringgetHeadRef()Get ref that HEAD points to in the current submodule's repositoryStringgetModuleName()The module name for the current submodule entry (used for the section name of .git/config)SubmoduleWalk.IgnoreSubmoduleModegetModulesIgnore()Get the configured ignore field for the current entry.StringgetModulesPath()Get the configured path for current entry.StringgetModulesUpdate()Get the configured update field for current entry.StringgetModulesUrl()Get the configured remote URL for current entry.ObjectIdgetObjectId()Get object id of current submodule entryStringgetPath()Get path of current submodule entryStringgetRemoteUrl()Get the resolved remote URL for the current submodule.RepositorygetRepository()Get repository for current submodule entrystatic FilegetSubmoduleDirectory(Repository parent, String path)Get submodule directorystatic StringgetSubmoduleRemoteUrl(Repository parent, String url)Resolve submodule repository URL.static RepositorygetSubmoduleRepository(File parent, String path)Get submodule repository at pathstatic RepositorygetSubmoduleRepository(File parent, String path, FS fs)Get submodule repository at path, using the specified file system abstractionstatic RepositorygetSubmoduleRepository(File parent, String path, FS fs, BaseRepositoryBuilder<?,? extends Repository> builder)Get submodule repository at path, using the specified file system abstraction and the specified builderstatic RepositorygetSubmoduleRepository(Repository parent, String path)Get submodule repositorySubmoduleWalkloadModulesConfig()Load the config for this walk from.gitmodules.booleannext()Advance to next submodule in the index tree.SubmoduleWalkreset()Reset generator and start new submodule walkvoidsetBuilderFactory(RepositoryBuilderFactory factory)Sets theRepositoryBuilderFactoryto use for creating submodule repositories.SubmoduleWalksetFilter(TreeFilter filter)Set tree filterSubmoduleWalksetModulesConfig(Config config)Set the config used by this walk.SubmoduleWalksetRootTree(AnyObjectId id)Set the tree used by this walk for finding.gitmodules.SubmoduleWalksetRootTree(AbstractTreeIterator tree)Set the tree used by this walk for finding.gitmodules.SubmoduleWalksetTree(AnyObjectId treeId)Set the tree used for finding submodule entriesSubmoduleWalksetTree(AbstractTreeIterator iterator)Set the tree iterator used for finding submodule entries
-
-
-
Constructor Detail
-
SubmoduleWalk
public SubmoduleWalk(Repository repository) throws IOException
Create submodule generator- Parameters:
repository- theRepository.- Throws:
IOException
-
-
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.gitmodulesfile is read from the index.- Parameters:
repository- aRepositoryobject.- 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- aRepositoryobject.treeId- the root of a tree containing both a submodule at the given path and .gitmodules at the root.path- aStringobject.- 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- aRepositoryobject.iterator- the root of a tree containing both a submodule at the given path and .gitmodules at the root.path- aStringobject.- 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- theRepository.path- submodule path- Returns:
- directory
-
getSubmoduleRepository
public static Repository getSubmoduleRepository(Repository parent, String path) throws IOException
Get submodule repository- Parameters:
parent- theRepository.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 parentpath- 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-Repositorythat contains the submodulepath- of the working tree of the submodulefs-FSto usebuilder-BaseRepositoryBuilderto use to build the submodule repository- Returns:
- the
Repositoryof the submodule, ornullif 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 repositoryurl- 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
-
loadModulesConfig
public SubmoduleWalk loadModulesConfig() throws IOException, ConfigInvalidException
Load the config for this walk from.gitmodules.Uses the root tree if
setRootTree(AbstractTreeIterator)was previously called, otherwise uses the working tree.If no submodule config is found, loads an empty config.
- Returns:
- this generator
- Throws:
IOException- if an error occurred, or if the repository is bareConfigInvalidException
-
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:
trueif the working tree contains a .gitmodules file,falseotherwise. Always returnsfalsefor bare repositories.- Throws:
IOExceptionCorruptObjectException- if any.- Since:
- 3.6
-
setFilter
public SubmoduleWalk setFilter(TreeFilter filter)
Set tree filter- Parameters:
filter- aTreeFilterobject.- Returns:
- this generator
-
setTree
public SubmoduleWalk setTree(AbstractTreeIterator iterator) throws CorruptObjectException
Set the tree iterator used for finding submodule entries- Parameters:
iterator- anAbstractTreeIteratorobject.- Returns:
- this generator
- Throws:
CorruptObjectException
-
setTree
public SubmoduleWalk setTree(AnyObjectId treeId) throws IOException
Set the tree used for finding submodule entries- Parameters:
treeId- anAnyObjectIdobject.- Returns:
- this generator
- Throws:
IOExceptionIncorrectObjectTypeException- if any.MissingObjectException- if any.
-
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 IOExceptionAdvance to next submodule in the index tree. The object id and path of the next entry can be obtained by callinggetObjectId()andgetPath().- Returns:
- true if entry found, false otherwise
- Throws:
IOException
-
getPath
public String getPath()
Get path of current submodule entry- Returns:
- path
-
setBuilderFactory
public void setBuilderFactory(RepositoryBuilderFactory factory)
Sets theRepositoryBuilderFactoryto use for creating submodule repositories. If none is set, a plainRepositoryBuilderis used.- Parameters:
factory- to set- Since:
- 5.6
-
getModuleName
public String getModuleName() throws IOException, ConfigInvalidException
The module name for the current submodule entry (used for the section name of .git/config)- Returns:
- name
- Throws:
ConfigInvalidExceptionIOException- Since:
- 4.10
-
getObjectId
public ObjectId getObjectId()
Get object id of current submodule entry- Returns:
- object id
-
getModulesPath
public String getModulesPath() throws IOException, ConfigInvalidException
Get the configured path for current entry. This will be the value from the .gitmodules file in the current repository's working tree.- Returns:
- configured path
- Throws:
ConfigInvalidExceptionIOException
-
getConfigUrl
public String getConfigUrl() throws IOException, ConfigInvalidException
Get the configured remote URL for current entry. This will be the value from the repository's config.- Returns:
- configured URL
- Throws:
ConfigInvalidExceptionIOException
-
getModulesUrl
public String getModulesUrl() throws IOException, ConfigInvalidException
Get the configured remote URL for current entry. This will be the value from the .gitmodules file in the current repository's working tree.- Returns:
- configured URL
- Throws:
ConfigInvalidExceptionIOException
-
getConfigUpdate
public String getConfigUpdate() throws IOException, ConfigInvalidException
Get the configured update field for current entry. This will be the value from the repository's config.- Returns:
- update value
- Throws:
ConfigInvalidExceptionIOException
-
getModulesUpdate
public String getModulesUpdate() throws IOException, ConfigInvalidException
Get the configured update field for current entry. This will be the value from the .gitmodules file in the current repository's working tree.- Returns:
- update value
- Throws:
ConfigInvalidExceptionIOException
-
getModulesIgnore
public SubmoduleWalk.IgnoreSubmoduleMode getModulesIgnore() throws IOException, ConfigInvalidException
Get the configured ignore field for the current entry. This will be the value from the .gitmodules file in the current repository's working tree.- Returns:
- ignore value
- Throws:
ConfigInvalidExceptionIOException- Since:
- 3.6
-
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
-
getRemoteUrl
public String getRemoteUrl() throws IOException, ConfigInvalidException
Get the resolved remote URL for the current submodule.This method resolves the value of
getModulesUrl()to an absolute URL- Returns:
- resolved remote URL
- Throws:
IOExceptionConfigInvalidException
-
close
public void close()
Release any resources used by this walker's reader.
- Specified by:
closein interfaceAutoCloseable- Since:
- 4.0
-
-