Top Description Inners Fields Constructors Methods
org.eclipse.jgit.submodule

public Class SubmoduleWalk

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
java.io.File, .IOException, java.text.MessageFormat, java.util.HashMap, .Map, org.eclipse.jgit.dircache.DirCache, .DirCacheIterator, org.eclipse.jgit.errors.ConfigInvalidException, .CorruptObjectException, .IncorrectObjectTypeException, .MissingObjectException, .RepositoryNotFoundException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.AnyObjectId, .BaseRepositoryBuilder, .BlobBasedConfig, .Config, .ConfigConstants, .Constants, .FileMode, .ObjectId, .Ref, .Repository, .RepositoryBuilder, .RepositoryBuilderFactory, .StoredConfig, org.eclipse.jgit.storage.file.FileBasedConfig, org.eclipse.jgit.treewalk.AbstractTreeIterator, .CanonicalTreeParser, .TreeWalk, org.eclipse.jgit.treewalk.filter.PathFilter, .TreeFilter, org.eclipse.jgit.util.FS

Walker that visits all submodule entries found in a tree

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
SubmoduleWalk.IgnoreSubmoduleMode

The values for the config parameter submodule.

Field Summary

Modifier and TypeField and Description
private RepositoryBuilderFactory
private Config
private String
private Map<String, String>
private StoredConfig
private final Repository
private AbstractTreeIterator
private final TreeWalk

Constructor Summary

AccessConstructor and Description
public
SubmoduleWalk(Repository repository)

Create submodule generator

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public static boolean

Returns:

true if the working tree contains a .gitmodules file, false otherwise. Always returns false for bare repositories.
containsGitModulesFile
(Repository
the repository to check
repository
)

Checks whether the working tree contains a .gitmodules file.

public static SubmoduleWalk

Returns:

generator over submodule index entries. The caller is responsible for calling close().
forIndex
(Repository repository)

Create a generator to walk over the submodule entries currently in the index The .gitmodules file is read from the index.

public static SubmoduleWalk

Returns:

generator at given path. The caller is responsible for calling close(). Null if no submodule at given path.
forPath
(Repository repository, AnyObjectId
the root of a tree containing both a submodule at the given path and .gitmodules at the root.
treeId
,
String path)

Create a generator and advance it to the submodule entry at the given path

public static SubmoduleWalk

Returns:

generator at given path. The caller is responsible for calling close(). Null if no submodule at given path.
forPath
(Repository repository, AbstractTreeIterator
the root of a tree containing both a submodule at the given path and .gitmodules at the root.
iterator
,
String path)

Create a generator and advance it to the submodule entry at the given path

private BaseRepositoryBuilder<?, ? extends Repository>
public String

Returns:

update value
getConfigUpdate
()

Get the configured update field for current entry.

public String

Returns:

configured URL
getConfigUrl
()

Get the configured remote URL for current entry.

public File

Returns:

submodule repository directory
getDirectory
()

Get directory that will be the root of the submodule's local repository

public ObjectId

Returns:

object id of HEAD reference
getHead
()

Get commit id that HEAD points to in the current submodule's repository

public String

Returns:

ref name, null on failures
getHeadRef
()

Get ref that HEAD points to in the current submodule's repository

private String
getModuleName(String modulePath)

public String

Returns:

name of the submodule
getModuleName
()

The module name for the current submodule entry (used for the section name of .git/config)

public SubmoduleWalk.IgnoreSubmoduleMode

Returns:

ignore value
getModulesIgnore
()

Get the configured ignore field for the current entry.

public String

Returns:

configured path
getModulesPath
()

Get the configured path for current entry.

public String

Returns:

update value
getModulesUpdate
()

Get the configured update field for current entry.

public String

Returns:

configured URL
getModulesUrl
()

Get the configured remote URL for current entry.

public ObjectId

Returns:

object id
getObjectId
()

Get object id of current submodule entry

public String

Returns:

path
getPath
()

Get path of current submodule entry

public String

Returns:

resolved remote URL
getRemoteUrl
()

Get the resolved remote URL for the current submodule.

public Repository

Returns:

repository or null if non-existent
getRepository
()

Get repository for current submodule entry

public static File

Returns:

directory
getSubmoduleDirectory
(final Repository parent, final String
submodule path
path
)

Get submodule directory

public static String

Returns:

