Browse Source

Zips of recreated hello-world.git and all external repositories for testing.

This hello-world.git repo is created using the native Git for Windows
software.

Various test classes in the GitBlitSuite test suite require the presence
of the hello-world.git repo in github.com/git/ which has been missing,
hence causing many test failures in the suite. This recreation of the
hello-world.git repo aims to conform to the many test cases'
requirements in the suite, and to be checked in as part of the gitblit
repo, thus eliminates the requirement of a remote hello-world.git repo
during the test run. The repo is now stored is a zip ball in the new
src/test/data folder.

The hello-world repo's various commit IDs were hard-coded in various
test classes. These commit IDs, which must now have new values in the
recreated repo, are now extracted out to the
src/test/data/hello-world.properties file. The gitblit's build.xml is
modified to generate the HelloworldKeys.java file containing the
hello-world.properties file's key strings, in similar fashion as the
existing generation of the com.gitblit.Keys.java file. And these key
strings in HelloworldKeys.java are now used in the various test classes,
thus eliminating the hard-coding of the hello-world repo's commit IDs in
the test code.

During the test run by GitBlitSuite test suite, some repos from GitHub
were cloned and became part of the test data. These repos are now zipped
to be part of gitblit repo itself, thus eliminating the network fetch at
the start of test run which can be slow, especially with the JGit repo
cloning which is huge and time consuming. The cloned JGit repo is now
zipped and checked in to gitblit, along with the other 4 repos
(hello-world, ambition, gitective and ticgit). They will be unzipped
during the test suite run and be available in the local file system,
thus avoiding the need for some network fetch.

