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

public Class RepoCommand

extends GitCommand<RevCommit>
Class Inheritance
Imports
java.io.File, .FileInputStream, .IOException, .InputStream, java.net.URI, java.text.MessageFormat, java.util.ArrayList, .List, .Map, .Objects, .StringJoiner, .TreeMap, org.eclipse.jgit.annotations.NonNull, .Nullable, org.eclipse.jgit.api.Git, .GitCommand, org.eclipse.jgit.api.errors.GitAPIException, .InvalidRefNameException, org.eclipse.jgit.gitrepo.BareSuperprojectWriter.ExtraContent, .ManifestParser.IncludedFileReader, org.eclipse.jgit.gitrepo.internal.RepoText, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.Constants, .FileMode, .ObjectId, .PersonIdent, .ProgressMonitor, .Ref, .RefDatabase, .Repository, org.eclipse.jgit.revwalk.RevCommit, org.eclipse.jgit.treewalk.TreeWalk, org.eclipse.jgit.util.FileUtils

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
RepoCommand.DefaultRemoteReader

A default implementation of RemoteReader callback.

pack-priv static class
public static class
RepoCommand.RemoteFile

Read-only view of contents and file mode (i.e. permissions) for a file in a remote repository.

public static interface
RepoCommand.RemoteReader

A callback to get ref sha1 of a repository from its uri.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private PersonIdent
private BareSuperprojectWriter.BareWriterConfig
private String
private String
private RepoCommand.RemoteReader
private final List<BareSuperprojectWriter.ExtraContent>
private String
private ManifestParser.IncludedFileReader
private InputStream
private String
private ProgressMonitor
private static final String
private String
private URI
Inherited from org.eclipse.jgit.api.GitCommand:
repo

Constructor Summary

AccessConstructor and Description
public
RepoCommand(Repository repo)

Constructor for RepoCommand

Method Summary

Modifier and TypeMethod and Description
public RepoCommand

Returns:

this command
addToDestination
(String
where to create the file in the destination repository
path
,
String
content for the create file
contents
)

Create a file with the given content in the destination repository

public RevCommit
call()

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

pack-priv static URI
relativize(URI current, URI target)

private List<RepoProject>

Returns:

projects that are renamed if necessary
renameProjects
(List<RepoProject>
parsed projects
projects
)

Rename the projects if there's a conflict when converted to submodules.

public RepoCommand

Returns:

this command
setAuthor
(PersonIdent author)

Set the author/committer for the bare repository commit.

public RepoCommand

Returns:

this command
setBranch
(String
a branch name
branch
)

Set default branch.

public RepoCommand

Returns:

this command
setGroups
(String
groups separated by comma, examples: default|all|G1,-G2,-G3
groups
)

Set groups to sync

public RepoCommand

Returns:

this command
setIgnoreRemoteFailures
(boolean
Whether to ignore the remote failures.
ignore
)

Set whether to skip projects whose commits don't exist remotely.

public RepoCommand

Returns:

this command
setIncludedFileReader
(ManifestParser.IncludedFileReader reader)

Set the IncludedFileReader callback.

public RepoCommand

Returns:

this command
setInputStream
(InputStream inputStream)

Set the input stream to the manifest XML.

public RepoCommand

Returns:

this command
setPath
(String
(with / as separator)
path
)

Set path to the manifest XML file.

public RepoCommand

Returns:

this command
setProgressMonitor
(ProgressMonitor monitor)

The progress monitor associated with the clone operation.

public RepoCommand

Returns:

this command
setRecommendShallow
(boolean
Whether to record the shallow recommendation.
enable
)

Set whether the clone-depth field should be recorded as a shallow recommendation in .gitmodules.

public RepoCommand

Returns:

this command
setRecordRemoteBranch
(boolean
Whether to record the branch name
enable
)

Set whether the branch name should be recorded in .gitmodules.

public RepoCommand

Returns:

this command
setRecordSubmoduleLabels
(boolean
Whether to record the labels in the .gitattributes
enable
)