resolved URL
getSubmoduleRemoteUrl
(final Repository
parent repository
parent
,
final String
absolute or relative URL of the submodule repository
url
)

Resolve submodule repository URL.

public static Repository

Returns:

repository or null if repository doesn't exist
getSubmoduleRepository
(final Repository parent, final String
submodule path
path
)

Get submodule repository

public static Repository

Returns:

repository or null if repository doesn't exist
getSubmoduleRepository
(final File
the parent
parent
,
final String
submodule path
path
)

Get submodule repository at path

public static Repository

Returns:

repository or null if repository doesn't exist
getSubmoduleRepository
(final File
Repository that contains the submodule
parent
,
final String
of the working tree of the submodule
path
,
FS
the file system abstraction to be used
fs
)

Get submodule repository at path, using the specified file system abstraction

public static Repository

Returns:

the Repository of the submodule, or null if it doesn't exist
getSubmoduleRepository
(File
Repository that contains the submodule
parent
,
String
of the working tree of the submodule
path
,
FS
FS to use
fs
,
BaseRepositoryBuilder<?, ? extends Repository>
BaseRepositoryBuilder to use to build the submodule repository
builder
)

Get submodule repository at path, using the specified file system abstraction and the specified builder

private void
public SubmoduleWalk

Returns:

this generator
loadModulesConfig
()

Load the config for this walk from .gitmodules.

private void
public boolean

Returns:

true if entry found, false otherwise
next
()

Advance to next submodule in the index tree.

public SubmoduleWalk

Returns:

this generator
reset
()

Reset generator and start new submodule walk

public void
setBuilderFactory(RepositoryBuilderFactory
to set
factory
)

Sets the RepositoryBuilderFactory to use for creating submodule repositories.

public SubmoduleWalk

Returns:

this generator
setFilter
(TreeFilter filter)

Set tree filter

public SubmoduleWalk

Returns:

this generator
setModulesConfig
(Config
.gitmodules config object
config
)

Set the config used by this walk.

public SubmoduleWalk

Returns:

this generator
setRootTree
(AbstractTreeIterator
tree containing .gitmodules
tree
)

Set the tree used by this walk for finding .gitmodules.

public SubmoduleWalk

Returns:

this generator
setRootTree
(AnyObjectId
ID of a tree containing .gitmodules
id
)

Set the tree used by this walk for finding .gitmodules.

public SubmoduleWalk

Returns:

this generator
setTree
(AbstractTreeIterator iterator)

Set the tree iterator used for finding submodule entries

public SubmoduleWalk

Returns:

this generator
setTree
(AnyObjectId treeId)

Set the tree used for finding submodule entries

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

factoryback to summary
private RepositoryBuilderFactory factory
modulesConfigback to summary
private Config modulesConfig
pathback to summary
private String path
pathToNameback to summary
private Map<String, String> pathToName
repoConfigback to summary
private StoredConfig repoConfig
repositoryback to summary
private final Repository repository
rootTreeback to summary
private AbstractTreeIterator rootTree
walkback to summary
private final TreeWalk walk

Constructor Detail

SubmoduleWalkback to summary
public SubmoduleWalk(Repository repository) throws IOException

Create submodule generator

Parameters
repository:Repository

the org.eclipse.jgit.lib.Repository.

Exceptions
IOException:
if an IO error occurred

Method Detail

closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Release any resources used by this walker's reader.

Annotations
@Override
Since
4.0
containsGitModulesFileback to summary
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:Repository

the repository to check

Returns:boolean

true if the working tree contains a .gitmodules file, false otherwise. Always returns false for bare repositories.

Exceptions
IOException:
if an IO error occurred
CorruptObjectException:
if a corrupt object was found
Since
3.6
forIndexback to summary
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:Repository

a org.eclipse.jgit.lib.Repository object.

Returns:SubmoduleWalk

generator over submodule index entries. The caller is responsible for calling close().

Exceptions
IOException:
if an IO error occurred
forPathback to summary
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:Repository

a org.eclipse.jgit.lib.Repository object.

treeId:AnyObjectId

the root of a tree containing both a submodule at the given path and .gitmodules at the root.

path:String

a java.lang.String object.

Returns:SubmoduleWalk

generator at given path. The caller is responsible for calling close(). Null if no submodule at given path.

Exceptions
IOException:
if an IO error occurred
forPathback to summary
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:Repository

a org.eclipse.jgit.lib.Repository object.

iterator:AbstractTreeIterator

