org.eclipse.jgit.junit
Class TestRepository<R extends Repository>

java.lang.Object
  extended by org.eclipse.jgit.junit.TestRepository<R>
Type Parameters:
R - type of Repository the test data is stored on.

public class TestRepository<R extends Repository>
extends java.lang.Object

Wrapper to make creating test data easier.


Nested Class Summary
 class TestRepository.BranchBuilder
          Helper to build a branch with one or more commits
 class TestRepository.CommitBuilder
          Helper to generate a commit.
 
Constructor Summary
TestRepository(R db)
          Wrap a repository with test building tools.
TestRepository(R db, RevWalk rw)
          Wrap a repository with test building tools.
 
Method Summary
 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.
 TestRepository.CommitBuilder commit()
           
 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.
 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 getClock()
           
 R getRepository()
           
 RevWalk getRevWalk()
           
 void packAndPrune()
          Pack all reachable objects in the repository into a single pack file.
<T extends RevObject>
T
parseBody(T object)
          Ensure the body of the given object has been parsed.
 void setAuthorAndCommitter(CommitBuilder c)
          Set the author and committer using getClock().
 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>
T
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestRepository

public TestRepository(R db)
               throws java.io.IOException
Wrap a repository with test building tools.

Parameters:
db - the test repository to write into.
Throws:
java.io.IOException

TestRepository

public TestRepository(R db,
                      RevWalk rw)
               throws java.io.IOException
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:
java.io.IOException
Method Detail

getRepository

public R getRepository()
Returns:
the repository this helper class operates against.

getRevWalk

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

getClock

public java.util.Date getClock()
Returns:
current time adjusted by tick(int).

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

public void setAuthorAndCommitter(CommitBuilder c)
Set the author and committer using getClock().

Parameters:
c - the commit builder to store.

blob

public RevBlob blob(java.lang.String content)
             throws java.lang.Exception
Create a new blob object in the repository.

Parameters:
content - file content, will be UTF-8 encoded.
Returns:
reference to the blob.
Throws:
java.lang.Exception

blob

public RevBlob blob(byte[] content)
             throws java.lang.Exception
Create a new blob object in the repository.

Parameters:
content - binary file content.
Returns:
reference to the blob.
Throws:
java.lang.Exception

file

public DirCacheEntry file(java.lang.String path,
                          RevBlob blob)
                   throws java.lang.Exception
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:
java.lang.Exception

tree

public RevTree tree(DirCacheEntry... entries)
             throws java.lang.Exception
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:
reference to the tree specified by the entry list.
Throws:
java.lang.Exception

get

public RevObject get(RevTree tree,
                     java.lang.String path)
              throws java.lang.Exception
Lookup an entry stored in a tree, failing if not present.

Parameters:
tree - the tree to search.
path - the path to find the entry of.
Returns:
the parsed object entry at this path, never null.
Throws:
java.lang.Exception

commit

public RevCommit commit(RevCommit... parents)
                 throws java.lang.Exception
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:
java.lang.Exception

commit

public RevCommit commit(RevTree tree,
                        RevCommit... parents)
                 throws java.lang.Exception
Create a new commit.

See commit(int, RevTree, RevCommit...).

Parameters:
tree - the root tree for the commit.
parents - zero or more parents of the commit.
Returns:
the new commit.
Throws:
java.lang.Exception

commit

public RevCommit commit(int secDelta,
                        RevCommit... parents)
                 throws java.lang.Exception
Create a new commit.

See commit(int, RevTree, RevCommit...). The tree is the empty tree (no files or subdirectories).

Parameters:
secDelta - number of seconds to advance tick(int) by.
parents - zero or more parents of the commit.
Returns:
the new commit.
Throws:
java.lang.Exception

commit

public RevCommit commit(int secDelta,
                        RevTree tree,
                        RevCommit... parents)
                 throws java.lang.Exception
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.

Parameters:
secDelta - number of seconds to advance tick(int) by.
tree - the root tree for the commit.
parents - zero or more parents of the commit.
Returns:
the new commit.
Throws:
java.lang.Exception

commit

public TestRepository.CommitBuilder commit()
Returns:
a new commit builder.

tag

public RevTag tag(java.lang.String name,
                  RevObject dst)
           throws java.lang.Exception
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 with refs/tags/.
dst - object the tag should be pointed at.
Returns:
the annotated tag object.
Throws:
java.lang.Exception

update

public RevCommit update(java.lang.String ref,
                        TestRepository.CommitBuilder to)
                 throws java.lang.Exception
Update a reference to point to an object.

Parameters:
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.
Returns:
the target object.
Throws:
java.lang.Exception

update

public <T extends AnyObjectId> T update(java.lang.String ref,
                                        T obj)
                             throws java.lang.Exception
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. 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.
Returns:
the target object.
Throws:
java.lang.Exception

updateServerInfo

public void updateServerInfo()
                      throws java.lang.Exception
Update the dumb client server info files.

Throws:
java.lang.Exception

parseBody

public <T extends RevObject> T parseBody(T object)
                              throws java.lang.Exception
Ensure the body of the given object has been parsed.

Type Parameters:
T - type of object, e.g. RevTag or RevCommit.
Parameters:
object - reference to the (possibly unparsed) object to force body parsing of.
Returns:
object
Throws:
java.lang.Exception

branch

public TestRepository.BranchBuilder branch(java.lang.String ref)
Create a new branch builder for this repository.

Parameters:
ref - name of the branch to be constructed. If ref does not start with refs/ the prefix refs/heads/ will be added.
Returns:
builder for the named branch.

fsck

public void fsck(RevObject... tips)
          throws MissingObjectException,
                 IncorrectObjectTypeException,
                 java.io.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:
MissingObjectException
IncorrectObjectTypeException
java.io.IOException

packAndPrune

public void packAndPrune()
                  throws java.lang.Exception
Pack all reachable objects in the repository into a single pack file.

All loose objects are automatically pruned. Existing packs however are not removed.

Throws:
java.lang.Exception


Copyright © 2011. All Rights Reserved.