public class SubmoduleWalk
extends java.lang.Object
implements java.lang.AutoCloseable
Modifier and Type | Class and Description |
---|---|
static class |
SubmoduleWalk.IgnoreSubmoduleMode
The values for the config parameter submodule.<name>.ignore
|
Modifier and Type | Field and Description |
---|---|
private Config |
modulesConfig |
private java.lang.String |
path |
private java.util.Map<java.lang.String,java.lang.String> |
pathToName |
private StoredConfig |
repoConfig |
private Repository |
repository |
private AbstractTreeIterator |
rootTree |
private TreeWalk |
walk |
Constructor and Description |
---|
SubmoduleWalk(Repository repository)
Create submodule generator
|
Modifier and Type | Method and Description |
---|---|
void |
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,
AbstractTreeIterator iterator,
java.lang.String path)
Create a generator and advance it to the submodule entry at the given
path
|
static SubmoduleWalk |
forPath(Repository repository,
AnyObjectId treeId,
java.lang.String path)
Create a generator and advance it to the submodule entry at the given
path
|
java.lang.String |
getConfigUpdate()
Get the configured update field for current entry.
|
java.lang.String |
getConfigUrl()
Get the configured remote URL for current entry.
|
java.io.File |
getDirectory()
Get directory that will be the root of the submodule's local repository
|
ObjectId |
getHead()
Get commit id that HEAD points to in the current submodule's repository
|
java.lang.String |
getHeadRef()
Get ref that HEAD points to in the current submodule's repository
|
java.lang.String |
getModuleName()
The module name for the current submodule entry (used for the section name of .git/config)
|
private java.lang.String |
getModuleName(java.lang.String modulePath) |
SubmoduleWalk.IgnoreSubmoduleMode |
getModulesIgnore()
Get the configured ignore field for the current entry.
|
java.lang.String |
getModulesPath()
Get the configured path for current entry.
|
java.lang.String |
getModulesUpdate()
Get the configured update field for current entry.
|
java.lang.String |
getModulesUrl()
Get the configured remote URL for current entry.
|
ObjectId |
getObjectId()
Get object id of current submodule entry
|
java.lang.String |
getPath()
Get path of current submodule entry
|
java.lang.String |
getRemoteUrl()
Get the resolved remote URL for the current submodule.
|
Repository |
getRepository()
Get repository for current submodule entry
|
static java.io.File |
getSubmoduleDirectory(Repository parent,
java.lang.String path)
Get submodule directory
|
static java.lang.String |
getSubmoduleRemoteUrl(Repository parent,
java.lang.String url)
Resolve submodule repository URL.
|
static Repository |
getSubmoduleRepository(java.io.File parent,
java.lang.String path)
Get submodule repository at path
|
static Repository |
getSubmoduleRepository(java.io.File parent,
java.lang.String path,
FS fs)
Get submodule repository at path, using the specified file system
abstraction
|
static Repository |
getSubmoduleRepository(Repository parent,
java.lang.String path)
Get submodule repository
|
private void |
lazyLoadModulesConfig() |
SubmoduleWalk |
loadModulesConfig()
Load the config for this walk from
.gitmodules . |
private void |
loadPathNames() |
boolean |
next()
Advance to next submodule in the index tree.
|
SubmoduleWalk |
reset()
Reset generator and start new submodule walk
|
SubmoduleWalk |
setFilter(TreeFilter filter)
Set tree filter
|
SubmoduleWalk |
setModulesConfig(Config config)
Set the config used by this walk.
|
SubmoduleWalk |
setRootTree(AbstractTreeIterator tree)
Set the tree used by this walk for finding
.gitmodules . |
SubmoduleWalk |
setRootTree(AnyObjectId id)
Set the tree used by this walk for finding
.gitmodules . |
SubmoduleWalk |
setTree(AbstractTreeIterator iterator)
Set the tree iterator used for finding submodule entries
|
SubmoduleWalk |
setTree(AnyObjectId treeId)
Set the tree used for finding submodule entries
|
private final Repository repository
private final TreeWalk walk
private StoredConfig repoConfig
private AbstractTreeIterator rootTree
private Config modulesConfig
private java.lang.String path
private java.util.Map<java.lang.String,java.lang.String> pathToName
public SubmoduleWalk(Repository repository) throws java.io.IOException
repository
- the Repository
.java.io.IOException
public static SubmoduleWalk forIndex(Repository repository) throws java.io.IOException
.gitmodules
file is read from the index.repository
- a Repository
object.close()
.java.io.IOException
public static SubmoduleWalk forPath(Repository repository, AnyObjectId treeId, java.lang.String path) throws java.io.IOException
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.close()
. Null if no submodule at given path.java.io.IOException
public static SubmoduleWalk forPath(Repository repository, AbstractTreeIterator iterator, java.lang.String path) throws java.io.IOException
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.close()
. Null if no submodule at given path.java.io.IOException
public static java.io.File getSubmoduleDirectory(Repository parent, java.lang.String path)
parent
- the Repository
.path
- submodule pathpublic static Repository getSubmoduleRepository(Repository parent, java.lang.String path) throws java.io.IOException
parent
- the Repository
.path
- submodule pathjava.io.IOException
public static Repository getSubmoduleRepository(java.io.File parent, java.lang.String path) throws java.io.IOException
parent
- the parentpath
- submodule pathjava.io.IOException
public static Repository getSubmoduleRepository(java.io.File parent, java.lang.String path, FS fs) throws java.io.IOException
parent
- path
- fs
- the file system abstraction to be usedjava.io.IOException
public static java.lang.String getSubmoduleRemoteUrl(Repository parent, java.lang.String url) throws java.io.IOException
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.
parent
- parent repositoryurl
- absolute or relative URL of the submodule repositoryjava.io.IOException
public SubmoduleWalk setModulesConfig(Config config)
config
- .gitmodules config objectpublic SubmoduleWalk setRootTree(AbstractTreeIterator tree)
.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.
tree
- tree containing .gitmodulespublic SubmoduleWalk setRootTree(AnyObjectId id) throws java.io.IOException
.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.
id
- ID of a tree containing .gitmodulesjava.io.IOException
public SubmoduleWalk loadModulesConfig() throws java.io.IOException, ConfigInvalidException
.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.
java.io.IOException
- if an error occurred, or if the repository is bareConfigInvalidException
private void loadPathNames()
public static boolean containsGitModulesFile(Repository repository) throws java.io.IOException
repository
- the repository to checktrue
if the working tree contains a .gitmodules file,
false
otherwise. Always returns false
for bare repositories.java.io.IOException
CorruptObjectException
- if any.private void lazyLoadModulesConfig() throws java.io.IOException, ConfigInvalidException
java.io.IOException
ConfigInvalidException
private java.lang.String getModuleName(java.lang.String modulePath)
public SubmoduleWalk setFilter(TreeFilter filter)
filter
- a TreeFilter
object.public SubmoduleWalk setTree(AbstractTreeIterator iterator) throws CorruptObjectException
iterator
- an AbstractTreeIterator
object.CorruptObjectException
public SubmoduleWalk setTree(AnyObjectId treeId) throws java.io.IOException
treeId
- an AnyObjectId
object.java.io.IOException
IncorrectObjectTypeException
- if any.MissingObjectException
- if any.public SubmoduleWalk reset()
public java.io.File getDirectory()
public boolean next() throws java.io.IOException
getObjectId()
and getPath()
.java.io.IOException
public java.lang.String getPath()
public java.lang.String getModuleName()
public ObjectId getObjectId()
public java.lang.String getModulesPath() throws java.io.IOException, ConfigInvalidException
ConfigInvalidException
java.io.IOException
public java.lang.String getConfigUrl() throws java.io.IOException, ConfigInvalidException
ConfigInvalidException
java.io.IOException
public java.lang.String getModulesUrl() throws java.io.IOException, ConfigInvalidException
ConfigInvalidException
java.io.IOException
public java.lang.String getConfigUpdate() throws java.io.IOException, ConfigInvalidException
ConfigInvalidException
java.io.IOException
public java.lang.String getModulesUpdate() throws java.io.IOException, ConfigInvalidException
ConfigInvalidException
java.io.IOException
public SubmoduleWalk.IgnoreSubmoduleMode getModulesIgnore() throws java.io.IOException, ConfigInvalidException
ConfigInvalidException
java.io.IOException
public Repository getRepository() throws java.io.IOException
java.io.IOException
public ObjectId getHead() throws java.io.IOException
java.io.IOException
public java.lang.String getHeadRef() throws java.io.IOException
java.io.IOException
public java.lang.String getRemoteUrl() throws java.io.IOException, ConfigInvalidException
This method resolves the value of getModulesUrl()
to an absolute
URL
java.io.IOException
ConfigInvalidException
public void close()
Release any resources used by this walker's reader.
close
in interface java.lang.AutoCloseable