the root of a tree containing both a submodule at the given path and .gitmodules at the root.

path:String

a java.lang.String object.

Returns:SubmoduleWalk

generator at given path. The caller is responsible for calling close(). Null if no submodule at given path.

Exceptions
IOException:
if an IO error occurred
getBuilderback to summary
private BaseRepositoryBuilder<?, ? extends Repository> getBuilder()
getConfigUpdateback to summary
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:String

update value

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if .gitmodules config is invalid
getConfigUrlback to summary
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:String

configured URL

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if .gitmodules config is invalid
getDirectoryback to summary
public File getDirectory()

Get directory that will be the root of the submodule's local repository

Returns:File

submodule repository directory

getHeadback to summary
public ObjectId getHead() throws IOException

Get commit id that HEAD points to in the current submodule's repository

Returns:ObjectId

object id of HEAD reference

Exceptions
IOException:
if an IO error occurred
getHeadRefback to summary
public String getHeadRef() throws IOException

Get ref that HEAD points to in the current submodule's repository

Returns:String

ref name, null on failures

Exceptions
IOException:
if an IO error occurred
getModuleNameback to summary
private String getModuleName(String modulePath)
getModuleNameback to summary
public String getModuleName() throws IOException, ConfigInvalidException

The module name for the current submodule entry (used for the section name of .git/config)

Returns:String

name of the submodule

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if the .gitmodules config is invalid
Since
4.10
getModulesIgnoreback to summary
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:SubmoduleWalk.IgnoreSubmoduleMode

ignore value

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if .gitmodules config is invalid
Since
3.6
getModulesPathback to summary
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:String

configured path

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if .gitmodules config is invalid
getModulesUpdateback to summary
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:String

update value

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if .gitmodules config is invalid
getModulesUrlback to summary
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:String

configured URL

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if .gitmodules config is invalid
getObjectIdback to summary
public ObjectId getObjectId()

Get object id of current submodule entry

Returns:ObjectId

object id

getPathback to summary
public String getPath()

Get path of current submodule entry

Returns:String

path

getRemoteUrlback to summary
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:String

resolved remote URL

Exceptions
IOException:
if an IO error occurred
ConfigInvalidException:
if .gitmodules config is invalid
getRepositoryback to summary
public Repository getRepository() throws IOException

Get repository for current submodule entry

Returns:Repository

repository or null if non-existent

Exceptions
IOException:
if an IO error occurred
getSubmoduleDirectoryback to summary
public static File getSubmoduleDirectory(final Repository parent, final String path)

Get submodule directory

Parameters
parent:Repository

the org.eclipse.jgit.lib.Repository.

path:String

submodule path

Returns:File

directory

