From ab07d0d86d8b64b4f7c88b45bc81f1eec22105db Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Thu, 10 Apr 2014 19:00:05 -0400 Subject: [PATCH] Preserve key index when re-adding an existing key --- src/main/java/com/gitblit/manager/GitblitManager.java | 92 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java index 08d6408..0001706 100644 --- a/src/main/java/com/gitblit/manager/GitblitManager.java +++ b/src/main/java/com/gitblit/manager/GitblitManager.java @@ -33,9 +33,16 @@ 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; + +import ro.fortsoft.pf4j.PluginWrapper; import com.gitblit.Constants; import com.gitblit.Constants.AccessPermission; @@ -62,9 +69,11 @@ import com.gitblit.models.SettingModel; import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; +import com.gitblit.tickets.ITicketService; +import com.gitblit.transport.ssh.IPublicKeyManager; +import com.gitblit.transport.ssh.SshKey; 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; @@ -95,11 +104,15 @@ protected final IRuntimeManager runtimeManager; + protected final IPluginManager pluginManager; + protected final INotificationManager notificationManager; protected final IUserManager userManager; protected final IAuthenticationManager authenticationManager; + + protected final IPublicKeyManager publicKeyManager; protected final IRepositoryManager repositoryManager; @@ -109,18 +122,22 @@ public GitblitManager( IRuntimeManager runtimeManager, + IPluginManager pluginManager, INotificationManager notificationManager, IUserManager userManager, IAuthenticationManager authenticationManager, + IPublicKeyManager publicKeyManager, IRepositoryManager repositoryManager, IProjectManager projectManager, IFederationManager federationManager) { this.settings = runtimeManager.getSettings(); this.runtimeManager = runtimeManager; + this.pluginManager = pluginManager; this.notificationManager = notificationManager; this.userManager = userManager; this.authenticationManager = authenticationManager; + this.publicKeyManager = publicKeyManager; this.repositoryManager = repositoryManager; this.projectManager = projectManager; this.federationManager = federationManager; @@ -158,7 +175,33 @@ // 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); } @@ -483,6 +526,20 @@ } } + /** + * Throws an exception if trying to get a ticket service. + * + */ + @Override + public ITicketService getTicketService() { + throw new RuntimeException("This class does not have a ticket service!"); + } + + @Override + public IPublicKeyManager getPublicKeyManager() { + return publicKeyManager; + } + /* * ISTOREDSETTINGS * @@ -611,6 +668,12 @@ } return user; } + + @Override + public UserModel authenticate(String username, SshKey key) { + return authenticationManager.authenticate(username, key); + } + @Override public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) { UserModel user = authenticationManager.authenticate(httpRequest, requiresCertificate); @@ -1099,4 +1162,29 @@ public boolean deletePendingFederationProposal(FederationProposal proposal) { return federationManager.deletePendingFederationProposal(proposal); } + + @Override + public void closeAll() { + repositoryManager.closeAll(); + } + + @Override + public void close(String repository) { + repositoryManager.close(repository); + } + + @Override + public boolean isIdle(Repository repository) { + return repositoryManager.isIdle(repository); + } + + @Override + public <T> List<T> getExtensions(Class<T> clazz) { + return pluginManager.getExtensions(clazz); + } + + @Override + public PluginWrapper whichPlugin(Class<?> clazz) { + return pluginManager.whichPlugin(clazz); + } } -- Gitblit v1.9.1