GitSharp.Tests
Base class for most unit tests.
Sets up a predefined test repository and has support for creating additional
repositories and destroying them when the tests are finished.
A fake (but stable) identity for author fields in the test.
A fake (but stable) identity for committer fields in the test.
Increment the {@link #author} and {@link #committer} times.
Recursively delete a directory, failing the test if the delete fails.
@param dir
the recursively directory to delete, if present.
Creates a new empty bare repository.
@return the newly created repository, opened for access
@throws IOException
the repository could not be created in the temporary area
Creates a new empty repository within a new empty working directory.
@return the newly created repository, opened for access
@throws IOException
the repository could not be created in the temporary area
Creates a new empty repository.
@param bare
true to create a bare repository; false to make a repository
within its working directory
@return the newly created repository, opened for access
@throws IOException
the repository could not be created in the temporary area
Run a hook script in the repository, returning the exit status.
@param db
repository the script should see in GIT_DIR environment
@param hook
path of the hook script to execute, must be executable file
type on this platform
@param args
arguments to pass to the hook script
@return exit status code of the invoked hook
@throws IOException
the hook could not be executed
@throws InterruptedException
the caller was interrupted before the hook completed
Create a string to a UTF-8 temporary file and return the path.
@param body
complete content to write to the file. If the file should end
with a trailing LF, the string should end with an LF.
@return path of the temporary file created within the trash area.
@throws IOException
the file could not be written.
Write a string as a UTF-8 file.
@param f
file to write the string to. Caller is responsible for making
sure it is in the trash directory or will otherwise be cleaned
up at the end of the test. If the parent directory does not
exist, the missing parent directories are automatically
created.
@param body
content to write to the file.
@throws IOException
the file could not be written.
Fully read a UTF-8 file and return as a string.
@param f
file to read the content of.
@return UTF-8 decoded content of the file, empty string if the file
exists but has no content.
@throws IOException
the file does not exist, or could not be read.
Test repository, initialized for this test case.
mock user's global configuration used instead ~/.gitconfig.
This configuration can be modified by the tests without any
effect for ~/.gitconfig.
Working directory of {@link #db}.
This testcase shows how to interact with the index without a working directory
When not allowing a fast forward merge, a new commit is created the merged commits as parent.
Tests the performance of MyersDiff for texts which are similar (not
random data). The CPU time is measured and returned. Because of bad
accuracy of CPU time information the diffs are repeated. During each
repetition the interim CPU time is checked. The diff operation is
repeated until we have seen the CPU time clock changed its value at least
{@link #minCPUTimerTicks} times.
@param characters
the size of the diffed character sequences.
@return performance data
We had bugs related to buffer size in the DirCache. This test creates an
index larger than the default BufferedInputStream buffer size. This made
the DirCache unable to Read the extensions when index size exceeded the
buffer size (in some cases at least).
The c belongs to the range a-c. "-e" is no valid range so d should not match.
for some reasons
Check for a conflict where the second text was changed similar to the
first one, but the second texts modification covers one more line.
@throws IOException
Test a case where we have three consecutive chunks. The first text
modifies all three chunks. The second text modifies the first and the
last chunk. This should be reported as one conflicting region.
@throws IOException
Test a merge where only the second text contains modifications. Expect as
merge result the second text.
@throws IOException
Both texts contain modifications but not on the same chunks. Expect a
non-conflict merge result.
@throws IOException
Merge two complicated modifications. The merge algorithm has to extend
and combine conflicting regions to get to the expected merge result.
@throws IOException
Test a conflicting region at the very start of the text.
@throws IOException
Test a conflicting region at the very end of the text.
@throws IOException
Test parsing of a commit whose encoding is given and works.
This is a twisted case, but show what we expect here. We can revise the
expectations provided this case is updated.
What happens here is that an encoding us given, but data is not encoded
that way (and we can detect it), so we try other encodings.
This is a twisted case too, but show what we expect here. We can revise the
expectations provided this case is updated.
What happens here is that an encoding us given, but data is not encoded
that way (and we can detect it), so we try other encodings. Here data could
actually be decoded in the stated encoding, but we override using UTF-8.
Test parsing of a commit whose encoding is given and works.
@throws Exception
This is a twisted case, but show what we expect here. We can revise the
expectations provided this case is updated.
What happens here is that an encoding us given, but data is not encoded
that way (and we can detect it), so we try other encodings.
@throws Exception
This is a twisted case too, but show what we expect here. We can revise
the expectations provided this case is updated.
What happens here is that an encoding us given, but data is not encoded
that way (and we can detect it), so we try other encodings. Here data
could actually be decoded in the stated encoding, but we override using
UTF-8.
@throws Exception
Incremental bundle test
@throws Exception
Test indexing one of the test packs in the egit repo. It has deltas.
This is just another pack. It so happens that we have two convenient pack to
test with in the repository.
use this method instead of the constructor to be sure that the underlying
VM provides all features needed by this class.
@return a new instance of {@link #CPUTimeStopWatch()} or
null if the VM does not support getting CPU time
information
Starts the stopwatch. If the stopwatch is already started this will
restart the stopwatch.
Stops the stopwatch and return the elapsed CPU time in nanoseconds.
Should be called only on started stopwatches.
@return the elapsed CPU time in nanoseconds. When called on non-started
stopwatches (either because {@link #start()} was never called or
{@link #stop()} was called after the last call to
{@link #start()}) this method will return 0.
Return the elapsed CPU time in nanoseconds. In contrast to
{@link #stop()} the stopwatch will continue to run after this call.
@return the elapsed CPU time in nanoseconds. When called on non-started
stopwatches (either because {@link #start()} was never called or
{@link #stop()} was called after the last call to
{@link #start()}) this method will return 0.
Wrap a repository with test building tools.
@param db
the test repository to write into.
@throws Exception
Wrap a repository with test building tools.
@param db
the test repository to write into.
@param rw
the RevObject pool to use for object lookup.
@throws Exception
@return the repository this helper class operates against.
@return get the RevWalk pool all objects are allocated through.
@return current time adjusted by {@link #tick(int)}.
Adjust the current time that will used by the next commit.
@param secDelta
number of seconds to add to the current time.
Create a new blob object in the repository.
@param content
file content, will be UTF-8 encoded.
@return reference to the blob.
@throws Exception
Create a new blob object in the repository.
@param content
binary file content.
@return reference to the blob.
@throws Exception
Construct a regular file mode tree entry.
@param path
path of the file.
@param blob
a blob, previously constructed in the repository.
@return the entry.
@throws Exception
Construct a tree from a specific listing of file entries.
@param entries
the files to include in the tree. The collection does not need
to be sorted properly and may be empty.
@return reference to the tree specified by the entry list.
@throws Exception
Lookup an entry stored in a tree, failing if not present.
@param tree
the tree to search.
@param path
the path to find the entry of.
@return the parsed object entry at this path, never null.
@throws AssertionFailedError
if the path does not exist in the given tree.
@throws Exception
Update a reference to point to an object.
@param ref
the name of the reference to update to. If {@code ref} does
not start with {@code refs/} and is not the magic names
{@code HEAD} {@code FETCH_HEAD} or {@code MERGE_HEAD}, then
{@code refs/heads/} will be prefixed in front of the given
name, thereby assuming it is a branch.
@param to
the target object.
@return the target object.
@throws Exception
Helper to build a branch with one or more commits
@return construct a new commit builder that updates this branch. If
the branch already exists, the commit builder will have its
first parent as the current commit and its tree will be
initialized to the current files.
@throws Exception
the commit builder can't read the current branch state
Forcefully update this branch to a particular commit.
@param to
the commit to update to.
@return {@code to}.
@throws Exception
Forcefully update this branch to a particular commit.
@param to
the commit to update to.
@return {@code to}.
@throws Exception
Helper to generate a commit.
Toy RNG to ensure we get predictable numbers during unit tests.
Return File with appropriate index version for prepared pack.
Return File with appropriate index version for prepared pack.
Verify CRC32 support.
Test contracts of Iterator methods and this implementation remove()
limitations.
Test results of iterator comparing to content of well-known (prepared)
small index.
Compare offset from iterator entries with output of findOffset() method.
Test partial results of iterator comparing to content of well-known
(prepared) dense index, that may need multi-level indexing.
Verify CRC32 - V1 should not index anything.
Verify CRC32 indexing.
Set up tested class instance, test constructor by the way.
Test findObject() for all index entries.
Test findObject() with illegal argument.
Test findNextOffset() for all index entries.
Test findNextOffset() with wrong illegal argument as offset.
Try to pass non-existing object as uninteresting, with ignoring setting.
Create pack basing on only interesting objects, then precisely verify
content. No delta reuse here.
Compare sizes of packs created using
and
.
The pack with delta bases written as offsets should be smaller.
Compare sizes of packs created using and
.
Obviously, the thin pack should be smaller.
Test constructor for exceptions, default settings, initialization.
Change default settings and verify them.
Try to pass non-existing object as uninteresting, with non-ignoring
setting.
Write empty pack by providing empty sets of interesting/uninteresting
objects and check for correct format.
Write empty pack by providing empty iterator of objects to write and
check for correct format.
Test writing pack without object reuse. Pack content/preparation as in
.
Create pack basing on both interesting and uninteresting objects, then
precisely verify content. No delta reuse here.
Test pack writing with delta reuse. Raw-data copy (reuse) is made on a
pack with CRC32 index. Pack configuration as in
.
Test pack writing with delta reuse. Delta bases referred as offsets. Pack
configuration as in .
Test pack writing with deltas reuse, delta-base first rule. Pack
content/preparation as in .
Compare sizes of packs created using and
. The pack using deltas should
be smaller.
Create pack basing on fixed objects list, then precisely verify content.
No delta reuse here.
Another pack creation: basing on both interesting and uninteresting
objects. No delta reuse possible here, as this is a specific case when we
write only 1 commit, associated with 1 tree, 1 blob.
Test thin pack writing: 1 blob delta base is on objects edge. Pack
configuration as in .
Misc tests for refs. A lot of things are tested elsewhere so not having a
test for a ref related method, does not mean it is untested.
Let an "outsider" Create a loose ref with the same name as a packed one
Modify a packed ref using the API. This creates a loose ref too, ie. LOOSE_PACKED
Delete a ref that is pointed to by HEAD
@throws IOException
Delete a loose ref and make sure the directory in refs is deleted too,
and the reflog dir too
@throws IOException
Try modify a ref forward, fast forward
@throws IOException
Delete a ref that exists both as packed and loose. Make sure the ref
cannot be resolved after delete.
@throws IOException
Try modify a ref to same
@throws IOException
Test case originating from
bug 285991
Make sure the in memory cache is updated properly after
update of symref. This one did not fail because the
ref was packed due to implementation issues.
@throws Exception
Test case originating from
bug 285991
Make sure the in memory cache is updated properly after
update of symref.
@throws Exception
Try modify a ref, but get wrong expected old value
@throws IOException
Try modify a ref forward, fast forward, checking old value first
@throws IOException
Try modify a ref forward, fast forward, checking old commit first
@throws IOException
Try modify a ref that is locked
@throws IOException
Try to delete a ref. Delete requires force.
@throws IOException
Empty tree
One file
two files
Empty tree
Empty tree
one file
two files
Empty tree
Empty tree
one file
two files
Empty tree