Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/org/libgit2/jagged/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public enum Mode
FILE(0100644),

/** A file with the executable bit set */
EXECUTABLE_FILE(0100755);
EXECUTABLE_FILE(0100755),

/** A directory/tree */
TREE(0040000);

private final int value;

Expand Down
22 changes: 11 additions & 11 deletions src/test/java/org/libgit2/jagged/CommitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void testLookupCommit()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("055fe18dd1aef07991ebd08b4d54fc761dd022fb");
ObjectId oid = new ObjectId(FIRST_COMMIT_ID);
Commit commit = repository.lookup(oid);

Assert.assertEquals(oid, commit.getId());
Expand All @@ -30,11 +30,11 @@ public void testGetCommitter()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("055fe18dd1aef07991ebd08b4d54fc761dd022fb");
ObjectId oid = new ObjectId(FIRST_COMMIT_ID);
Commit commit = repository.lookup(oid);

Assert.assertEquals("Edward Thomson", commit.getCommitter().getName());
Assert.assertEquals("ethomson@microsoft.com", commit.getCommitter().getEmail());
Assert.assertEquals(AUTHOR_NAME, commit.getCommitter().getName());
Assert.assertEquals(AUTHOR_EMAIL, commit.getCommitter().getEmail());

repository.close();
}
Expand All @@ -45,11 +45,11 @@ public void testGetAuthor()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("5eab02d63a3676df528bcd878ac935ec0c4d5bdc");
ObjectId oid = new ObjectId(SECOND_COMMIT_ID);
Commit commit = repository.lookup(oid);

Assert.assertEquals("Edward Thomson", commit.getAuthor().getName());
Assert.assertEquals("ethomson@microsoft.com", commit.getAuthor().getEmail());
Assert.assertEquals(AUTHOR_NAME, commit.getAuthor().getName());
Assert.assertEquals(AUTHOR_EMAIL, commit.getAuthor().getEmail());

repository.close();
}
Expand All @@ -60,12 +60,12 @@ public void testGetParents()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId parentOid = new ObjectId("055fe18dd1aef07991ebd08b4d54fc761dd022fb");
ObjectId parentOid = new ObjectId(FIRST_COMMIT_ID);
Commit parent = repository.lookup(parentOid);

Assert.assertEquals(false, parent.getParents().iterator().hasNext());

ObjectId childOid = new ObjectId("5eab02d63a3676df528bcd878ac935ec0c4d5bdc");
ObjectId childOid = new ObjectId(SECOND_COMMIT_ID);
Commit child = repository.lookup(childOid);

Iterator<Commit> parents = child.getParents().iterator();
Expand All @@ -82,10 +82,10 @@ public void testGetTree()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("055fe18dd1aef07991ebd08b4d54fc761dd022fb");
ObjectId oid = new ObjectId(FIRST_COMMIT_ID);
Commit commit = repository.lookup(oid);

Tree tree = repository.lookup(new ObjectId("e77ab1c63f3fbde9c5ef9972939aa0717012d7c0"));
Tree tree = repository.lookup(new ObjectId("ff77323c5557be69500eb91efa418074fd3f0443"));

Assert.assertEquals(tree, commit.getTree());

Expand Down
61 changes: 9 additions & 52 deletions src/test/java/org/libgit2/jagged/GitTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package org.libgit2.jagged;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.text.MessageFormat;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.libgit2.jagged.core.NativeTestMethods;