getSubmoduleRemoteUrlback to summary
public static String getSubmoduleRemoteUrl(final Repository parent, final 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:Repository

parent repository

url:String

absolute or relative URL of the submodule repository

Returns:String

resolved URL

Exceptions
IOException:
if an IO error occurred
getSubmoduleRepositoryback to summary
public static Repository getSubmoduleRepository(final Repository parent, final String path) throws IOException

Get submodule repository

Parameters
parent:Repository

the org.eclipse.jgit.lib.Repository.

path:String

submodule path

Returns:Repository

repository or null if repository doesn't exist

Exceptions
IOException:
if an IO error occurred
getSubmoduleRepositoryback to summary
public static Repository getSubmoduleRepository(final File parent, final String path) throws IOException

Get submodule repository at path

Parameters
parent:File

the parent

path:String

submodule path

Returns:Repository

repository or null if repository doesn't exist

Exceptions
IOException:
if an IO error occurred
getSubmoduleRepositoryback to summary
public static Repository getSubmoduleRepository(final File parent, final String path, FS fs) throws IOException

Get submodule repository at path, using the specified file system abstraction

Parameters
parent:File

Repository that contains the submodule

path:String

of the working tree of the submodule

fs:FS

the file system abstraction to be used

Returns:Repository

repository or null if repository doesn't exist

Exceptions
IOException:
if an IO error occurred
Since
4.10
getSubmoduleRepositoryback to summary
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:File

Repository that contains the submodule

path:String

of the working tree of the submodule

fs:FS

FS to use

builder:BaseRepositoryBuilder<?, ? extends Repository>

BaseRepositoryBuilder to use to build the submodule repository

Returns:Repository

the Repository of the submodule, or null if it doesn't exist

Exceptions
IOException:
if an IO error occurred
Since
5.6
lazyLoadModulesConfigback to summary
private void lazyLoadModulesConfig() throws IOException, ConfigInvalidException
loadModulesConfigback to summary
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:SubmoduleWalk

this generator

Exceptions
IOException:
if an error occurred, or if the repository is bare
ConfigInvalidException:
if .gitmodules config is invalid
loadPathNamesback to summary
private void loadPathNames()
nextback to summary
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:boolean

true if entry found, false otherwise

Exceptions
IOException:
if an IO error occurred
resetback to summary
public SubmoduleWalk reset()

Reset generator and start new submodule walk

Returns:SubmoduleWalk

this generator

setBuilderFactoryback to summary
public void setBuilderFactory(RepositoryBuilderFactory factory)

Sets the RepositoryBuilderFactory to use for creating submodule repositories. If none is set, a plain RepositoryBuilder is used.

Parameters
factory:RepositoryBuilderFactory

to set

Since
5.6
setFilterback to summary
public SubmoduleWalk setFilter(TreeFilter filter)

Set tree filter

Parameters
filter:TreeFilter

a org.eclipse.jgit.treewalk.filter.TreeFilter object.

Returns:SubmoduleWalk

this generator

setModulesConfigback to summary
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:Config

.gitmodules config object

Returns:SubmoduleWalk

this generator

setRootTreeback to summary
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:AbstractTreeIterator

tree containing .gitmodules

Returns:SubmoduleWalk

this generator

setRootTreeback to summary
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:AnyObjectId

ID of a tree containing .gitmodules

Returns:SubmoduleWalk

this generator

Exceptions
IOException:
if an IO error occurred
setTreeback to summary
public SubmoduleWalk setTree(AbstractTreeIterator iterator) throws CorruptObjectException

Set the tree iterator used for finding submodule entries

Parameters
iterator:AbstractTreeIterator

an org.eclipse.jgit.treewalk.AbstractTreeIterator object.

Returns:SubmoduleWalk

this generator

Exceptions
CorruptObjectException:
if a corrupt object was found
setTreeback to summary
public SubmoduleWalk setTree(AnyObjectId treeId) throws IOException

Set the tree used for finding submodule entries

Parameters
treeId:AnyObjectId

an org.eclipse.jgit.lib.AnyObjectId object.

Returns:SubmoduleWalk

this generator

Exceptions
IOException:
if an IO error occurred
IncorrectObjectTypeException:
if object has unexpected type
MissingObjectException:
if object is missing
org.eclipse.jgit.submodule back to summary

public final Enum SubmoduleWalk.IgnoreSubmoduleMode

extends Enum<SubmoduleWalk.IgnoreSubmoduleMode>
Class Inheritance

The values for the config parameter submodule.<name>.ignore
Since
3.6

Field Summary

Modifier and TypeField and Description
public static final SubmoduleWalk.IgnoreSubmoduleMode
ALL

Ignore all modifications to submodules

public static final SubmoduleWalk.IgnoreSubmoduleMode
DIRTY

Ignore changes to the working tree of a submodule

public static final SubmoduleWalk.IgnoreSubmoduleMode
NONE

Ignore nothing.

public static final SubmoduleWalk.IgnoreSubmoduleMode
UNTRACKED

Ignore changes to untracked files in the working tree of a submodule

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SubmoduleWalk.IgnoreSubmoduleMode
public static SubmoduleWalk.IgnoreSubmoduleMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALLback to summary
public static final SubmoduleWalk.IgnoreSubmoduleMode ALL

Ignore all modifications to submodules

DIRTYback to summary
public static final SubmoduleWalk.IgnoreSubmoduleMode DIRTY

Ignore changes to the working tree of a submodule

NONEback to summary
public static final SubmoduleWalk.IgnoreSubmoduleMode NONE

Ignore nothing. That's the default

UNTRACKEDback to summary
public static final SubmoduleWalk.IgnoreSubmoduleMode UNTRACKED

Ignore changes to untracked files in the working tree of a submodule

Constructor Detail

IgnoreSubmoduleModeback to summary
private IgnoreSubmoduleMode()

Method Detail

valueOfback to summary
public static SubmoduleWalk.IgnoreSubmoduleMode valueOf(String name)
valuesback to summary
public static SubmoduleWalk.IgnoreSubmoduleMode[] values()