James Moger
2011-06-03 4ab184198bd7eac67eb767cf2e19423f618a70ae
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 @@
      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 @@
      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,10 +99,7 @@
      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 + "... ");
@@ -97,10 +109,26 @@
         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 {
         RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);