Class TestRepository<R extends Repository>
- Type Parameters:
R- type of Repository the test data is stored on.
- All Implemented Interfaces:
AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassHelper to build a branch with one or more commitsclassHelper to generate a commit. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstantAUTHOR="J.static final StringConstantAUTHOR_EMAIL="jauthor@example.com"static final StringConstantCOMMITTER="J.static final StringConstantCOMMITTER_EMAIL="jcommitter@example.com"private final Rprivate final PersonIdentprivate final PersonIdentprivate final Gitprivate final ObjectInserterprivate final MockSystemReaderprivate final RevWalk -
Constructor Summary
ConstructorsConstructorDescriptionTestRepository(R db) Wrap a repository with test building tools.TestRepository(R db, RevWalk rw) Wrap a repository with test building tools.TestRepository(R db, RevWalk rw, MockSystemReader reader) Wrap a repository with test building tools. -
Method Summary
Modifier and TypeMethodDescriptionamend(AnyObjectId id) Amend an existing commit.private TestRepository<R>.CommitBuilderamend(RevCommit old, TestRepository<R>.CommitBuilder b) Amend an existing ref.private static voidassertHash(RevObject id, byte[] bin) blob(byte[] content) Create a new blob object in the repository.Create a new blob object in the repository.Create a new branch builder for this repository.Cherry-pick a commit onto HEAD.voidclose()Closes the underlyingRepositoryobject and any other internal resources.commit()Create commit builderCreate a new commit.Create a new commit.Create a new commit.Create a new commit.voidDelete a reference.Construct a regular file mode tree entry.voidRun consistency checks against the object database.Lookup an entry stored in a tree, failing if not present.getDate()Get dateGet repositoryGet RevWalkGet timezonegit()Return Git API wrapperlightweightTag(String name, ObjectId obj) Tag an object using a lightweight tag.Construct a symlink mode tree entry.private static StringnormalizeRef(String ref) voidPack all reachable objects in the repository into a single pack file.<T extends RevObject>
TparseBody(T object) Ensure the body of the given object has been parsed.private static voidvoidSoft-reset HEAD to a different commit.voidreset(AnyObjectId id) Soft-reset HEAD to a detached state.voidSet the author and committer usinggetDate().Construct an annotated tag object pointing at another object.voidtick(int secDelta) Adjust the current time that will used by the next commit.tree(DirCacheEntry... entries) Construct a tree from a specific listing of file entries.unparsedCommit(int secDelta, RevTree tree, ObjectId... parents) Create a new, unparsed commit.unparsedCommit(ObjectId... parents) Create a new, unparsed commit.update(String ref, TestRepository<R>.CommitBuilder to) Update a reference to point to an object.<T extends AnyObjectId>
TUpdate a reference to point to an object.voidUpdate the dumb client server info files.private void
-
Field Details
-
AUTHOR
-
AUTHOR_EMAIL
-
COMMITTER
-
COMMITTER_EMAIL
ConstantCOMMITTER_EMAIL="jcommitter@example.com"- See Also:
-
defaultAuthor
-
defaultCommitter
-
db
-
git
-
pool
-
inserter
-
mockSystemReader
-
-
Constructor Details
-
TestRepository
Wrap a repository with test building tools.- Parameters:
db- the test repository to write into.- Throws:
IOException
-
TestRepository
Wrap a repository with test building tools.- Parameters:
db- the test repository to write into.rw- the RevObject pool to use for object lookup.- Throws:
IOException
-
TestRepository
Wrap a repository with test building tools.- Parameters:
db- the test repository to write into.rw- the RevObject pool to use for object lookup.reader- the MockSystemReader to use for clock and other system operations.- Throws:
IOException- Since:
- 4.2
-
-
Method Details
-
getRepository
-
getRevWalk
Get RevWalk- Returns:
- get the RevWalk pool all objects are allocated through.
-
git
Return Git API wrapper- 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).
-
getDate
-
getTimeZone
-
tick
public void tick(int secDelta) Adjust the current time that will used by the next commit.- Parameters:
secDelta- number of seconds to add to the current time.
-
setAuthorAndCommitter
Set the author and committer usinggetDate().- Parameters:
c- the commit builder to store.
-
blob
-
blob
-
file
Construct a regular file mode tree entry.- Parameters:
path- path of the file.blob- a blob, previously constructed in the repository.- Returns:
- the entry.
- Throws:
Exception
-
link
Construct a symlink mode tree entry.- Parameters:
path- path of the symlink.blob- a blob, previously constructed in the repository.- Returns:
- the entry.
- Throws:
Exception- if an error occurred- Since:
- 5.13.3
-
tree
Construct a tree from a specific listing of file entries.- Parameters:
entries- the files to include in the tree. The collection does not need to be sorted properly and may be empty.- Returns:
- the new, fully parsed tree specified by the entry list.
- Throws:
Exception
-
get
-
unparsedCommit
Create a new, unparsed commit.See
unparsedCommit(int, RevTree, ObjectId...). The tree is the empty tree (no files or subdirectories).- Parameters:
parents- zero or more IDs of the commit's parents.- Returns:
- the ID of the new commit.
- Throws:
Exception
-
commit
Create a new commit.See
commit(int, RevTree, RevCommit...). The tree is the empty tree (no files or subdirectories).- Parameters:
parents- zero or more parents of the commit.- Returns:
- the new commit.
- Throws:
Exception
-
commit
-
commit
Create a new commit.See
commit(int, RevTree, RevCommit...). The tree is the empty tree (no files or subdirectories). -
commit
Create a new commit.The author and committer identities are stored using the current timestamp, after being incremented by
secDelta. The message body is empty. -
unparsedCommit
Create a new, unparsed commit.The author and committer identities are stored using the current timestamp, after being incremented by
secDelta. The message body is empty. -
commit
Create commit builder- Returns:
- a new commit builder.
-
tag
Construct an annotated tag object pointing at another object.The tagger is the committer identity, at the current time as specified by
tick(int). The time is not increased.The tag message is empty.
- Parameters:
name- name of the tag. Traditionally a tag name should not start withrefs/tags/.dst- object the tag should be pointed at.- Returns:
- the new, fully parsed annotated tag object.
- Throws:
Exception
-
update
Update a reference to point to an object.- Parameters:
ref- the name of the reference to update to. Ifrefdoes not start withrefs/and is not the magic namesHEADFETCH_HEADorMERGE_HEAD, thenrefs/heads/will be prefixed in front of the given name, thereby assuming it is a branch.to- the target object.- Returns:
- the target object.
- Throws:
Exception
-
amendRef
Amend an existing ref.- Parameters:
ref- the name of the reference to amend, which must already exist. Ifrefdoes not start withrefs/and is not the magic namesHEADFETCH_HEADorMERGE_HEAD, thenrefs/heads/will be prefixed in front of the given name, thereby assuming it is a branch.- Returns:
- commit builder that amends the branch on commit.
- Throws:
Exception
-
amend
Amend an existing commit.- Parameters:
id- the id of the commit to amend.- Returns:
- commit builder.
- Throws:
Exception
-
amend
private TestRepository<R>.CommitBuilder amend(RevCommit old, TestRepository<R>.CommitBuilder b) throws Exception - Throws:
Exception
-
update
Update a reference to point to an object.- Type Parameters:
T- type of the target object.- Parameters:
ref- the name of the reference to update to. Ifrefdoes not start withrefs/and is not the magic namesHEADFETCH_HEADorMERGE_HEAD, thenrefs/heads/will be prefixed in front of the given name, thereby assuming it is a branch.obj- the target object.- Returns:
- the target object.
- Throws:
Exception
-
delete
Delete a reference.- Parameters:
ref- the name of the reference to delete. This is normalized in the same way asupdate(String, AnyObjectId).- Throws:
Exception- Since:
- 4.4
-
normalizeRef
-
reset
Soft-reset HEAD to a detached state.- Parameters:
id- ID of detached head.- Throws:
Exception- See Also:
-
reset
Soft-reset HEAD to a different commit.This is equivalent to
git reset --softin that it modifies HEAD but not the index or the working tree of a non-bare repository.- Parameters:
name- revision string; either an existing ref name, or something that can be parsed to an object ID.- Throws:
Exception
-
cherryPick
Cherry-pick a commit onto HEAD.This differs from
git cherry-pickin that it works in a bare repository. As a result, any merge failure results in an exception, as there is no way to recover.- Parameters:
id- commit-ish to cherry-pick.- Returns:
- the new, fully parsed commit, or null if no work was done due to the resulting tree being identical.
- Throws:
Exception
-
updateServerInfo
-
parseBody
Ensure the body of the given object has been parsed. -
branch
Create a new branch builder for this repository.- Parameters:
ref- name of the branch to be constructed. Ifrefdoes not start withrefs/the prefixrefs/heads/will be added.- Returns:
- builder for the named branch.
-
lightweightTag
-
fsck
public void fsck(RevObject... tips) throws MissingObjectException, IncorrectObjectTypeException, IOException Run consistency checks against the object database.This method completes silently if the checks pass. A temporary revision pool is constructed during the checking.
- Parameters:
tips- the tips to start checking from; if not supplied the refs of the repository are used instead.- Throws:
MissingObjectExceptionIncorrectObjectTypeExceptionIOException
-
assertHash
-
packAndPrune
-
close
public void close()Closes the underlyingRepositoryobject and any other internal resources.AutoCloseableresources that may escape this object, such as those returned by thegitandgetRevWalk()methods are not closed.- Specified by:
closein interfaceAutoCloseable
-
prunePacked
- Throws:
IOException
-
writeFile
- Throws:
IOExceptionObjectWritingException
-