Class RepoCommand
- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<RevCommit>
-
- org.eclipse.jgit.gitrepo.RepoCommand
-
- All Implemented Interfaces:
java.util.concurrent.Callable<RevCommit>
public class RepoCommand extends GitCommand<RevCommit>
A class used to execute a repo command. This will parse a repo XML manifest, convert it into .gitmodules file and the repository config file. If called against a bare repository, it will replace all the existing content of the repository with the contents populated from the manifest. repo manifest allows projects overlapping, e.g. one project's manifestPath is "foo" and another project's manifestPath is "foo/bar". This won't work in git submodule, so we'll skip all the sub projects ("foo/bar" in the example) while converting.- Since:
- 3.4
- See Also:
- git-repo project page
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RepoCommand.DefaultRemoteReader
A default implementation ofRepoCommand.RemoteReader
callback.private static class
RepoCommand.ManifestErrorException
static class
RepoCommand.RemoteFile
Read-only view of contents and file mode (i.e.static interface
RepoCommand.RemoteReader
A callback to get ref sha1 of a repository from its uri.private static class
RepoCommand.RemoteUnavailableException
-
Field Summary
Fields Modifier and Type Field Description private PersonIdent
author
private java.lang.String
baseUri
private java.lang.String
branch
private RepoCommand.RemoteReader
callback
private java.lang.String
groupsParam
private boolean
ignoreRemoteFailures
private ManifestParser.IncludedFileReader
includedReader
private java.io.InputStream
inputStream
private java.lang.String
manifestPath
private ProgressMonitor
monitor
private boolean
recordRemoteBranch
private boolean
recordShallowSubmodules
private boolean
recordSubmoduleLabels
private static java.lang.String
SLASH
private java.lang.String
targetBranch
private java.net.URI
targetUri
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Constructor Description RepoCommand(Repository repo)
Constructor for RepoCommand
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addSubmodule(java.lang.String name, java.lang.String url, java.lang.String path, java.lang.String revision, java.util.List<RepoProject.CopyFile> copyfiles, java.util.List<RepoProject.LinkFile> linkfiles, Git git)
RevCommit
call()
private static java.lang.String
findRef(java.lang.String ref, Repository repo)
(package private) static java.net.URI
relativize(java.net.URI current, java.net.URI target)
private java.util.List<RepoProject>
renameProjects(java.util.List<RepoProject> projects)
Rename the projects if there's a conflict when converted to submodules.RepoCommand
setAuthor(PersonIdent author)
Set the author/committer for the bare repository commit.RepoCommand
setBranch(java.lang.String branch)
Set default branch.RepoCommand
setGroups(java.lang.String groups)
Set groups to syncRepoCommand
setIgnoreRemoteFailures(boolean ignore)
Set whether to skip projects whose commits don't exist remotely.RepoCommand
setIncludedFileReader(ManifestParser.IncludedFileReader reader)
Set the IncludedFileReader callback.RepoCommand
setInputStream(java.io.InputStream inputStream)
Set the input stream to the manifest XML.RepoCommand
setPath(java.lang.String path)
Set path to the manifest XML file.RepoCommand
setProgressMonitor(ProgressMonitor monitor)
The progress monitor associated with the clone operation.RepoCommand
setRecommendShallow(boolean enable)
Set whether the clone-depth field should be recorded as a shallow recommendation in .gitmodules.RepoCommand
setRecordRemoteBranch(boolean enable)
Set whether the branch name should be recorded in .gitmodules.RepoCommand
setRecordSubmoduleLabels(boolean enable)
Set whether the labels field should be recorded as a label in .gitattributes.RepoCommand
setRemoteReader(RepoCommand.RemoteReader callback)
Set the GetHeadFromUri callback.RepoCommand
setTargetBranch(java.lang.String branch)
Set target branch.RepoCommand
setTargetURI(java.lang.String uri)
Set the URI of the superproject (this repository), so the .gitmodules file can specify the submodule URLs relative to the superproject.RepoCommand
setURI(java.lang.String uri)
Set base URI of the paths inside the XML.-
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
-
-
-
Field Detail
-
manifestPath
private java.lang.String manifestPath
-
baseUri
private java.lang.String baseUri
-
targetUri
private java.net.URI targetUri
-
groupsParam
private java.lang.String groupsParam
-
branch
private java.lang.String branch
-
targetBranch
private java.lang.String targetBranch
-
recordRemoteBranch
private boolean recordRemoteBranch
-
recordSubmoduleLabels
private boolean recordSubmoduleLabels
-
recordShallowSubmodules
private boolean recordShallowSubmodules
-
author
private PersonIdent author
-
callback
private RepoCommand.RemoteReader callback
-
inputStream
private java.io.InputStream inputStream
-
includedReader
private ManifestParser.IncludedFileReader includedReader
-
ignoreRemoteFailures
private boolean ignoreRemoteFailures
-
monitor
private ProgressMonitor monitor
-
SLASH
private static final java.lang.String SLASH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RepoCommand
public RepoCommand(Repository repo)
Constructor for RepoCommand- Parameters:
repo
- theRepository
-
-
Method Detail
-
setPath
public RepoCommand setPath(java.lang.String path)
Set path to the manifest XML file.Calling
setInputStream(java.io.InputStream)
will ignore the path set here.- Parameters:
path
- (with/
as separator)- Returns:
- this command
-
setInputStream
public RepoCommand setInputStream(java.io.InputStream inputStream)
Set the input stream to the manifest XML.Setting inputStream will ignore the path set. It will be closed in
call()
.- Parameters:
inputStream
- aInputStream
object.- Returns:
- this command
- Since:
- 3.5
-
setURI
public RepoCommand setURI(java.lang.String uri)
Set base URI of the paths inside the XML. This is typically the name of the directory holding the manifest repository, eg. for https://android.googlesource.com/platform/manifest, this should be /platform (if you would run this on android.googlesource.com) or https://android.googlesource.com/platform elsewhere.- Parameters:
uri
- the base URI- Returns:
- this command
-
setTargetURI
public RepoCommand setTargetURI(java.lang.String uri)
Set the URI of the superproject (this repository), so the .gitmodules file can specify the submodule URLs relative to the superproject.- Parameters:
uri
- the URI of the repository holding the superproject.- Returns:
- this command
- Since:
- 4.8
-
setGroups
public RepoCommand setGroups(java.lang.String groups)
Set groups to sync- Parameters:
groups
- groups separated by comma, examples: default|all|G1,-G2,-G3- Returns:
- this command
-
setBranch
public RepoCommand setBranch(java.lang.String branch)
Set default branch.This is generally the name of the branch the manifest file was in. If there's no default revision (branch) specified in manifest and no revision specified in project, this branch will be used.
- Parameters:
branch
- a branch name- Returns:
- this command
-
setTargetBranch
public RepoCommand setTargetBranch(java.lang.String branch)
Set target branch.This is the target branch of the super project to be updated. If not set, default is HEAD.
For non-bare repositories, HEAD will always be used and this will be ignored.
- Parameters:
branch
- branch name- Returns:
- this command
- Since:
- 4.1
-
setRecordRemoteBranch
public RepoCommand setRecordRemoteBranch(boolean enable)
Set whether the branch name should be recorded in .gitmodules.Submodule entries in .gitmodules can include a "branch" field to indicate what remote branch each submodule tracks.
That field is used by "git submodule update --remote" to update to the tip of the tracked branch when asked and by Gerrit to update the superproject when a change on that branch is merged.
Subprojects that request a specific commit or tag will not have a branch name recorded.
Not implemented for non-bare repositories.
- Parameters:
enable
- Whether to record the branch name- Returns:
- this command
- Since:
- 4.2
-
setRecordSubmoduleLabels
public RepoCommand setRecordSubmoduleLabels(boolean enable)
Set whether the labels field should be recorded as a label in .gitattributes.Not implemented for non-bare repositories.
- Parameters:
enable
- Whether to record the labels in the .gitattributes- Returns:
- this command
- Since:
- 4.4
-
setRecommendShallow
public RepoCommand setRecommendShallow(boolean enable)
Set whether the clone-depth field should be recorded as a shallow recommendation in .gitmodules.Not implemented for non-bare repositories.
- Parameters:
enable
- Whether to record the shallow recommendation.- Returns:
- this command
- Since:
- 4.4
-
setProgressMonitor
public RepoCommand setProgressMonitor(ProgressMonitor monitor)
The progress monitor associated with the clone operation. By default, this is set toNullProgressMonitor
- Parameters:
monitor
- aProgressMonitor
- Returns:
- this command
- See Also:
NullProgressMonitor
-
setIgnoreRemoteFailures
public RepoCommand setIgnoreRemoteFailures(boolean ignore)
Set whether to skip projects whose commits don't exist remotely.When set to true, we'll just skip the manifest entry and continue on to the next one.
When set to false (default), we'll throw an error when remote failures occur.
Not implemented for non-bare repositories.
- Parameters:
ignore
- Whether to ignore the remote failures.- Returns:
- this command
- Since:
- 4.3
-
setAuthor
public RepoCommand setAuthor(PersonIdent author)
Set the author/committer for the bare repository commit.For non-bare repositories, the current user will be used and this will be ignored.
- Parameters:
author
- the author'sPersonIdent
- Returns:
- this command
-
setRemoteReader
public RepoCommand setRemoteReader(RepoCommand.RemoteReader callback)
Set the GetHeadFromUri callback. This is only used in bare repositories.- Parameters:
callback
- aRepoCommand.RemoteReader
object.- Returns:
- this command
-
setIncludedFileReader
public RepoCommand setIncludedFileReader(ManifestParser.IncludedFileReader reader)
Set the IncludedFileReader callback.- Parameters:
reader
- aManifestParser.IncludedFileReader
object.- Returns:
- this command
- Since:
- 4.0
-
call
public RevCommit call() throws GitAPIException
Execute the command
- Specified by:
call
in interfacejava.util.concurrent.Callable<RevCommit>
- Specified by:
call
in classGitCommand<RevCommit>
- Throws:
GitAPIException
-
addSubmodule
private void addSubmodule(java.lang.String name, java.lang.String url, java.lang.String path, java.lang.String revision, java.util.List<RepoProject.CopyFile> copyfiles, java.util.List<RepoProject.LinkFile> linkfiles, Git git) throws GitAPIException, java.io.IOException
- Throws:
GitAPIException
java.io.IOException
-
renameProjects
private java.util.List<RepoProject> renameProjects(java.util.List<RepoProject> projects)
Rename the projects if there's a conflict when converted to submodules.- Parameters:
projects
- parsed projects- Returns:
- projects that are renamed if necessary
-
relativize
static java.net.URI relativize(java.net.URI current, java.net.URI target)
-
findRef
private static java.lang.String findRef(java.lang.String ref, Repository repo) throws java.io.IOException
- Throws:
java.io.IOException
-
-