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

public Class TestRepository<R extends Repository>

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Type Parameters
<R>
type of Repository the test data is stored on.
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.junit.Assert.assertEquals, .Assert.fail

Wrapper to make creating test data easier.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
TestRepository.BranchBuilder

Helper to build a branch with one or more commits

public class
TestRepository.CommitBuilder

Helper to generate a commit.

Field Summary

Modifier and TypeField and Description
public static final String
AUTHOR

Constant AUTHOR="J.

public static final String
AUTHOR_EMAIL

Constant AUTHOR_EMAIL="[email protected]"

public static final String
COMMITTER

Constant COMMITTER="J.

public static final String
COMMITTER_EMAIL

Constant COMMITTER_EMAIL="[email protected]"

private final R
private final PersonIdent
private final PersonIdent
private final Git
private final ObjectInserter
private final MockSystemReader
private final RevWalk

Constructor Summary

AccessConstructor and Description
public
TestRepository(R
the test repository to write into.
db
)

Wrap a repository with test building tools.

public
TestRepository(R
the test repository to write into.
db
,
RevWalk
the RevObject pool to use for object lookup.
rw
)

Wrap a repository with test building tools.

public
TestRepository(R
the test repository to write into.
db
,
RevWalk
the RevObject pool to use for object lookup.
rw
,
MockSystemReader
the MockSystemReader to use for clock and other system operations.
reader
)

Wrap a repository with test building tools.

Method Summary

Modifier and TypeMethod and Description
public TestRepository<R>.CommitBuilder

Returns:

commit builder.
amend
(AnyObjectId
the id of the commit to amend.
id
)

Amend an existing commit.

private TestRepository<R>.CommitBuilder
public TestRepository<R>.CommitBuilder

Returns:

commit builder that amends the branch on commit.
amendRef
(String
the name of the reference to amend, which must already exist. If ref does not start with refs/ and is not the magic names HEAD FETCH_HEAD or MERGE_HEAD, then refs/heads/ will be prefixed in front of the given name, thereby assuming it is a branch.
ref
)

Amend an existing ref.

private static void
assertHash(RevObject id, byte[] bin)

public RevBlob

Returns:

reference to the blob.
blob
(String
file content, will be UTF-8 encoded.
content
)

Create a new blob object in the repository.

public RevBlob

Returns:

the new, fully parsed blob.
blob
(byte[]
binary file content.
content
)

Create a new blob object in the repository.

public TestRepository<R>.BranchBuilder

Returns:

builder for the named branch.
branch
(String
name of the branch to be constructed. If ref does not start with refs/ the prefix refs/heads/ will be added.
ref
)

Create a new branch builder for this repository.

public RevCommit

Returns:

the new, fully parsed commit, or null if no work was done due to the resulting tree being identical.
cherryPick
(AnyObjectId
commit-ish to cherry-pick.
id
)

Cherry-pick a commit onto HEAD.

public void
close()

Implements java.lang.AutoCloseable.close.

Closes the underlying Repository object and any other internal resources.

public RevCommit

Returns:

the new commit.
commit
(RevCommit...
zero or more parents of the commit.
parents
)

Create a new commit.

public RevCommit

Returns:

the new commit.
commit
(RevTree
the root tree for the commit.
tree
,
RevCommit...
zero or more parents of the commit.
parents
)

Create a new commit.

public RevCommit

Returns:

the new commit.
commit
(int
number of seconds to advance tick(int) by.
secDelta
,
RevCommit...
zero or more parents of the commit.
parents
)

Create a new commit.

public RevCommit

Returns:

the new, fully parsed commit.
commit
(final int
number of seconds to advance tick(int) by.
secDelta
,
final RevTree
the root tree for the commit.
tree
,
final RevCommit...
zero or more parents of the commit.
parents
)

Create a new commit.

public TestRepository<R>.CommitBuilder

Returns:

a new commit builder.
commit
()

Create commit builder

public void
delete(String
the name of the reference to delete. This is normalized in the same way as update(String, AnyObjectId).
ref
)

Delete a reference.

public DirCacheEntry

Returns:

