diff options
author | James Moger <james.moger@gitblit.com> | 2011-06-07 19:08:24 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-06-07 19:08:24 -0400 |
commit | 16856603ec575718857768e2d18e455c95fd6ea4 (patch) | |
tree | 7369326e7de9dec82d80d63a671b54f3d69f8210 /tests | |
parent | f08c1ca55e1ffaef81f3d6514aa4bffa5d716c5b (diff) | |
download | gitblit-16856603ec575718857768e2d18e455c95fd6ea4.tar.gz gitblit-16856603ec575718857768e2d18e455c95fd6ea4.zip |
Documentation. Moved clone and fetch into JGitUtils. Create bare only.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/com/gitblit/tests/GitBlitSuite.java | 64 | ||||
-rw-r--r-- | tests/com/gitblit/tests/JGitUtilsTest.java | 22 |
2 files changed, 25 insertions, 61 deletions
diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java index fe201b8b..e13e1bbf 100644 --- a/tests/com/gitblit/tests/GitBlitSuite.java +++ b/tests/com/gitblit/tests/GitBlitSuite.java @@ -16,25 +16,20 @@ 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;
import com.gitblit.GitBlitException;
import com.gitblit.JettyLoginService;
import com.gitblit.models.RepositoryModel;
+import com.gitblit.utils.JGitUtils;
public class GitBlitSuite extends TestSetup {
public static final File REPOSITORIES = new File("git");
@@ -66,11 +61,11 @@ public class GitBlitSuite extends TestSetup { }
public static Repository getJGitRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "nested/jgit.git"));
+ return new FileRepository(new File(REPOSITORIES, "test/jgit.git"));
}
public static Repository getBluezGnomeRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "nested/bluez-gnome.git"));
+ return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git"));
}
@Override
@@ -82,51 +77,24 @@ public class GitBlitSuite extends TestSetup { GitBlit.self().setLoginService(loginService);
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
- cloneOrFetch("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);
+ cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
+ cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git");
+ cloneOrFetch("test/bluez-gnome.git",
+ "https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git");
+ cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
+ cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
enableTickets("ticgit.git");
enableDocs("ticgit.git");
showRemoteBranches("ticgit.git");
- showRemoteBranches("nested/jgit.git");
+ showRemoteBranches("test/jgit.git");
}
}
- private void cloneOrFetch(String toFolder, String fromUrl, boolean bare) throws Exception {
- File folder = new File(REPOSITORIES, toFolder + (bare ? "" : "/.git"));
- if (folder.exists()) {
- System.out.print("Updating " + (bare ? "bare " : " ") + toFolder + "... ");
- 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.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 cloneOrFetch(String name, String fromUrl) throws Exception {
+ System.out.print("Fetching " + name + "... ");
+ JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl);
+ System.out.println("done.");
}
private void enableTickets(String repositoryName) {
@@ -138,7 +106,7 @@ public class GitBlitSuite extends TestSetup { g.printStackTrace();
}
}
-
+
private void enableDocs(String repositoryName) {
try {
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
@@ -148,7 +116,7 @@ public class GitBlitSuite extends TestSetup { g.printStackTrace();
}
}
-
+
private void showRemoteBranches(String repositoryName) {
try {
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
diff --git a/tests/com/gitblit/tests/JGitUtilsTest.java b/tests/com/gitblit/tests/JGitUtilsTest.java index 6646bf80..277166cf 100644 --- a/tests/com/gitblit/tests/JGitUtilsTest.java +++ b/tests/com/gitblit/tests/JGitUtilsTest.java @@ -30,7 +30,9 @@ import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.util.FS;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
@@ -94,16 +96,10 @@ public class JGitUtilsTest extends TestCase { public void testCreateRepository() throws Exception {
String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
- for (String repositoryName : repositories) {
- boolean isBare = repositoryName.endsWith(".git");
+ for (String repositoryName : repositories) {
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
- repositoryName, isBare);
- File folder;
- if (isBare) {
- folder = new File(GitBlitSuite.REPOSITORIES, repositoryName);
- } else {
- folder = new File(GitBlitSuite.REPOSITORIES, repositoryName + "/.git");
- }
+ repositoryName);
+ File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName), FS.DETECTED);
assertTrue(repository != null);
assertFalse(JGitUtils.hasCommits(repository));
assertTrue(JGitUtils.getFirstCommit(repository, null) == null);
@@ -138,7 +134,7 @@ public class JGitUtilsTest extends TestCase { }
public void testBranches() throws Exception {
- Repository repository = GitBlitSuite.getTicgitRepository();
+ Repository repository = GitBlitSuite.getJGitRepository();
for (RefModel model : JGitUtils.getLocalBranches(repository, true, -1)) {
assertTrue(model.getName().startsWith(Constants.R_HEADS));
assertTrue(model.equals(model));
@@ -155,14 +151,14 @@ public class JGitUtilsTest extends TestCase { + model.getName().hashCode());
assertTrue(model.getShortMessage().equals(model.getShortMessage()));
}
- assertTrue(JGitUtils.getRemoteBranches(repository, true, 10).size() == 10);
+ assertTrue(JGitUtils.getRemoteBranches(repository, true, 8).size() == 8);
repository.close();
}
public void testTags() throws Exception {
- Repository repository = GitBlitSuite.getTicgitRepository();
+ Repository repository = GitBlitSuite.getJGitRepository();
for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
- if (model.getObjectId().getName().equals("283035e4848054ff1803cb0e690270787dc92399")) {
+ if (model.getObjectId().getName().equals("d28091fb2977077471138fe97da1440e0e8ae0da")) {
assertTrue("Not an annotated tag!", model.isAnnotatedTag());
}
assertTrue(model.getName().startsWith(Constants.R_TAGS));
|