diff options
author | James Moger <james.moger@gitblit.com> | 2011-06-03 17:44:19 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-06-03 17:44:19 -0400 |
commit | 4ab184198bd7eac67eb767cf2e19423f618a70ae (patch) | |
tree | 453994de502014616a35fef507b631f2b56fab4d /tests | |
parent | a125cf6876e0edc5a2498df57a9df06d60b1f572 (diff) | |
download | gitblit-4ab184198bd7eac67eb767cf2e19423f618a70ae.tar.gz gitblit-4ab184198bd7eac67eb767cf2e19423f618a70ae.zip |
GitNotes. Unit testing. More correct refs.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/com/gitblit/tests/GitBlitSuite.java | 40 | ||||
-rw-r--r-- | tests/com/gitblit/tests/JGitUtilsTest.java | 69 |
2 files changed, 86 insertions, 23 deletions
diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java index 97e46c9c..fe201b8b 100644 --- a/tests/com/gitblit/tests/GitBlitSuite.java +++ b/tests/com/gitblit/tests/GitBlitSuite.java @@ -16,15 +16,19 @@ package com.gitblit.tests;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.jgit.api.CloneCommand;
+import org.eclipse.jgit.api.FetchCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.transport.RefSpec;
import com.gitblit.FileSettings;
import com.gitblit.GitBlit;
@@ -61,6 +65,14 @@ public class GitBlitSuite extends TestSetup { return new FileRepository(new File(REPOSITORIES, "ticgit.git"));
}
+ public static Repository getJGitRepository() throws Exception {
+ return new FileRepository(new File(REPOSITORIES, "nested/jgit.git"));
+ }
+
+ public static Repository getBluezGnomeRepository() throws Exception {
+ return new FileRepository(new File(REPOSITORIES, "nested/bluez-gnome.git"));
+ }
+
@Override
protected void setUp() throws Exception {
FileSettings settings = new FileSettings("distrib/gitblit.properties");
@@ -71,12 +83,15 @@ public class GitBlitSuite extends TestSetup { if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git", true);
- cloneOrFetch("nested/helloworld.git", "https://github.com/git/hello-world.git", true);
cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git", true);
+ cloneOrFetch("nested/bluez-gnome.git", "https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git", true);
+ cloneOrFetch("nested/jgit.git", "https://github.com/eclipse/jgit.git", true);
+ cloneOrFetch("nested/helloworld.git", "https://github.com/git/hello-world.git", true);
enableTickets("ticgit.git");
enableDocs("ticgit.git");
showRemoteBranches("ticgit.git");
+ showRemoteBranches("nested/jgit.git");
}
}
@@ -84,22 +99,35 @@ public class GitBlitSuite extends TestSetup { File folder = new File(REPOSITORIES, toFolder + (bare ? "" : "/.git"));
if (folder.exists()) {
System.out.print("Updating " + (bare ? "bare " : " ") + toFolder + "... ");
- FileRepository repository = new FileRepository(new File(REPOSITORIES, toFolder));
- Git git = new Git(repository);
- git.fetch().call();
- repository.close();
+ fetch(toFolder);
System.out.println("done.");
} else {
System.out.println("Cloning " + (bare ? "bare " : " ") + toFolder + "... ");
CloneCommand clone = new CloneCommand();
clone.setBare(bare);
- clone.setCloneAllBranches(true);
+ clone.setCloneAllBranches(true);
clone.setURI(fromUrl);
clone.setDirectory(folder);
clone.call();
+ // Now we have to fetch because CloneCommand doesn't fetch
+ // Notes nor does it allow manual RefSpec.
+ fetch(toFolder);
System.out.println("done.");
}
}
+
+ private void fetch(String toFolder) throws Exception {
+ FileRepository repository = new FileRepository(new File(REPOSITORIES, toFolder));
+ Git git = new Git(repository);
+ FetchCommand fetch = git.fetch();
+ List<RefSpec> specs = new ArrayList<RefSpec>();
+ specs.add(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
+ specs.add(new RefSpec("+refs/tags/*:refs/tags/*"));
+ specs.add(new RefSpec("+refs/notes/*:refs/notes/*"));
+ fetch.setRefSpecs(specs);
+ fetch.call();
+ repository.close();
+ }
private void enableTickets(String repositoryName) {
try {
diff --git a/tests/com/gitblit/tests/JGitUtilsTest.java b/tests/com/gitblit/tests/JGitUtilsTest.java index 6afa38b2..7196afdf 100644 --- a/tests/com/gitblit/tests/JGitUtilsTest.java +++ b/tests/com/gitblit/tests/JGitUtilsTest.java @@ -34,11 +34,13 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.GitBlit;
import com.gitblit.Keys;
+import com.gitblit.models.GitNote;
import com.gitblit.models.PathModel;
import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.RefModel;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.JGitUtils.SearchType;
+import com.gitblit.utils.StringUtils;
public class JGitUtilsTest extends TestCase {
@@ -115,10 +117,24 @@ public class JGitUtilsTest extends TestCase { }
public void testRefs() throws Exception {
- Repository repository = GitBlitSuite.getTicgitRepository();
- Map<ObjectId, List<String>> map = JGitUtils.getAllRefs(repository);
+ Repository repository = GitBlitSuite.getJGitRepository();
+ Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);
repository.close();
assertTrue(map.size() > 0);
+ for (Map.Entry<ObjectId, List<RefModel>> entry : map.entrySet()) {
+ List<RefModel> list = entry.getValue();
+ for (RefModel ref : list) {
+ if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {
+ assertTrue(ref.getObjectId().getName().equals("8bbde7aacf771a9afb6992434f1ae413e010c6d8"));
+ assertTrue(ref.getAuthorIdent().getEmailAddress().equals("spearce@spearce.org"));
+ assertTrue(ref.getShortMessage().startsWith("GPG key"));
+ assertTrue(ref.getFullMessage().startsWith("GPG key"));
+ assertTrue(ref.getReferencedObjectType() == Constants.OBJ_BLOB);
+ } else if (ref.displayName.equals("refs/tags/v0.12.1")) {
+ assertTrue(ref.isAnnotatedTag());
+ }
+ }
+ }
}
public void testBranches() throws Exception {
@@ -127,17 +143,17 @@ public class JGitUtilsTest extends TestCase { assertTrue(model.getName().startsWith(Constants.R_HEADS));
assertTrue(model.equals(model));
assertFalse(model.equals(""));
- assertTrue(model.hashCode() == model.getCommitId().hashCode()
+ assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
+ model.getName().hashCode());
- assertTrue(model.getShortLog().equals(model.commit.getShortMessage()));
+ assertTrue(model.getShortMessage().equals(model.getShortMessage()));
}
for (RefModel model : JGitUtils.getRemoteBranches(repository, -1)) {
assertTrue(model.getName().startsWith(Constants.R_REMOTES));
assertTrue(model.equals(model));
assertFalse(model.equals(""));
- assertTrue(model.hashCode() == model.getCommitId().hashCode()
+ assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
+ model.getName().hashCode());
- assertTrue(model.getShortLog().equals(model.commit.getShortMessage()));
+ assertTrue(model.getShortMessage().equals(model.getShortMessage()));
}
assertTrue(JGitUtils.getRemoteBranches(repository, 10).size() == 10);
repository.close();
@@ -152,33 +168,52 @@ public class JGitUtilsTest extends TestCase { assertTrue(model.getName().startsWith(Constants.R_TAGS));
assertTrue(model.equals(model));
assertFalse(model.equals(""));
- assertTrue(model.hashCode() == model.getCommitId().hashCode()
+ assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
+ model.getName().hashCode());
- assertTrue(model.getShortLog().equals(model.commit.getShortMessage()));
+ }
+ repository.close();
+
+ repository = GitBlitSuite.getBluezGnomeRepository();
+ for (RefModel model : JGitUtils.getTags(repository, -1)) {
+ if (model.getObjectId().getName().equals("728643ec0c438c77e182898c2f2967dbfdc231c8")) {
+ assertFalse(model.isAnnotatedTag());
+ assertTrue(model.getAuthorIdent().getEmailAddress().equals("marcel@holtmann.org"));
+ assertTrue(model.getFullMessage().equals("Update changelog and bump version number\n"));
+ }
}
repository.close();
}
public void testCommitNotes() throws Exception {
-// Repository repository = new FileRepository(new File("c:/projects/git/jgit.git/.git"));
-// RevCommit commit = JGitUtils.getCommit(repository,
-// "ada903085d1b4ef8c79e3e2d91f49fee7e188f53");
-// List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
-// repository.close();
-// assertTrue(list.size() > 0);
+ Repository repository = GitBlitSuite.getJGitRepository();
+ RevCommit commit = JGitUtils.getCommit(repository,
+ "690c268c793bfc218982130fbfc25870f292295e");
+ List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
+ repository.close();
+ assertTrue(list.size() > 0);
+ assertTrue(list.get(0).notesRef.getReferencedObjectId().getName()
+ .equals("183474d554e6f68478a02d9d7888b67a9338cdff"));
}
public void testStringContent() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
- String contentA = JGitUtils.getRawContentAsString(repository, null, "java.java");
+ String contentA = JGitUtils.getStringContent(repository, null, "java.java");
RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);
- String contentB = JGitUtils.getRawContentAsString(repository, commit, "java.java");
- String contentC = JGitUtils.getRawContentAsString(repository, commit, "missing.txt");
+ String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");
+ String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");
+
+ // manually construct a blob, calculate the hash, lookup the hash in git
+ StringBuilder sb = new StringBuilder();
+ sb.append("blob ").append(contentA.length()).append('\0');
+ sb.append(contentA);
+ String sha1 = StringUtils.getSHA1(sb.toString());
+ String contentD = JGitUtils.getStringContent(repository, sha1);
repository.close();
assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);
assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);
assertTrue(contentA.equals(contentB));
assertTrue(contentC == null);
+ assertTrue(contentA.equals(contentD));
}
public void testFilesInCommit() throws Exception {
|