the entry.
file
(String
path of the file.
path
,
RevBlob
a blob, previously constructed in the repository.
blob
)

Construct a regular file mode tree entry.

public void
fsck(RevObject...
the tips to start checking from; if not supplied the refs of the repository are used instead.
tips
)

Run consistency checks against the object database.

public RevObject

Returns:

the parsed object entry at this path, never null.
get
(RevTree
the tree to search.
tree
,
String
the path to find the entry of.
path
)

Lookup an entry stored in a tree, failing if not present.

public Date

Returns:

current date.
getDate
()
Deprecated since 7.2. Use getInstant() instead.

Get date

public Instant

Returns:

current instant.
getInstant
()

Get instant

public R

Returns:

the repository this helper class operates against.
getRepository
()

Get repository

public RevWalk

Returns:

get the RevWalk pool all objects are allocated through.
getRevWalk
()

Get RevWalk

public TimeZone

Returns:

timezone used for default identities.
getTimeZone
()
Deprecated since 7.2. Use getTimeZoneId() instead.

Get timezone

public ZoneId

Returns:

timezone used for default identities.
getTimeZoneId
()

Get timezone

public Git

Returns:

an API wrapper for the underlying repository. This wrapper does not allocate any new resources and need not be closed (but closing it is harmless).
git
()

Return Git API wrapper

public ObjectId

Returns:

the tagged object
lightweightTag
(String
the tag name. The /refs/tags/ prefix will be added if the name doesn't start with it
name
,
ObjectId
the object to tag
obj
)

Tag an object using a lightweight tag.

private static String
public void
packAndPrune()

Pack all reachable objects in the repository into a single pack file.

public <T extends RevObject> T

Returns:

object
parseBody
(T
reference to the (possibly unparsed) object to force body parsing of.
object
)

Ensure the body of the given object has been parsed.

private static void
public void
reset(AnyObjectId
ID of detached head.
id
)

Soft-reset HEAD to a detached state.

public void
reset(String
revision string; either an existing ref name, or something that can be parsed to an object ID.
name
)

Soft-reset HEAD to a different commit.

public void
setAuthorAndCommitter(CommitBuilder
the commit builder to store.
c
)

Set the author and committer using getInstant().

public RevTag

Returns:

the new, fully parsed annotated tag object.
tag
(String
name of the tag. Traditionally a tag name should not start with refs/tags/.
name
,
RevObject
object the tag should be pointed at.
dst
)

Construct an annotated tag object pointing at another object.

public void
tick(int
number of seconds to add to the current time.
secDelta
)

Adjust the current time that will used by the next commit.

public RevTree

Returns:

the new, fully parsed tree specified by the entry list.
tree
(DirCacheEntry...
the files to include in the tree. The collection does not need to be sorted properly and may be empty.
entries
)

Construct a tree from a specific listing of file entries.

public ObjectId

Returns:

the ID of the new commit.
unparsedCommit
(ObjectId...
zero or more IDs of the commit's parents.
parents
)

Create a new, unparsed commit.

public ObjectId

Returns:

the ID of the new commit.
unparsedCommit
(final int
number of seconds to advance tick(int) by.
secDelta
,
final RevTree
the root tree for the commit.
tree
,
final ObjectId...
zero or more IDs of the commit's parents.
parents
)

Create a new, unparsed commit.

public RevCommit

Returns:

the target object.
update
(String
the name of the reference to update to. If ref does not start with refs/ and is not the magic names HEAD FETCH_HEAD or MERGE_HEAD, then refs/heads/ will be prefixed in front of the given name, thereby assuming it is a branch.
ref
,
TestRepository<R>.CommitBuilder
the target object.
to
)

Update a reference to point to an object.

public <
type of the target object.
T extends AnyObjectId
>
T

Returns:

the target object.
update
(String
the name of the reference to update to. If ref does not start with refs/ and is not the magic names HEAD FETCH_HEAD or MERGE_HEAD, then refs/heads/ will be prefixed in front of the given name, thereby assuming it is a branch.
ref
,
T
the target object.
obj
)

Update a reference to point to an object.

public void
updateServerInfo()

Update the dumb client server info files.

private void
writeFile(File p, byte[] bin)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait