R
- type of Repository the test data is stored on.public class TestRepository<R extends Repository>
extends java.lang.Object
implements java.lang.AutoCloseable
Modifier and Type | Class and Description |
---|---|
class |
TestRepository.BranchBuilder
Helper to build a branch with one or more commits
|
class |
TestRepository.CommitBuilder
Helper to generate a commit.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AUTHOR
Constant
AUTHOR="J. |
static java.lang.String |
AUTHOR_EMAIL
Constant
AUTHOR_EMAIL="jauthor@example.com" |
static java.lang.String |
COMMITTER
Constant
COMMITTER="J. |
static java.lang.String |
COMMITTER_EMAIL
Constant
COMMITTER_EMAIL="jcommitter@example.com" |
private R |
db |
private PersonIdent |
defaultAuthor |
private PersonIdent |
defaultCommitter |
private Git |
git |
private ObjectInserter |
inserter |
private MockSystemReader |
mockSystemReader |
private RevWalk |
pool |
Constructor and Description |
---|
TestRepository(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.
|
Modifier and Type | Method and Description |
---|---|
TestRepository.CommitBuilder |
amend(AnyObjectId id)
Amend an existing commit.
|
private TestRepository.CommitBuilder |
amend(RevCommit old,
TestRepository.CommitBuilder b) |
TestRepository.CommitBuilder |
amendRef(java.lang.String ref)
Amend an existing ref.
|
private static void |
assertHash(RevObject id,
byte[] bin) |
RevBlob |
blob(byte[] content)
Create a new blob object in the repository.
|
RevBlob |
blob(java.lang.String content)
Create a new blob object in the repository.
|
TestRepository.BranchBuilder |
branch(java.lang.String ref)
Create a new branch builder for this repository.
|
RevCommit |
cherryPick(AnyObjectId id)
Cherry-pick a commit onto HEAD.
|
void |
close()
Closes the underlying
Repository object and any other internal
resources. |
TestRepository.CommitBuilder |
commit()
Create commit builder
|
RevCommit |
commit(int secDelta,
RevCommit... parents)
Create a new commit.
|
RevCommit |
commit(int secDelta,
RevTree tree,
RevCommit... parents)
Create a new commit.
|
RevCommit |
commit(RevCommit... parents)
Create a new commit.
|
RevCommit |
commit(RevTree tree,
RevCommit... parents)
Create a new commit.
|
void |
delete(java.lang.String ref)
Delete a reference.
|
DirCacheEntry |
file(java.lang.String path,
RevBlob blob)
Construct a regular file mode tree entry.
|
void |
fsck(RevObject... tips)
Run consistency checks against the object database.
|
RevObject |
get(RevTree tree,
java.lang.String path)
Lookup an entry stored in a tree, failing if not present.
|
java.util.Date |
getDate()
Get date
|
R |
getRepository()
Get repository
|
RevWalk |
getRevWalk()
Get RevWalk
|
java.util.TimeZone |
getTimeZone()
Get timezone
|
Git |
git()
Return Git API wrapper
|
ObjectId |
lightweightTag(java.lang.String name,
ObjectId obj)
Tag an object using a lightweight tag.
|
private static java.io.File |
nameFor(ObjectDirectory odb,
ObjectId name,
java.lang.String t) |
private static java.lang.String |
normalizeRef(java.lang.String ref) |
void |
packAndPrune()
Pack all reachable objects in the repository into a single pack file.
|
<T extends RevObject> |
parseBody(T object)
Ensure the body of the given object has been parsed.
|
private static void |
prunePacked(ObjectDirectory odb) |
void |
reset(AnyObjectId id)
Soft-reset HEAD to a detached state.
|
void |
reset(java.lang.String name)
Soft-reset HEAD to a different commit.
|
void |
setAuthorAndCommitter(CommitBuilder c)
Set the author and committer using
getDate() . |
RevTag |
tag(java.lang.String name,
RevObject dst)
Construct an annotated tag object pointing at another object.
|
void |
tick(int secDelta)
Adjust the current time that will used by the next commit.
|
RevTree |
tree(DirCacheEntry... entries)
Construct a tree from a specific listing of file entries.
|
<T extends AnyObjectId> |
update(java.lang.String ref,
T obj)
Update a reference to point to an object.
|
RevCommit |
update(java.lang.String ref,
TestRepository.CommitBuilder to)
Update a reference to point to an object.
|
void |
updateServerInfo()
Update the dumb client server info files.
|
private void |
writeFile(java.io.File p,
byte[] bin) |
public static final java.lang.String AUTHOR
AUTHOR="J. Author"
public static final java.lang.String AUTHOR_EMAIL
AUTHOR_EMAIL="jauthor@example.com"
public static final java.lang.String COMMITTER
COMMITTER="J. Committer"
public static final java.lang.String COMMITTER_EMAIL
COMMITTER_EMAIL="jcommitter@example.com"
private final PersonIdent defaultAuthor
private final PersonIdent defaultCommitter
private final R extends Repository db
private final Git git
private final RevWalk pool
private final ObjectInserter inserter
private final MockSystemReader mockSystemReader
public TestRepository(R db) throws java.io.IOException
db
- the test repository to write into.java.io.IOException
public TestRepository(R db, RevWalk rw) throws java.io.IOException
db
- the test repository to write into.rw
- the RevObject pool to use for object lookup.java.io.IOException
public TestRepository(R db, RevWalk rw, MockSystemReader reader) throws java.io.IOException
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.java.io.IOException
public R getRepository()
public RevWalk getRevWalk()
public Git git()
public java.util.Date getDate()
public java.util.TimeZone getTimeZone()
public void tick(int secDelta)
secDelta
- number of seconds to add to the current time.public void setAuthorAndCommitter(CommitBuilder c)
getDate()
.c
- the commit builder to store.public RevBlob blob(java.lang.String content) throws java.lang.Exception
content
- file content, will be UTF-8 encoded.java.lang.Exception
public RevBlob blob(byte[] content) throws java.lang.Exception
content
- binary file content.java.lang.Exception
public DirCacheEntry file(java.lang.String path, RevBlob blob) throws java.lang.Exception
path
- path of the file.blob
- a blob, previously constructed in the repository.java.lang.Exception
public RevTree tree(DirCacheEntry... entries) throws java.lang.Exception
entries
- the files to include in the tree. The collection does not need
to be sorted properly and may be empty.java.lang.Exception
public RevObject get(RevTree tree, java.lang.String path) throws java.lang.Exception
tree
- the tree to search.path
- the path to find the entry of.java.lang.Exception
public RevCommit commit(RevCommit... parents) throws java.lang.Exception
See commit(int, RevTree, RevCommit...)
. The tree is the empty
tree (no files or subdirectories).
parents
- zero or more parents of the commit.java.lang.Exception
public RevCommit commit(RevTree tree, RevCommit... parents) throws java.lang.Exception
tree
- the root tree for the commit.parents
- zero or more parents of the commit.java.lang.Exception
public RevCommit commit(int secDelta, RevCommit... parents) throws java.lang.Exception
See commit(int, RevTree, RevCommit...)
. The tree is the empty
tree (no files or subdirectories).
secDelta
- number of seconds to advance tick(int)
by.parents
- zero or more parents of the commit.java.lang.Exception
public RevCommit commit(int secDelta, RevTree tree, RevCommit... parents) throws java.lang.Exception
The author and committer identities are stored using the current
timestamp, after being incremented by secDelta
. The message body
is empty.
secDelta
- number of seconds to advance tick(int)
by.tree
- the root tree for the commit.parents
- zero or more parents of the commit.java.lang.Exception
public TestRepository.CommitBuilder commit()
public RevTag tag(java.lang.String name, RevObject dst) throws java.lang.Exception
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.
name
- name of the tag. Traditionally a tag name should not start
with refs/tags/
.dst
- object the tag should be pointed at.java.lang.Exception
public RevCommit update(java.lang.String ref, TestRepository.CommitBuilder to) throws java.lang.Exception
ref
- 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.to
- the target object.java.lang.Exception
public TestRepository.CommitBuilder amendRef(java.lang.String ref) throws java.lang.Exception
ref
- 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.java.lang.Exception
public TestRepository.CommitBuilder amend(AnyObjectId id) throws java.lang.Exception
id
- the id of the commit to amend.java.lang.Exception
private TestRepository.CommitBuilder amend(RevCommit old, TestRepository.CommitBuilder b) throws java.lang.Exception
java.lang.Exception
public <T extends AnyObjectId> T update(java.lang.String ref, T obj) throws java.lang.Exception
T
- type of the target object.ref
- 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.obj
- the target object.java.lang.Exception
public void delete(java.lang.String ref) throws java.lang.Exception
ref
- the name of the reference to delete. This is normalized
in the same way as update(String, AnyObjectId)
.java.lang.Exception
private static java.lang.String normalizeRef(java.lang.String ref)
public void reset(AnyObjectId id) throws java.lang.Exception
id
- ID of detached head.java.lang.Exception
reset(String)
public void reset(java.lang.String name) throws java.lang.Exception
This is equivalent to git reset --soft
in that it modifies HEAD but
not the index or the working tree of a non-bare repository.
name
- revision string; either an existing ref name, or something that
can be parsed to an object ID.java.lang.Exception
public RevCommit cherryPick(AnyObjectId id) throws java.lang.Exception
This differs from git cherry-pick
in that it works in a bare
repository. As a result, any merge failure results in an exception, as
there is no way to recover.
id
- commit-ish to cherry-pick.java.lang.Exception
public void updateServerInfo() throws java.lang.Exception
java.lang.Exception
public <T extends RevObject> T parseBody(T object) throws java.lang.Exception
public TestRepository.BranchBuilder branch(java.lang.String ref)
ref
- name of the branch to be constructed. If ref
does not
start with refs/
the prefix refs/heads/
will
be added.public ObjectId lightweightTag(java.lang.String name, ObjectId obj) throws java.lang.Exception
name
- the tag name. The /refs/tags/ prefix will be added if the name
doesn't start with itobj
- the object to tagjava.lang.Exception
public void fsck(RevObject... tips) throws MissingObjectException, IncorrectObjectTypeException, java.io.IOException
This method completes silently if the checks pass. A temporary revision pool is constructed during the checking.
tips
- the tips to start checking from; if not supplied the refs of
the repository are used instead.MissingObjectException
IncorrectObjectTypeException
java.io.IOException
private static void assertHash(RevObject id, byte[] bin)
public void packAndPrune() throws java.lang.Exception
All loose objects are automatically pruned. Existing packs however are not removed.
java.lang.Exception
public void close()
Repository
object and any other internal
resources.
AutoCloseable
resources that may escape this object, such as
those returned by the git
and getRevWalk()
methods are
not closed.
close
in interface java.lang.AutoCloseable
private static void prunePacked(ObjectDirectory odb) throws java.io.IOException
java.io.IOException
private static java.io.File nameFor(ObjectDirectory odb, ObjectId name, java.lang.String t)
private void writeFile(java.io.File p, byte[] bin) throws java.io.IOException, ObjectWritingException
java.io.IOException
ObjectWritingException