Class SubmoduleWalk
- java.lang.Object
-
- org.eclipse.jgit.submodule.SubmoduleWalk
-
public class SubmoduleWalk extends java.lang.ObjectWalker 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 param submodule..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 static booleancontainsGitModulesFile(Repository repository)Checks whether the working tree (or the index in case of a bare repo) 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, java.lang.String path)Create a generator and advance it to the submodule entry at the given pathstatic SubmoduleWalkforPath(Repository repository, AbstractTreeIterator iterator, java.lang.String path)Create a generator and advance it to the submodule entry at the given pathjava.lang.StringgetConfigUpdate()Get the configured update field for current entry.java.lang.StringgetConfigUrl()Get the configured remote URL for current entry.java.io.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 repositoryjava.lang.StringgetHeadRef()Get ref that HEAD points to in the current submodule's repositorySubmoduleWalk.IgnoreSubmoduleModegetModulesIgnore()Get the configured ignore field for the current entry.java.lang.StringgetModulesPath()Get the configured path for current entry.java.lang.StringgetModulesUpdate()Get the configured update field for current entry.java.lang.StringgetModulesUrl()Get the configured remote URL for current entry.ObjectIdgetObjectId()Get object id of current submodule entryjava.lang.StringgetPath()Get path of current submodule entryjava.lang.StringgetRemoteUrl()Get the resolved remote URL for the current submodule.RepositorygetRepository()Get repository for current submodule entrystatic java.io.FilegetSubmoduleDirectory(Repository parent, java.lang.String path)Get submodule directorystatic java.lang.StringgetSubmoduleRemoteUrl(Repository parent, java.lang.String url)Resolve submodule repository URL.static RepositorygetSubmoduleRepository(java.io.File parent, java.lang.String path)Get submodule repository at pathstatic RepositorygetSubmoduleRepository(Repository parent, java.lang.String path)Get submodule repositorySubmoduleWalkloadModulesConfig()Load the config for this walk from.gitmodules.booleannext()Advance to next submodule in the index tree.voidrelease()Release any resources used by this walker's reader.SubmoduleWalkreset()Reset generator and start new submodule walkSubmoduleWalksetFilter(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 java.io.IOException
Create submodule generator- Parameters:
repository-- Throws:
java.io.IOException
-
-
Method Detail
-
forIndex
public static SubmoduleWalk forIndex(Repository repository) throws java.io.IOException
Create a generator to walk over the submodule entries currently in the index The.gitmodulesfile is read from the index.- Parameters:
repository-- Returns:
- generator over submodule index entries
- Throws:
java.io.IOException
-
forPath
public static SubmoduleWalk forPath(Repository repository, AnyObjectId treeId, java.lang.String path) throws java.io.IOException
Create a generator and advance it to the submodule entry at the given path- Parameters:
repository-treeId- the root of a tree containing both a submodule at the given path and .gitmodules at the root.path-- Returns:
- generator at given path, null if no submodule at given path
- Throws:
java.io.IOException
-
forPath
public static SubmoduleWalk forPath(Repository repository, AbstractTreeIterator iterator, java.lang.String path) throws java.io.IOException
Create a generator and advance it to the submodule entry at the given path- Parameters:
repository-iterator- the root of a tree containing both a submodule at the given path and .gitmodules at the root.path-- Returns:
- generator at given path, null if no submodule at given path
- Throws:
java.io.IOException
-
getSubmoduleDirectory
public static java.io.File getSubmoduleDirectory(Repository parent, java.lang.String path)
Get submodule directory- Parameters:
parent-path-- Returns:
- directory
-
getSubmoduleRepository
public static Repository getSubmoduleRepository(Repository parent, java.lang.String path) throws java.io.IOException
Get submodule repository- Parameters:
parent-path-- Returns:
- repository or null if repository doesn't exist
- Throws:
java.io.IOException
-
getSubmoduleRepository
public static Repository getSubmoduleRepository(java.io.File parent, java.lang.String path) throws java.io.IOException
Get submodule repository at path- Parameters:
parent-path-- Returns:
- repository or null if repository doesn't exist
- Throws:
java.io.IOException
-
getSubmoduleRemoteUrl
public static java.lang.String getSubmoduleRemoteUrl(Repository parent, java.lang.String url) throws java.io.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:
java.io.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 java.io.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:
java.io.IOException
-
loadModulesConfig
public SubmoduleWalk loadModulesConfig() throws java.io.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:
java.io.IOException- if an error occurred, or if the repository is bareConfigInvalidException
-
containsGitModulesFile
public static boolean containsGitModulesFile(Repository repository) throws java.io.IOException
Checks whether the working tree (or the index in case of a bare repo) contains a .gitmodules file. That's a hint that the repo contains submodules.- Parameters:
repository- the repository to check- Returns:
trueif the repo contains a .gitmodules file- Throws:
java.io.IOExceptionCorruptObjectException- Since:
- 3.6
-
setFilter
public SubmoduleWalk setFilter(TreeFilter filter)
Set tree filter- Parameters:
filter-- Returns:
- this generator
-
setTree
public SubmoduleWalk setTree(AbstractTreeIterator iterator) throws CorruptObjectException
Set the tree iterator used for finding submodule entries- Parameters:
iterator-- Returns:
- this generator
- Throws:
CorruptObjectException
-
setTree
public SubmoduleWalk setTree(AnyObjectId treeId) throws java.io.IOException
Set the tree used for finding submodule entries- Parameters:
treeId-- Returns:
- this generator
- Throws:
java.io.IOExceptionIncorrectObjectTypeExceptionMissingObjectException
-
reset
public SubmoduleWalk reset()
Reset generator and start new submodule walk- Returns:
- this generator
-
getDirectory
public java.io.File getDirectory()
Get directory that will be the root of the submodule's local repository- Returns:
- submodule repository directory
-
next
public boolean next() throws java.io.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:
java.io.IOException
-
getPath
public java.lang.String getPath()
Get path of current submodule entry- Returns:
- path
-
getObjectId
public ObjectId getObjectId()
Get object id of current submodule entry- Returns:
- object id
-
getModulesPath
public java.lang.String getModulesPath() throws java.io.IOException, ConfigInvalidExceptionGet 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:
ConfigInvalidExceptionjava.io.IOException
-
getConfigUrl
public java.lang.String getConfigUrl() throws java.io.IOException, ConfigInvalidExceptionGet the configured remote URL for current entry. This will be the value from the repository's config.- Returns:
- configured URL
- Throws:
ConfigInvalidExceptionjava.io.IOException
-
getModulesUrl
public java.lang.String getModulesUrl() throws java.io.IOException, ConfigInvalidExceptionGet 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:
ConfigInvalidExceptionjava.io.IOException
-
getConfigUpdate
public java.lang.String getConfigUpdate() throws java.io.IOException, ConfigInvalidExceptionGet the configured update field for current entry. This will be the value from the repository's config.- Returns:
- update value
- Throws:
ConfigInvalidExceptionjava.io.IOException
-
getModulesUpdate
public java.lang.String getModulesUpdate() throws java.io.IOException, ConfigInvalidExceptionGet 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:
ConfigInvalidExceptionjava.io.IOException
-
getModulesIgnore
public SubmoduleWalk.IgnoreSubmoduleMode getModulesIgnore() throws java.io.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:
ConfigInvalidExceptionjava.io.IOException- Since:
- 3.6
-
getRepository
public Repository getRepository() throws java.io.IOException
Get repository for current submodule entry- Returns:
- repository or null if non-existent
- Throws:
java.io.IOException
-
getHead
public ObjectId getHead() throws java.io.IOException
Get commit id that HEAD points to in the current submodule's repository- Returns:
- object id of HEAD reference
- Throws:
java.io.IOException
-
getHeadRef
public java.lang.String getHeadRef() throws java.io.IOExceptionGet ref that HEAD points to in the current submodule's repository- Returns:
- ref name, null on failures
- Throws:
java.io.IOException
-
getRemoteUrl
public java.lang.String getRemoteUrl() throws java.io.IOException, ConfigInvalidExceptionGet the resolved remote URL for the current submodule.This method resolves the value of
getModulesUrl()to an absolute URL- Returns:
- resolved remote URL
- Throws:
java.io.IOExceptionConfigInvalidException
-
release
public void release()
Release any resources used by this walker's reader.
-
-