- All Implemented Interfaces:
AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The values for the config parameter submodule.<name>.ignore -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static boolean
containsGitModulesFile
(Repository repository) Checks whether the working tree contains a .gitmodules file.static SubmoduleWalk
forIndex
(Repository repository) Create a generator to walk over the submodule entries currently in the index The.gitmodules
file is read from the index.static SubmoduleWalk
forPath
(Repository repository, AnyObjectId treeId, String path) Create a generator and advance it to the submodule entry at the given pathstatic SubmoduleWalk
forPath
(Repository repository, AbstractTreeIterator iterator, String path) Create a generator and advance it to the submodule entry at the given pathGet the configured update field for current entry.Get the configured remote URL for current entry.Get directory that will be the root of the submodule's local repositorygetHead()
Get commit id that HEAD points to in the current submodule's repositoryGet ref that HEAD points to in the current submodule's repositoryThe module name for the current submodule entry (used for the section name of .git/config)Get the configured ignore field for the current entry.Get the configured path for current entry.Get the configured update field for current entry.Get the configured remote URL for current entry.Get object id of current submodule entrygetPath()
Get path of current submodule entryGet the resolved remote URL for the current submodule.Get repository for current submodule entrystatic File
getSubmoduleDirectory
(Repository parent, String path) Get submodule directorystatic String
getSubmoduleRemoteUrl
(Repository parent, String url) Resolve submodule repository URL.static Repository
getSubmoduleRepository
(File parent, String path) Get submodule repository at pathstatic Repository
getSubmoduleRepository
(File parent, String path, FS fs) Get submodule repository at path, using the specified file system abstractionstatic Repository
getSubmoduleRepository
(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 Repository
getSubmoduleRepository
(Repository parent, String path) Get submodule repositoryLoad the config for this walk from.gitmodules
.boolean
next()
Advance to next submodule in the index tree.reset()
Reset generator and start new submodule walkvoid
Sets theRepositoryBuilderFactory
to use for creating submodule repositories.setFilter
(TreeFilter filter) Set tree filtersetModulesConfig
(Config config) Set the config used by this walk.Set the tree used by this walk for finding.gitmodules
.Set the tree used by this walk for finding.gitmodules
.setTree
(AnyObjectId treeId) Set the tree used for finding submodule entriessetTree
(AbstractTreeIterator iterator) Set the tree iterator used for finding submodule entries
-
Constructor Details
-
SubmoduleWalk
Create submodule generator- Parameters:
repository
- theRepository
.- Throws:
IOException
- if an IO error occurred
-
-
Method Details
-
forIndex
Create a generator to walk over the submodule entries currently in the index The.gitmodules
file is read from the index.- Parameters:
repository
- aRepository
object.- Returns:
- generator over submodule index entries. The caller is responsible
for calling
close()
. - Throws:
IOException
- if an IO error occurred
-
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
- aRepository
object.treeId
- the root of a tree containing both a submodule at the given path and .gitmodules at the root.path
- aString
object.- Returns:
- generator at given path. The caller is responsible for calling
close()
. Null if no submodule at given path. - Throws:
IOException
- if an IO error occurred
-
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
- aRepository
object.iterator
- the root of a tree containing both a submodule at the given path and .gitmodules at the root.path
- aString
object.- Returns:
- generator at given path. The caller is responsible for calling
close()
. Null if no submodule at given path. - Throws:
IOException
- if an IO error occurred
-
getSubmoduleDirectory
Get submodule directory- Parameters:
parent
- theRepository
.path
- submodule path- Returns:
- directory
-
getSubmoduleRepository
Get submodule repository- Parameters:
parent
- theRepository
.path
- submodule path- Returns:
- repository or null if repository doesn't exist
- Throws:
IOException
- if an IO error occurred
-
getSubmoduleRepository
Get submodule repository at path- Parameters:
parent
- the parentpath
- submodule path- Returns:
- repository or null if repository doesn't exist
- Throws:
IOException
- if an IO error occurred
-
getSubmoduleRepository
Get submodule repository at path, using the specified file system abstraction- Parameters:
parent
-Repository
that contains the submodulepath
- of the working tree of the submodulefs
- the file system abstraction to be used- Returns:
- repository or null if repository doesn't exist
- Throws:
IOException
- if an IO error occurred- Since:
- 4.10
-
getSubmoduleRepository
public static Repository getSubmoduleRepository(File parent, String path, FS fs, BaseRepositoryBuilder<?, ? extends Repository> builder) throws IOExceptionGet submodule repository at path, using the specified file system abstraction and the specified builder- Parameters:
parent
-Repository
that contains the submodulepath
- of the working tree of the submodulefs
-FS
to usebuilder
-BaseRepositoryBuilder
to use to build the submodule repository- Returns:
- the
Repository
of the submodule, ornull
if it doesn't exist - Throws:
IOException
- if an IO error occurred- Since:
- 5.6
-
getSubmoduleRemoteUrl
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
- if an IO error occurred
-
setModulesConfig
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
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
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
- if an IO error occurred
-
loadModulesConfig
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
- if .gitmodules config is invalid
-
containsGitModulesFile
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 returnsfalse
for bare repositories.- Throws:
IOException
- if an IO error occurredCorruptObjectException
- if a corrupt object was found- Since:
- 3.6
-
setFilter
Set tree filter- Parameters:
filter
- aTreeFilter
object.- Returns:
- this generator
-
setTree
Set the tree iterator used for finding submodule entries- Parameters:
iterator
- anAbstractTreeIterator
object.- Returns:
- this generator
- Throws:
CorruptObjectException
- if a corrupt object was found
-
setTree
Set the tree used for finding submodule entries- Parameters:
treeId
- anAnyObjectId
object.- Returns:
- this generator
- Throws:
IOException
- if an IO error occurredIncorrectObjectTypeException
- if object has unexpected typeMissingObjectException
- if object is missing
-
reset
Reset generator and start new submodule walk- Returns:
- this generator
-
getDirectory
Get directory that will be the root of the submodule's local repository- Returns:
- submodule repository directory
-
next
Advance 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
- if an IO error occurred
-
getPath
Get path of current submodule entry- Returns:
- path
-
setBuilderFactory
Sets theRepositoryBuilderFactory
to use for creating submodule repositories. If none is set, a plainRepositoryBuilder
is used.- Parameters:
factory
- to set- Since:
- 5.6
-
getModuleName
The module name for the current submodule entry (used for the section name of .git/config)- Returns:
- name of the submodule
- Throws:
ConfigInvalidException
- if the .gitmodules config is invalidIOException
- if an IO error occurred- Since:
- 4.10
-
getObjectId
Get object id of current submodule entry- Returns:
- object id
-
getModulesPath
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:
ConfigInvalidException
- if .gitmodules config is invalidIOException
- if an IO error occurred
-
getConfigUrl
Get the configured remote URL for current entry. This will be the value from the repository's config.- Returns:
- configured URL
- Throws:
ConfigInvalidException
- if .gitmodules config is invalidIOException
- if an IO error occurred
-
getModulesUrl
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:
ConfigInvalidException
- if .gitmodules config is invalidIOException
- if an IO error occurred
-
getConfigUpdate
Get the configured update field for current entry. This will be the value from the repository's config.- Returns:
- update value
- Throws:
ConfigInvalidException
- if .gitmodules config is invalidIOException
- if an IO error occurred
-
getModulesUpdate
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:
ConfigInvalidException
- if .gitmodules config is invalidIOException
- if an IO error occurred
-
getModulesIgnore
public SubmoduleWalk.IgnoreSubmoduleMode getModulesIgnore() throws IOException, ConfigInvalidExceptionGet 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:
ConfigInvalidException
- if .gitmodules config is invalidIOException
- if an IO error occurred- Since:
- 3.6
-
getRepository
Get repository for current submodule entry- Returns:
- repository or null if non-existent
- Throws:
IOException
- if an IO error occurred
-
getHead
Get commit id that HEAD points to in the current submodule's repository- Returns:
- object id of HEAD reference
- Throws:
IOException
- if an IO error occurred
-
getHeadRef
Get ref that HEAD points to in the current submodule's repository- Returns:
- ref name, null on failures
- Throws:
IOException
- if an IO error occurred
-
getRemoteUrl
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:
IOException
- if an IO error occurredConfigInvalidException
- if .gitmodules config is invalid
-
close
public void close()Release any resources used by this walker's reader.
- Specified by:
close
in interfaceAutoCloseable
- Since:
- 4.0
-