Special note on the zipped JGit repo: this repo is big (and growing all
the time on GitHub), and takes up about 32MB of disk space after cloning
from GitHub. I've made it smaller by resetting HEAD back to a commit of
5 years ago (with git reset --hard <commitId> command), to put it back
to roughly where/when the tests were written for it (which is not quite,
because there are tons of commit history since which can't be removed.)
The local JGit repo is then garbage-collected (with git gc --prune
--aggressive) to reduce its size to about 19MB.

Zipped it is still 17MB. This is a lot of MBs for a few tests.
So the JGit repo is not included in this commit.

Fixes #1275
tags/r1.9.0
chirontt 5 years ago
parent
commit
c7bf84f79a

+ 5
- 0
build.xml View File

--> -->
<target name="test" depends="compile" description="compiles Gitblit from source and runs unit tests"> <target name="test" depends="compile" description="compiles Gitblit from source and runs unit tests">
<!-- Generate the HelloworldKeys class from the hello-world.properties file -->
<mx:keys propertiesfile="${basedir}/src/test/data/hello-world.properties"
outputclass="com.gitblit.tests.HelloworldKeys"
todir="${basedir}/src/test/java" />
<!-- Compile unit tests --> <!-- Compile unit tests -->
<mx:javac scope="test" /> <mx:javac scope="test" />

+ 1
- 0
src/test/data/.gitignore View File

/*.git/

BIN
src/test/data/ambition.git.zip View File


BIN
src/test/data/gitective.git.zip View File


BIN
src/test/data/hello-world.git.zip View File


+ 9
- 0
src/test/data/hello-world.properties View File

commit.first=192cdede1cc81da7b393aeb7aba9f88998b04713
commit.second=8caad51
commit.fifth=55f6796044dc51f0bb9301f07920f0fb64c3d12c
commit.fifteen=5ebfaca
commit.added=192cded
commit.changed=b2c50ce
commit.deleted=8613bee10bde27a0fbaca66447cdc3f0f9483365
users.byEmail=9
users.byName=8

BIN
src/test/data/ticgit.git.zip View File


+ 1
- 0
src/test/java/com/gitblit/tests/.gitignore View File

/HelloworldKeys.java

+ 11
- 11
src/test/java/com/gitblit/tests/DiffUtilsTest.java View File

public void testParentCommitDiff() throws Exception { public void testParentCommitDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content; String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close(); repository.close();
assertTrue(diff != null && diff.length() > 0); assertTrue(diff != null && diff.length() > 0);
public void testArbitraryCommitDiff() throws Exception { public void testArbitraryCommitDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository, RevCommit baseCommit = JGitUtils.getCommit(repository,
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content; String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close(); repository.close();
assertTrue(diff != null && diff.length() > 0); assertTrue(diff != null && diff.length() > 0);
public void testPlainFileDiff() throws Exception { public void testPlainFileDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content; String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close(); repository.close();
assertTrue(diff != null && diff.length() > 0); assertTrue(diff != null && diff.length() > 0);
public void testFilePatch() throws Exception { public void testFilePatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java"); String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java");
repository.close(); repository.close();
assertTrue(patch != null && patch.length() > 0); assertTrue(patch != null && patch.length() > 0);
public void testArbitraryFilePatch() throws Exception { public void testArbitraryFilePatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository, RevCommit baseCommit = JGitUtils.getCommit(repository,
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java"); String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java");
repository.close(); repository.close();
assertTrue(patch != null && patch.length() > 0); assertTrue(patch != null && patch.length() > 0);
public void testArbitraryCommitPatch() throws Exception { public void testArbitraryCommitPatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository, RevCommit baseCommit = JGitUtils.getCommit(repository,
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null); String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null);
repository.close(); repository.close();
assertTrue(patch != null && patch.length() > 0); assertTrue(patch != null && patch.length() > 0);
public void testBlame() throws Exception { public void testBlame() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java", List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
repository.close(); repository.close();
assertTrue(lines.size() > 0); assertTrue(lines.size() > 0);
assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
assertEquals(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first), lines.get(0).commitId);
} }
} }

+ 89
- 5
src/test/java/com/gitblit/tests/GitBlitSuite.java View File

package com.gitblit.tests; package com.gitblit.tests;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
import com.gitblit.FileSettings;
import com.gitblit.GitBlitException; import com.gitblit.GitBlitException;
import com.gitblit.GitBlitServer; import com.gitblit.GitBlitServer;
import com.gitblit.manager.IRepositoryManager; import com.gitblit.manager.IRepositoryManager;
public static final File USERSCONF = new File("src/test/config/test-users.conf"); public static final File USERSCONF = new File("src/test/config/test-users.conf");
private static final File AMBITION_REPO_SOURCE = new File("src/test/data/ambition.git");
private static final File TICGIT_REPO_SOURCE = new File("src/test/data/ticgit.git");
private static final File GITECTIVE_REPO_SOURCE = new File("src/test/data/gitective.git");
private static final File HELLOWORLD_REPO_SOURCE = new File("src/test/data/hello-world.git");
private static final File HELLOWORLD_REPO_PROPERTIES = new File("src/test/data/hello-world.properties");
public static final FileSettings helloworldSettings = new FileSettings(HELLOWORLD_REPO_PROPERTIES.getAbsolutePath());
static int port = 8280; static int port = 8280;
static int gitPort = 8300; static int gitPort = 8300;
static int shutdownPort = 8281; static int shutdownPort = 8281;
Thread.sleep(5000); Thread.sleep(5000);
} }
public static void deleteRefChecksFolder() throws IOException {
File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks");
if (refChecks.exists()) {
FileUtils.delete(refChecks, FileUtils.RECURSIVE | FileUtils.RETRY);
}
}
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
//"refchecks" folder is used in GitServletTest;
//need be deleted before Gitblit server instance is started
deleteRefChecksFolder();
startGitblit(); startGitblit();
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) { if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
cloneOrFetch("ticgit.git", "https://github.com/schacon/ticgit.git");
if (!HELLOWORLD_REPO_SOURCE.exists()) {
unzipRepository(HELLOWORLD_REPO_SOURCE.getPath() + ".zip", HELLOWORLD_REPO_SOURCE.getParentFile());
}
if (!TICGIT_REPO_SOURCE.exists()) {
unzipRepository(TICGIT_REPO_SOURCE.getPath() + ".zip", TICGIT_REPO_SOURCE.getParentFile());
}
if (!AMBITION_REPO_SOURCE.exists()) {
unzipRepository(AMBITION_REPO_SOURCE.getPath() + ".zip", AMBITION_REPO_SOURCE.getParentFile());
}
if (!GITECTIVE_REPO_SOURCE.exists()) {
unzipRepository(GITECTIVE_REPO_SOURCE.getPath() + ".zip", GITECTIVE_REPO_SOURCE.getParentFile());
}
cloneOrFetch("helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("ticgit.git", TICGIT_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git"); cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
cloneOrFetch("test/ambition.git", "https://github.com/defunkt/ambition.git");
cloneOrFetch("test/gitective.git", "https://github.com/kevinsawicki/gitective.git");
cloneOrFetch("test/helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/ambition.git", AMBITION_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/gitective.git", GITECTIVE_REPO_SOURCE.getAbsolutePath());
showRemoteBranches("ticgit.git"); showRemoteBranches("ticgit.git");
automaticallyTagBranchTips("ticgit.git"); automaticallyTagBranchTips("ticgit.git");
r.close(); r.close();
} }
} }
private static void unzipRepository(String zippedRepo, File destDir) throws IOException {
System.out.print("Unzipping " + zippedRepo + "... ");
if (!destDir.exists()) {
destDir.mkdir();
}
byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(zippedRepo));
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry);
if (zipEntry.isDirectory()) {
newFile.mkdirs();
}
else {
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
System.out.println("done.");
}
private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());
String destDirPath = destinationDir.getCanonicalPath();
String destFilePath = destFile.getCanonicalPath();
//guards against writing files to the file system outside of the target folder
//to prevent Zip Slip exploit
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}
return destFile;
}
} }

+ 23
- 23
src/test/java/com/gitblit/tests/GroovyScriptTest.java View File

MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git"); RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.customFields = new HashMap<String,String>(); repository.customFields = new HashMap<String,String>();
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git"); RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git"); repository.mailingLists.add("list@helloworld.git");
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git"); RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git"); repository.mailingLists.add("list@helloworld.git");
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/tags/v1.0"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
ReceiveCommand command = new ReceiveCommand(ObjectId ReceiveCommand command = new ReceiveCommand(ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/heads/master"); "refs/heads/master");
commands.add(command); commands.add(command);
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/heads/other")); "refs/heads/other"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
ReceiveCommand command = new ReceiveCommand(ObjectId ReceiveCommand command = new ReceiveCommand(ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/tags/v1.0"); "refs/tags/v1.0");
commands.add(command); commands.add(command);
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());

+ 6
- 5
src/test/java/com/gitblit/tests/JGitUtilsTest.java View File

Date firstChange = JGitUtils.getFirstChange(repository, null); Date firstChange = JGitUtils.getFirstChange(repository, null);
repository.close(); repository.close();
assertNotNull("Could not get first commit!", commit); assertNotNull("Could not get first commit!", commit);
assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",
assertEquals("Incorrect first commit!",
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first),
commit.getName()); commit.getName());
assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L))); assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
} }
public void testFilesInCommit() throws Exception { public void testFilesInCommit() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifteen));
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit); List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit);
commit = JGitUtils.getCommit(repository, "af0e9b2891fda85afc119f04a69acf7348922830");
commit = JGitUtils.getCommit(repository, GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted));
List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit); List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit);
commit = JGitUtils.getFirstCommit(repository, null); commit = JGitUtils.getFirstCommit(repository, null);
public void testRevLogRange() throws Exception { public void testRevLogRange() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
List<RevCommit> commits = JGitUtils.getRevLog(repository, List<RevCommit> commits = JGitUtils.getRevLog(repository,
"fbd14fa6d1a01d4aefa1fca725792683800fc67e",
"85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second),
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifteen));
repository.close(); repository.close();
assertEquals(14, commits.size()); assertEquals(14, commits.size());
} }

+ 2
- 2
src/test/java/com/gitblit/tests/MetricUtilsTest.java View File

List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true); List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true);
List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false); List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false);
repository.close(); repository.close();
assertEquals("No author metrics found!", 9, byEmail.size());
assertEquals("No author metrics found!", 8, byName.size());
assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byEmail, -1), byEmail.size());
assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byName, -1), byName.size());
} }
} }

Loading…
Cancel
Save