summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-03-11 12:36:30 -0400
committerJames Moger <james.moger@gitblit.com>2014-03-11 12:36:30 -0400
commit66a5e2c8a12243557d39ba9e562f52d52e991781 (patch)
tree0845c086d34348eff3b1572be87354401c59f742
parent16a739b35838da85d2194493a6764631c344adac (diff)
downloadgitblit-66a5e2c8a12243557d39ba9e562f52d52e991781.tar.gz
gitblit-66a5e2c8a12243557d39ba9e562f52d52e991781.zip
Exclude ticket branches when forking a canonical repository
-rw-r--r--src/main/java/com/gitblit/manager/GitblitManager.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java
index b27d650d..b6c2b474 100644
--- a/src/main/java/com/gitblit/manager/GitblitManager.java
+++ b/src/main/java/com/gitblit/manager/GitblitManager.java
@@ -33,7 +33,12 @@ import java.util.TimeZone;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jgit.api.CloneCommand;
+import org.eclipse.jgit.api.FetchCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.RefSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,7 +70,6 @@ import com.gitblit.models.UserModel;
import com.gitblit.tickets.ITicketService;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.HttpUtils;
-import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.JsonUtils;
import com.gitblit.utils.ObjectCache;
import com.gitblit.utils.StringUtils;
@@ -159,7 +163,33 @@ public class GitblitManager implements IGitblit {
// clone the repository
try {
- JGitUtils.cloneRepository(repositoryManager.getRepositoriesFolder(), cloneName, fromUrl, true, null);
+ Repository canonical = getRepository(repository.name);
+ File folder = new File(repositoryManager.getRepositoriesFolder(), cloneName);
+ CloneCommand clone = new CloneCommand();
+ clone.setBare(true);
+
+ // fetch branches with exclusions
+ Collection<Ref> branches = canonical.getRefDatabase().getRefs(Constants.R_HEADS).values();
+ List<String> branchesToClone = new ArrayList<String>();
+ for (Ref branch : branches) {
+ String name = branch.getName();
+ if (name.startsWith(Constants.R_TICKET)) {
+ // exclude ticket branches
+ continue;
+ }
+ branchesToClone.add(name);
+ }
+ clone.setBranchesToClone(branchesToClone);
+ clone.setURI(fromUrl);
+ clone.setDirectory(folder);
+ Git git = clone.call();
+
+ // fetch tags
+ FetchCommand fetch = git.fetch();
+ fetch.setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*"));
+ fetch.call();
+
+ git.getRepository().close();
} catch (Exception e) {
throw new GitBlitException(e);
}