public abstract class GitTest
{
private static File resourcesRoot;
public static String FIRST_COMMIT_ID = "de6e275694ca4b8850f380650cf6e4e26169d15f";
public static String SECOND_COMMIT_ID = "3dcee60faede7e1acf6058345a29748ae31f74bc";
public static String AUTHOR_NAME = "T. E. Ster";
public static String AUTHOR_EMAIL = "tester@domain.com";

private static File tempRoot;
private static File tempDir;
private static File tempConfigurationDir;
Expand All @@ -24,13 +26,6 @@ public abstract class GitTest
{
File systemTempDir;

resourcesRoot = new File("src/test/resources");

if (!resourcesRoot.exists())
{
resourcesRoot = new File(GitTest.class.getResource("/testrepo").getFile()).getParentFile();
}

if (System.getenv("TMPDIR") != null)
{
systemTempDir = new File(System.getenv("TMPDIR"));
Expand Down Expand Up @@ -128,48 +123,10 @@ private static void cleanupDirectory(final File file)
}
}

private static File copyRecursive(final File source, final File target, final String item)
{
final String sourceItem = item;
final String targetItem = (item.equals(".gitted") ? ".git" : item);

final File sourceFile = new File(source, sourceItem);
final File targetFile = new File(target, targetItem);

if (sourceFile.isDirectory())
{
targetFile.mkdir();

for (String child : sourceFile.list())
{
copyRecursive(sourceFile, targetFile, child);
}

return targetFile;
}
else
{
try
{
@SuppressWarnings("resource")
FileChannel sourceChannel = new FileInputStream(sourceFile).getChannel();
@SuppressWarnings("resource")
FileChannel targetChannel = new FileOutputStream(targetFile).getChannel();
targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
sourceChannel.close();
targetChannel.close();

return targetFile;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}

public File setupRepository(final String name)
{
return copyRecursive(resourcesRoot, tempDir, name);
File path = new File(tempDir, name);
NativeTestMethods.createTestRepository(path.getAbsolutePath().replace("\\", "/"), new Signature(AUTHOR_NAME, AUTHOR_EMAIL));
return path;
}
}
26 changes: 20 additions & 6 deletions src/test/java/org/libgit2/jagged/TreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void testLookupTree()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("e77ab1c63f3fbde9c5ef9972939aa0717012d7c0");
ObjectId oid = new ObjectId("ff77323c5557be69500eb91efa418074fd3f0443");
Tree tree = repository.lookup(oid);

Assert.assertEquals(oid, tree.getId());
Expand All @@ -30,10 +30,10 @@ public void testGetEntryCount()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("e77ab1c63f3fbde9c5ef9972939aa0717012d7c0");
ObjectId oid = new ObjectId("ff77323c5557be69500eb91efa418074fd3f0443");
Tree tree = repository.lookup(oid);

Assert.assertEquals(3, tree.getEntryCount());
Assert.assertEquals(5, tree.getEntryCount());

repository.close();
}
Expand All @@ -44,13 +44,27 @@ public void testGetEntries()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("e77ab1c63f3fbde9c5ef9972939aa0717012d7c0");
ObjectId oid = new ObjectId("ff77323c5557be69500eb91efa418074fd3f0443");
Tree tree = repository.lookup(oid);

Iterator<TreeEntry> iterator = tree.getEntries().iterator();

TreeEntry entry = iterator.next();

Assert.assertEquals(".gitattributes", entry.getName());
Assert.assertEquals(new ObjectId("176a458f94e0ea5272ce67c36bf30b6be9caf623"), entry.getId());
Assert.assertEquals(Mode.FILE, entry.getMode());
Assert.assertEquals(ObjectType.BLOB, entry.getType());

entry = iterator.next();

Assert.assertEquals("a", entry.getName());
Assert.assertEquals(new ObjectId("32ef2016c46507680e32272204b1095cdf232f5d"), entry.getId());
Assert.assertEquals(Mode.TREE, entry.getMode());
Assert.assertEquals(ObjectType.TREE, entry.getType());

entry = iterator.next();

Assert.assertEquals("one.txt", entry.getName());
Assert.assertEquals(new ObjectId("d1796967d47949153bb852c07304d9e5f2f0040c"), entry.getId());
Assert.assertEquals(Mode.FILE, entry.getMode());
Expand Down Expand Up @@ -81,7 +95,7 @@ public void testGetEntryByName()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("e77ab1c63f3fbde9c5ef9972939aa0717012d7c0");
ObjectId oid = new ObjectId("ff77323c5557be69500eb91efa418074fd3f0443");
Tree tree = repository.lookup(oid);

TreeEntry entry = tree.getEntry("one.txt");
Expand Down Expand Up @@ -114,7 +128,7 @@ public void testCanRealizeTreeEntry()
final File repoPath = setupRepository("testrepo");
Repository repository = new Repository(repoPath.getAbsolutePath());

ObjectId oid = new ObjectId("e77ab1c63f3fbde9c5ef9972939aa0717012d7c0");
ObjectId oid = new ObjectId("ff77323c5557be69500eb91efa418074fd3f0443");
Tree tree = repository.lookup(oid);

TreeEntry entry = tree.getEntry("one.txt");
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/libgit2/jagged/core/NativeTestMethods.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.libgit2.jagged.core;

import org.libgit2.jagged.Signature;

public class NativeTestMethods
{
static
Expand All @@ -20,4 +22,6 @@ public class NativeTestMethods
public static native void throwFormattedString2();

public static native void throwFormattedString3();

public static native void createTestRepository(String path, Signature signature);
}
Loading