Set whether the labels field should be recorded as a label in .gitattributes.

public RepoCommand

Returns:

this command
setRemoteReader
(RepoCommand.RemoteReader callback)

Set the GetHeadFromUri callback.

public RepoCommand

Returns:

this command
setTargetBranch
(String
branch name
branch
)

Set target branch.

public RepoCommand

Returns:

this command
setTargetURI
(String
the URI of the repository holding the superproject.
uri
)

Set the URI of the superproject (this repository), so the .gitmodules file can specify the submodule URLs relative to the superproject.

public RepoCommand

Returns:

this command
setURI
(String
the base URI
uri
)

Set base URI of the paths inside the XML.

Inherited from org.eclipse.jgit.api.GitCommand:
checkCallablegetRepositorysetCallable

Field Detail

authorback to summary
private PersonIdent author
bareWriterConfigback to summary
private BareSuperprojectWriter.BareWriterConfig bareWriterConfig
baseUriback to summary
private String baseUri
branchback to summary
private String branch
callbackback to summary
private RepoCommand.RemoteReader callback
extraContentsback to summary
private final List<BareSuperprojectWriter.ExtraContent> extraContents
groupsParamback to summary
private String groupsParam
includedReaderback to summary
private ManifestParser.IncludedFileReader includedReader
inputStreamback to summary
private InputStream inputStream
manifestPathback to summary
private String manifestPath
monitorback to summary
private ProgressMonitor monitor
SLASHback to summary
private static final String SLASH
targetBranchback to summary
private String targetBranch
targetUriback to summary
private URI targetUri

Constructor Detail

RepoCommandback to summary
public RepoCommand(Repository repo)

Constructor for RepoCommand

Parameters
repo:Repository

the org.eclipse.jgit.lib.Repository

Method Detail

addToDestinationback to summary
public RepoCommand addToDestination(String path, String contents)

Create a file with the given content in the destination repository

Parameters
path:String

where to create the file in the destination repository

contents:String

content for the create file

Returns:RepoCommand

this command

Since
6.1
callback to summary
public RevCommit call() throws GitAPIException

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Doc from org.eclipse.jgit.api.GitCommand.call.

Computes a result, or throws an exception if unable to do so.

Execute the command

Returns:RevCommit

Doc from java.util.concurrent.Callable.call.

computed result

Annotations
@Override
relativizeback to summary
pack-priv static URI relativize(URI current, URI target)
renameProjectsback to summary
private List<RepoProject> renameProjects(List<RepoProject> projects)

Rename the projects if there's a conflict when converted to submodules.

Parameters
projects:List<RepoProject>

parsed projects

Returns:List<RepoProject>

projects that are renamed if necessary

setAuthorback to summary
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:PersonIdent

the author's org.eclipse.jgit.lib.PersonIdent

Returns:RepoCommand

this command

setBranchback to summary
public RepoCommand setBranch(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:String

a branch name

Returns:RepoCommand

this command

setGroupsback to summary
public RepoCommand setGroups(String groups)

Set groups to sync

Parameters
groups:String

groups separated by comma, examples: default|all|G1,-G2,-G3

Returns:RepoCommand

this command

setIgnoreRemoteFailuresback to summary
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:boolean

Whether to ignore the remote failures.

Returns:RepoCommand

this command

Since
4.3
setIncludedFileReaderback to summary
public RepoCommand setIncludedFileReader(ManifestParser.IncludedFileReader reader)

Set the IncludedFileReader callback.

Parameters
reader:ManifestParser.IncludedFileReader

a org.eclipse.jgit.gitrepo.ManifestParser.IncludedFileReader object.

Returns:RepoCommand

this command

Since
4.0
setInputStreamback to summary
public RepoCommand setInputStream(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:InputStream

a java.io.InputStream object.

Returns:RepoCommand

this command

Since
3.5
setPathback to summary
public RepoCommand setPath(String path)

Set path to the manifest XML file.

Calling setInputStream will ignore the path set here.

Parameters
path:String

(with / as separator)

Returns:RepoCommand

this command

setProgressMonitorback to summary
public RepoCommand setProgressMonitor(ProgressMonitor monitor)

The progress monitor associated with the clone operation. By default, this is set to NullProgressMonitor

Parameters
monitor:ProgressMonitor

a org.eclipse.jgit.lib.ProgressMonitor

Returns:RepoCommand

this command

See Also
org.eclipse.jgit.lib.NullProgressMonitor
setRecommendShallowback to summary
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:boolean

Whether to record the shallow recommendation.

Returns:RepoCommand

this command

Since
4.4
setRecordRemoteBranchback to summary
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:boolean

Whether to record the branch name

Returns:RepoCommand

this command

Since
4.2
setRecordSubmoduleLabelsback to summary
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:boolean

Whether to record the labels in the .gitattributes

Returns:RepoCommand

this command

Since
4.4
setRemoteReaderback to summary
public RepoCommand setRemoteReader(RepoCommand.RemoteReader callback)

Set the GetHeadFromUri callback. This is only used in bare repositories.

Parameters
callback:RepoCommand.RemoteReader

a org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader object.

Returns:RepoCommand

this command

setTargetBranchback to summary
public RepoCommand setTargetBranch(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:String

branch name

Returns:RepoCommand

this command

Since
4.1
setTargetURIback to summary
public RepoCommand setTargetURI(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:String

the URI of the repository holding the superproject.

Returns:RepoCommand

this command

Since
4.8
setURIback to summary
public RepoCommand setURI(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:String

the base URI

Returns:RepoCommand

this command

org.eclipse.jgit.gitrepo back to summary

public Class RepoCommand.DefaultRemoteReader

extends Object
implements RemoteReader
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader

A default implementation of RemoteReader callback.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public RepoCommand.RemoteFile
readFileWithMode(String
The URI of the remote repository
uri
,
String
Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.
ref
,
String
The relative path (inside the repo) to the file to read
path
)

Implements org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader.readFileWithMode.

Read contents and mode (i.e. permissions) of the file from a remote repository.

public ObjectId
sha1(String
The URI of the remote repository
uri
,
String
Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.
ref
)

Implements org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader.sha1.

Read a remote ref sha1.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DefaultRemoteReaderback to summary
public DefaultRemoteReader()

Method Detail

readFileWithModeback to summary
public RepoCommand.RemoteFile readFileWithMode(String uri, String ref, String path) throws GitAPIException, IOException

Implements org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader.readFileWithMode.

Doc from org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader.readFileWithMode.

Read contents and mode (i.e. permissions) of the file from a remote repository.

Parameters
uri:String

The URI of the remote repository

ref:String

Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.

path:String

The relative path (inside the repo) to the file to read

Returns:RepoCommand.RemoteFile

The contents and file mode of the file in the given repository and branch. Never null.

Annotations
@Override
Exceptions
GitAPIException:
If the ref have an invalid or ambiguous name, or it does not exist in the repository,
IOException:
If the object does not exist or is too large
sha1back to summary
public ObjectId sha1(String uri, String ref) throws GitAPIException

Implements org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader.sha1.

Doc from org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader.sha1.

Read a remote ref sha1.

Parameters
uri:String

The URI of the remote repository

ref:String

Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.

Returns:ObjectId

the sha1 of the remote repository, or null if the ref does not exist.

Annotations
@Override
Exceptions
GitAPIException:
a JGit API exception
org.eclipse.jgit.gitrepo back to summary

pack-priv Class RepoCommand.ManifestErrorException

extends GitAPIException
Class Inheritance
Annotations
@SuppressWarnings:serial

Constructor Summary

AccessConstructor and Description
pack-priv

Constructor Detail

ManifestErrorExceptionback to summary
pack-priv ManifestErrorException(Throwable cause)
org.eclipse.jgit.gitrepo back to summary

public final Class RepoCommand.RemoteFile

extends Object
Class Inheritance

Read-only view of contents and file mode (i.e. permissions) for a file in a remote repository.
Since
5.2

Field Summary

Modifier and TypeField and Description
private final byte[]
private final FileMode

Constructor Summary

AccessConstructor and Description
public
RemoteFile(byte[]
Raw contents of the file.
contents
,
FileMode
Git file mode for this file (e.g. executable or regular)
fileMode
)

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

Raw contents of the file. Do not modify it.
getContents
()

Contents of the file.

public FileMode

Returns:

Git file mode for this file (e.g. executable or regular)
getFileMode
()

Get file mode

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentsback to summary
private final byte[] contents
Annotations
@NonNull
fileModeback to summary
private final FileMode fileMode
Annotations
@NonNull

Constructor Detail

RemoteFileback to summary
public RemoteFile(byte[] contents, FileMode fileMode)
Parameters
contents:byte[]

Raw contents of the file.

fileMode:FileMode

Git file mode for this file (e.g. executable or regular)

Method Detail

getContentsback to summary
public byte[] getContents()

Contents of the file.

Callers who receive this reference must not modify its contents (as it can point to internal cached data).

Returns:byte[]

Raw contents of the file. Do not modify it.

Annotations
@NonNull
getFileModeback to summary
public FileMode getFileMode()

Get file mode

Returns:FileMode

Git file mode for this file (e.g. executable or regular)

Annotations
@NonNull
org.eclipse.jgit.gitrepo back to summary

public Interface RepoCommand.RemoteReader

Known Direct Implementers
org.eclipse.jgit.gitrepo.RepoCommand.DefaultRemoteReader

A callback to get ref sha1 of a repository from its uri. We provided a default implementation DefaultRemoteReader to use ls-remote command to read the sha1 from the repository and clone the repository to read the file. Callers may have their own quicker implementation.
Since
3.4

Method Summary

Modifier and TypeMethod and Description
public RepoCommand.RemoteFile

Returns:

The contents and file mode of the file in the given repository and branch. Never null.
readFileWithMode
(String
The URI of the remote repository
uri
,
String
Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.
ref
,
String
The relative path (inside the repo) to the file to read
path
)

Read contents and mode (i.e. permissions) of the file from a remote repository.

public ObjectId

Returns:

the sha1 of the remote repository, or null if the ref does not exist.
sha1
(String
The URI of the remote repository
uri
,
String
Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.
ref
)

Read a remote ref sha1.

Method Detail

readFileWithModeback to summary
public RepoCommand.RemoteFile readFileWithMode(String uri, String ref, String path) throws GitAPIException, IOException

Read contents and mode (i.e. permissions) of the file from a remote repository.

Parameters
uri:String

The URI of the remote repository

ref:String

Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.

path:String

The relative path (inside the repo) to the file to read

Returns:RepoCommand.RemoteFile

The contents and file mode of the file in the given repository and branch. Never null.

Annotations
@NonNull
Exceptions
GitAPIException:
If the ref have an invalid or ambiguous name, or it does not exist in the repository,
IOException:
If the object does not exist or is too large
Since
5.2
sha1back to summary
public ObjectId sha1(String uri, String ref) throws GitAPIException

Read a remote ref sha1.

Parameters
uri:String

The URI of the remote repository

ref:String

Name of the ref to lookup. May be a short-hand form, e.g. "master" which is automatically expanded to "refs/heads/master" if "refs/heads/master" already exists.

Returns:ObjectId

the sha1 of the remote repository, or null if the ref does not exist.

Annotations
@Nullable
Exceptions
GitAPIException:
a JGit API exception
org.eclipse.jgit.gitrepo back to summary

pack-priv Class RepoCommand.RemoteUnavailableException

extends GitAPIException
Class Inheritance
Annotations
@SuppressWarnings:serial

Constructor Summary

AccessConstructor and Description
pack-priv

Constructor Detail

RemoteUnavailableExceptionback to summary
pack-priv RemoteUnavailableException(String uri)