summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-09-26 15:33:19 -0400
committerJames Moger <james.moger@gitblit.com>2011-09-26 15:33:19 -0400
commitf6740d55ff80bc6e16da5c3df0ee1ba2235d6629 (patch)
tree55e3fe4e47dc6b4bd74636a95e833d6dc1c7dd7e /src
parentd7fb202c122faa90a75717cbd66791d3879b5776 (diff)
downloadgitblit-f6740d55ff80bc6e16da5c3df0ee1ba2235d6629.tar.gz
gitblit-f6740d55ff80bc6e16da5c3df0ee1ba2235d6629.zip
Implemented a Federation Client. Bare clone tweaks. Documentation.
Diffstat (limited to 'src')
-rw-r--r--src/com/gitblit/FederationClient.java133
-rw-r--r--src/com/gitblit/FederationClientLauncher.java54
-rw-r--r--src/com/gitblit/FederationPullExecutor.java54
-rw-r--r--src/com/gitblit/GitBlit.java87
-rw-r--r--src/com/gitblit/GitBlitServer.java2
-rw-r--r--src/com/gitblit/build/Build.java13
-rw-r--r--src/com/gitblit/models/FederationModel.java2
-rw-r--r--src/com/gitblit/utils/FederationUtils.java93
-rw-r--r--src/com/gitblit/utils/JGitUtils.java21
9 files changed, 367 insertions, 92 deletions
diff --git a/src/com/gitblit/FederationClient.java b/src/com/gitblit/FederationClient.java
new file mode 100644
index 00000000..daa9bfbf
--- /dev/null
+++ b/src/com/gitblit/FederationClient.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.beust.jcommander.Parameters;
+import com.gitblit.models.FederationModel;
+import com.gitblit.utils.FederationUtils;
+import com.gitblit.utils.StringUtils;
+
+/**
+ * Command-line client to pull federated Gitblit repositories.
+ *
+ * @author James Moger
+ *
+ */
+public class FederationClient {
+
+ public static void main(String[] args) {
+ Params params = new Params();
+ JCommander jc = new JCommander(params);
+ try {
+ jc.parse(args);
+ } catch (ParameterException t) {
+ usage(jc, t);
+ }
+
+ IStoredSettings settings = new FileSettings(params.registrationsFile);
+ List<FederationModel> registrations = new ArrayList<FederationModel>();
+ if (StringUtils.isEmpty(params.url)) {
+ registrations.addAll(FederationUtils.getFederationRegistrations(settings));
+ } else {
+ if (StringUtils.isEmpty(params.token)) {
+ System.out.println("Must specify --token parameter!");
+ System.exit(0);
+ }
+ FederationModel model = new FederationModel("Gitblit");
+ model.url = params.url;
+ model.token = params.token;
+ model.mirror = params.mirror;
+ model.bare = params.bare;
+ model.frequency = params.frequency;
+ model.folder = "";
+ registrations.add(model);
+ }
+ if (registrations.size() == 0) {
+ System.out.println("No Federation Registrations! Nothing to do.");
+ System.exit(0);
+ }
+
+ System.out.println("Gitblit Federation Client v" + Constants.VERSION + " (" + Constants.VERSION_DATE + ")");
+
+ // command-line specified repositories folder
+ if (!StringUtils.isEmpty(params.repositoriesFolder)) {
+ settings.overrideSetting(Keys.git.repositoriesFolder, new File(
+ params.repositoriesFolder).getAbsolutePath());
+ }
+
+ // configure the Gitblit singleton for minimal, non-server operation
+ GitBlit.self().configureContext(settings, false);
+ FederationPullExecutor executor = new FederationPullExecutor(registrations, params.isDaemon);
+ executor.run();
+ if (!params.isDaemon) {
+ System.out.println("Finished.");
+ System.exit(0);
+ }
+ }
+
+ private static void usage(JCommander jc, ParameterException t) {
+ System.out.println(Constants.getGitBlitVersion());
+ System.out.println();
+ if (t != null) {
+ System.out.println(t.getMessage());
+ System.out.println();
+ }
+
+ if (jc != null) {
+ jc.usage();
+ }
+ System.exit(0);
+ }
+
+ /**
+ * JCommander Parameters class for FederationClient.
+ */
+ @Parameters(separators = " ")
+ private static class Params {
+
+ @Parameter(names = { "--registrations" }, description = "Gitblit Federation Registrations File", required = false)
+ public String registrationsFile = "federation.properties";
+
+ @Parameter(names = { "--daemon" }, description = "Runs in daemon mode to schedule and pull repositories", required = false)
+ public boolean isDaemon;
+
+ @Parameter(names = { "--url" }, description = "URL of Gitblit instance to mirror from", required = false)
+ public String url;
+
+ @Parameter(names = { "--mirror" }, description = "Mirror repositories", required = false)
+ public boolean mirror;
+
+ @Parameter(names = { "--bare" }, description = "Create bare repositories", required = false)
+ public boolean bare;
+
+ @Parameter(names = { "--token" }, description = "Federation Token", required = false)
+ public String token;
+
+ @Parameter(names = { "--frequency" }, description = "Period to wait between pull attempts (requires --daemon)", required = false)
+ public String frequency = "60 mins";
+
+ @Parameter(names = { "--repositoriesFolder" }, description = "Destination folder for cloned repositories", required = false)
+ public String repositoriesFolder;
+
+ }
+}
diff --git a/src/com/gitblit/FederationClientLauncher.java b/src/com/gitblit/FederationClientLauncher.java
new file mode 100644
index 00000000..80f5a3d9
--- /dev/null
+++ b/src/com/gitblit/FederationClientLauncher.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+import com.gitblit.build.Build;
+
+/**
+ * Downloads dependencies and launches command-line Federation client.
+ *
+ * @author James Moger
+ *
+ */
+public class FederationClientLauncher {
+
+ public static void main(String[] args) {
+ // download federation client runtime dependencies
+ Build.federationClient();
+
+ File libFolder = new File("ext");
+ List<File> jars = Launcher.findJars(libFolder.getAbsoluteFile());
+
+ // sort the jars by name and then reverse the order so the newer version
+ // of the library gets loaded in the event that this is an upgrade
+ Collections.sort(jars);
+ Collections.reverse(jars);
+ for (File jar : jars) {
+ try {
+ Launcher.addJarFile(jar);
+ } catch (IOException e) {
+
+ }
+ }
+
+ FederationClient.main(args);
+ }
+}
diff --git a/src/com/gitblit/FederationPullExecutor.java b/src/com/gitblit/FederationPullExecutor.java
index f27ea3c2..ef089d03 100644
--- a/src/com/gitblit/FederationPullExecutor.java
+++ b/src/com/gitblit/FederationPullExecutor.java
@@ -15,6 +15,8 @@
*/
package com.gitblit;
+import static org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;
+
import java.io.File;
import java.io.FileOutputStream;
import java.net.InetAddress;
@@ -23,14 +25,17 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.slf4j.Logger;
@@ -57,6 +62,8 @@ public class FederationPullExecutor implements Runnable {
private final List<FederationModel> registrations;
+ private final boolean isDaemon;
+
/**
* Constructor for specifying a single federation registration. This
* constructor is used to schedule the next pull execution.
@@ -64,7 +71,7 @@ public class FederationPullExecutor implements Runnable {
* @param registration
*/
private FederationPullExecutor(FederationModel registration) {
- this(Arrays.asList(registration));
+ this(Arrays.asList(registration), true);
}
/**
@@ -73,9 +80,13 @@ public class FederationPullExecutor implements Runnable {
* on each registrations frequency setting.
*
* @param registrations
+ * @param isDaemon
+ * if true, registrations are rescheduled in perpetuity. if false,
+ * the federation pull operation is executed once.
*/
- public FederationPullExecutor(List<FederationModel> registrations) {
+ public FederationPullExecutor(List<FederationModel> registrations, boolean isDaemon) {
this.registrations = registrations;
+ this.isDaemon = isDaemon;
}
/**
@@ -109,7 +120,9 @@ public class FederationPullExecutor implements Runnable {
"Failed to pull from federated gitblit ({0} @ {1})", registration.name,
registration.url), t);
} finally {
- schedule(registration);
+ if (isDaemon) {
+ schedule(registration);
+ }
}
}
}
@@ -149,12 +162,25 @@ public class FederationPullExecutor implements Runnable {
continue;
}
+ // Determine local repository name
String repositoryName;
if (StringUtils.isEmpty(registrationFolder)) {
repositoryName = repository.name;
} else {
repositoryName = registrationFolder + "/" + repository.name;
}
+
+ if (registration.bare) {
+ // bare repository, ensure .git suffix
+ if (!repositoryName.toLowerCase().endsWith(DOT_GIT_EXT)) {
+ repositoryName += DOT_GIT_EXT;
+ }
+ } else {
+ // normal repository, strip .git suffix
+ if (repositoryName.toLowerCase().endsWith(DOT_GIT_EXT)) {
+ repositoryName = repositoryName.substring(0, repositoryName.indexOf(DOT_GIT_EXT));
+ }
+ }
// confirm that the origin of any pre-existing repository matches
// the clone url
@@ -164,8 +190,10 @@ public class FederationPullExecutor implements Runnable {
StoredConfig config = existingRepository.getConfig();
config.load();
String origin = config.getString("remote", "origin", "url");
- fetchHead = JGitUtils.getCommit(existingRepository, "refs/remotes/origin/master")
- .getName();
+ RevCommit commit = JGitUtils.getCommit(existingRepository, "refs/remotes/origin/master");
+ if (commit != null) {
+ fetchHead = commit.getName();
+ }
existingRepository.close();
if (!origin.startsWith(registration.url)) {
logger.warn(MessageFormat
@@ -181,6 +209,7 @@ public class FederationPullExecutor implements Runnable {
Constants.FEDERATION_USER, registration.token);
logger.info(MessageFormat.format("Pulling federated repository {0} from {1} @ {2}",
repository.name, registration.name, registration.url));
+
CloneResult result = JGitUtils.cloneRepository(registrationFolderFile, repository.name,
cloneUrl, registration.bare, credentials);
Repository r = GitBlit.self().getRepository(repositoryName);
@@ -196,8 +225,9 @@ public class FederationPullExecutor implements Runnable {
} else {
// fetch and update
boolean fetched = false;
- String origin = JGitUtils.getCommit(r, "refs/remotes/origin/master").getName();
- fetched = !fetchHead.equals(origin);
+ RevCommit commit = JGitUtils.getCommit(r, "refs/remotes/origin/master");
+ String origin = commit.getName();
+ fetched = fetchHead == null || !fetchHead.equals(origin);
if (registration.mirror) {
// mirror
@@ -225,6 +255,16 @@ public class FederationPullExecutor implements Runnable {
// preserve local settings
repository.isFrozen = rm.isFrozen;
repository.federationStrategy = rm.federationStrategy;
+
+ // merge federation sets
+ Set<String> federationSets = new HashSet<String>();
+ if (rm.federationSets != null) {
+ federationSets.addAll(rm.federationSets);
+ }
+ if (repository.federationSets != null) {
+ federationSets.addAll(repository.federationSets);
+ }
+ repository.federationSets = new ArrayList<String>(federationSets);
}
// only repositories that are actually _cloned_ from the origin
// Gitblit repository are marked as federated. If the origin
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index c2b214b4..62b93e7c 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -61,6 +61,7 @@ import com.gitblit.models.FederationModel;
import com.gitblit.models.FederationProposal;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.FederationUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
import com.google.gson.Gson;
@@ -830,8 +831,8 @@ public class GitBlit implements ServletContextListener {
// Schedule the federation executor
List<FederationModel> registrations = getFederationRegistrations();
if (registrations.size() > 0) {
- scheduledExecutor.schedule(new FederationPullExecutor(registrations), 1,
- TimeUnit.MINUTES);
+ FederationPullExecutor executor = new FederationPullExecutor(registrations, true);
+ scheduledExecutor.schedule(executor, 1, TimeUnit.MINUTES);
}
}
@@ -843,79 +844,7 @@ public class GitBlit implements ServletContextListener {
*/
public List<FederationModel> getFederationRegistrations() {
if (federationRegistrations.isEmpty()) {
- List<String> keys = settings.getAllKeys(Keys.federation._ROOT);
- keys.remove(Keys.federation.name);
- keys.remove(Keys.federation.passphrase);
- keys.remove(Keys.federation.allowProposals);
- keys.remove(Keys.federation.proposalsFolder);
- keys.remove(Keys.federation.defaultFrequency);
- keys.remove(Keys.federation.sets);
- Collections.sort(keys);
- Map<String, FederationModel> federatedModels = new HashMap<String, FederationModel>();
- for (String key : keys) {
- String value = key.substring(Keys.federation._ROOT.length() + 1);
- List<String> values = StringUtils.getStringsFromValue(value, "\\.");
- String server = values.get(0);
- if (!federatedModels.containsKey(server)) {
- federatedModels.put(server, new FederationModel(server));
- }
- String setting = values.get(1);
- if (setting.equals("url")) {
- // url of the origin Gitblit instance
- federatedModels.get(server).url = settings.getString(key, "");
- } else if (setting.equals("token")) {
- // token for the origin Gitblit instance
- federatedModels.get(server).token = settings.getString(key, "");
- } else if (setting.equals("frequency")) {
- // frequency of the pull operation
- federatedModels.get(server).frequency = settings.getString(key, "");
- } else if (setting.equals("folder")) {
- // destination folder of the pull operation
- federatedModels.get(server).folder = settings.getString(key, "");
- } else if (setting.equals("bare")) {
- // whether pulled repositories should be bare
- federatedModels.get(server).bare = settings.getBoolean(key, true);
- } else if (setting.equals("mirror")) {
- // are the repositories to be true mirrors of the origin
- federatedModels.get(server).mirror = settings.getBoolean(key, true);
- } else if (setting.equals("mergeAccounts")) {
- // merge remote accounts into local accounts
- federatedModels.get(server).mergeAccounts = settings.getBoolean(key, false);
- } else if (setting.equals("sendStatus")) {
- // send a status acknowledgment to source Gitblit instance
- // at end of git pull
- federatedModels.get(server).sendStatus = settings.getBoolean(key, false);
- } else if (setting.equals("notifyOnError")) {
- // notify administrators on federation pull failures
- federatedModels.get(server).notifyOnError = settings.getBoolean(key, false);
- } else if (setting.equals("exclude")) {
- // excluded repositories
- federatedModels.get(server).exclusions = settings.getStrings(key);
- } else if (setting.equals("include")) {
- // included repositories
- federatedModels.get(server).inclusions = settings.getStrings(key);
- }
- }
-
- // verify that registrations have a url and a token
- for (FederationModel model : federatedModels.values()) {
- if (StringUtils.isEmpty(model.url)) {
- logger.warn(MessageFormat.format(
- "Dropping federation registration {0}. Missing url.", model.name));
- continue;
- }
- if (StringUtils.isEmpty(model.token)) {
- logger.warn(MessageFormat.format(
- "Dropping federation registration {0}. Missing token.", model.name));
- continue;
- }
- // set default frequency if unspecified
- if (StringUtils.isEmpty(model.frequency)) {
- model.frequency = settings.getString(Keys.federation.defaultFrequency,
- "60 mins");
- }
- federationRegistrations.add(model);
- }
+ federationRegistrations.addAll(FederationUtils.getFederationRegistrations(settings));
}
return federationRegistrations;
}
@@ -1239,7 +1168,7 @@ public class GitBlit implements ServletContextListener {
*
* @param settings
*/
- public void configureContext(IStoredSettings settings) {
+ public void configureContext(IStoredSettings settings, boolean startFederation) {
logger.info("Reading configuration from " + settings.toString());
this.settings = settings;
repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "git"));
@@ -1268,13 +1197,15 @@ public class GitBlit implements ServletContextListener {
loginService = new FileUserService(realmFile);
}
setUserService(loginService);
- configureFederation();
mailExecutor = new MailExecutor(settings);
if (mailExecutor.isReady()) {
scheduledExecutor.scheduleAtFixedRate(mailExecutor, 1, 2, TimeUnit.MINUTES);
} else {
logger.warn("Mail server is not properly configured. Mail services disabled.");
}
+ if (startFederation) {
+ configureFederation();
+ }
}
/**
@@ -1288,7 +1219,7 @@ public class GitBlit implements ServletContextListener {
if (settings == null) {
// Gitblit WAR is running in a servlet container
WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());
- configureContext(webxmlSettings);
+ configureContext(webxmlSettings, true);
}
}
diff --git a/src/com/gitblit/GitBlitServer.java b/src/com/gitblit/GitBlitServer.java
index d2164f18..039f59d3 100644
--- a/src/com/gitblit/GitBlitServer.java
+++ b/src/com/gitblit/GitBlitServer.java
@@ -237,7 +237,7 @@ public class GitBlitServer {
// Setup the GitBlit context
GitBlit gitblit = GitBlit.self();
- gitblit.configureContext(settings);
+ gitblit.configureContext(settings, true);
rootContext.addEventListener(gitblit);
try {
diff --git a/src/com/gitblit/build/Build.java b/src/com/gitblit/build/Build.java
index 40342269..684f2787 100644
--- a/src/com/gitblit/build/Build.java
+++ b/src/com/gitblit/build/Build.java
@@ -115,6 +115,19 @@ public class Build {
// needed for site publishing
downloadFromApache(MavenObject.COMMONSNET, BuildType.RUNTIME);
}
+
+ public static void federationClient() {
+ downloadFromApache(MavenObject.JCOMMANDER, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.SERVLET, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.MAIL, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.SLF4JAPI, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.SLF4LOG4J, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.LOG4J, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.GSON, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.JSCH, BuildType.RUNTIME);
+
+ downloadFromEclipse(MavenObject.JGIT, BuildType.RUNTIME);
+ }
/**
* Builds the Keys class based on the gitblit.properties file and inserts
diff --git a/src/com/gitblit/models/FederationModel.java b/src/com/gitblit/models/FederationModel.java
index efb1b322..d67ae561 100644
--- a/src/com/gitblit/models/FederationModel.java
+++ b/src/com/gitblit/models/FederationModel.java
@@ -73,6 +73,8 @@ public class FederationModel implements Serializable, Comparable<FederationModel
*/
public FederationModel(String serverName) {
this.name = serverName;
+ bare = true;
+ mirror = true;
this.lastPull = new Date(0);
this.nextPull = new Date(0);
}
diff --git a/src/com/gitblit/utils/FederationUtils.java b/src/com/gitblit/utils/FederationUtils.java
index 4cb6881a..9fd88173 100644
--- a/src/com/gitblit/utils/FederationUtils.java
+++ b/src/com/gitblit/utils/FederationUtils.java
@@ -26,7 +26,10 @@ import java.net.URLConnection;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
+import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -39,8 +42,13 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.servlet.http.HttpServletResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.gitblit.Constants.FederationRequest;
import com.gitblit.FederationServlet;
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
import com.gitblit.models.FederationModel;
import com.gitblit.models.FederationProposal;
import com.gitblit.models.RepositoryModel;
@@ -74,6 +82,8 @@ public class FederationUtils {
private static final SSLContext SSL_CONTEXT;
private static final DummyHostnameVerifier HOSTNAME_VERIFIER;
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(FederationUtils.class);
static {
SSLContext context = null;
@@ -89,6 +99,89 @@ public class FederationUtils {
}
/**
+ * Returns the list of federated gitblit instances that this instance will
+ * try to pull.
+ *
+ * @return list of registered gitblit instances
+ */
+ public static List<FederationModel> getFederationRegistrations(IStoredSettings settings) {
+ List<FederationModel> federationRegistrations = new ArrayList<FederationModel>();
+ List<String> keys = settings.getAllKeys(Keys.federation._ROOT);
+ keys.remove(Keys.federation.name);
+ keys.remove(Keys.federation.passphrase);
+ keys.remove(Keys.federation.allowProposals);
+ keys.remove(Keys.federation.proposalsFolder);
+ keys.remove(Keys.federation.defaultFrequency);
+ keys.remove(Keys.federation.sets);
+ Collections.sort(keys);
+ Map<String, FederationModel> federatedModels = new HashMap<String, FederationModel>();
+ for (String key : keys) {
+ String value = key.substring(Keys.federation._ROOT.length() + 1);
+ List<String> values = StringUtils.getStringsFromValue(value, "\\.");
+ String server = values.get(0);
+ if (!federatedModels.containsKey(server)) {
+ federatedModels.put(server, new FederationModel(server));
+ }
+ String setting = values.get(1);
+ if (setting.equals("url")) {
+ // url of the origin Gitblit instance
+ federatedModels.get(server).url = settings.getString(key, "");
+ } else if (setting.equals("token")) {
+ // token for the origin Gitblit instance
+ federatedModels.get(server).token = settings.getString(key, "");
+ } else if (setting.equals("frequency")) {
+ // frequency of the pull operation
+ federatedModels.get(server).frequency = settings.getString(key, "");
+ } else if (setting.equals("folder")) {
+ // destination folder of the pull operation
+ federatedModels.get(server).folder = settings.getString(key, "");
+ } else if (setting.equals("bare")) {
+ // whether pulled repositories should be bare
+ federatedModels.get(server).bare = settings.getBoolean(key, true);
+ } else if (setting.equals("mirror")) {
+ // are the repositories to be true mirrors of the origin
+ federatedModels.get(server).mirror = settings.getBoolean(key, true);
+ } else if (setting.equals("mergeAccounts")) {
+ // merge remote accounts into local accounts
+ federatedModels.get(server).mergeAccounts = settings.getBoolean(key, false);
+ } else if (setting.equals("sendStatus")) {
+ // send a status acknowledgment to source Gitblit instance
+ // at end of git pull
+ federatedModels.get(server).sendStatus = settings.getBoolean(key, false);
+ } else if (setting.equals("notifyOnError")) {
+ // notify administrators on federation pull failures
+ federatedModels.get(server).notifyOnError = settings.getBoolean(key, false);
+ } else if (setting.equals("exclude")) {
+ // excluded repositories
+ federatedModels.get(server).exclusions = settings.getStrings(key);
+ } else if (setting.equals("include")) {
+ // included repositories
+ federatedModels.get(server).inclusions = settings.getStrings(key);
+ }
+ }
+
+ // verify that registrations have a url and a token
+ for (FederationModel model : federatedModels.values()) {
+ if (StringUtils.isEmpty(model.url)) {
+ LOGGER.warn(MessageFormat.format(
+ "Dropping federation registration {0}. Missing url.", model.name));
+ continue;
+ }
+ if (StringUtils.isEmpty(model.token)) {
+ LOGGER.warn(MessageFormat.format(
+ "Dropping federation registration {0}. Missing token.", model.name));
+ continue;
+ }
+ // set default frequency if unspecified
+ if (StringUtils.isEmpty(model.frequency)) {
+ model.frequency = settings.getString(Keys.federation.defaultFrequency, "60 mins");
+ }
+ federationRegistrations.add(model);
+ }
+ return federationRegistrations;
+ }
+
+ /**
* Sends a federation proposal to the Gitblit instance at remoteUrl
*
* @param remoteUrl
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index faca9cb6..bfbc6240 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -37,8 +37,6 @@ import java.util.zip.ZipOutputStream;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.FetchCommand;
import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.PullCommand;
-import org.eclipse.jgit.api.PullResult;
import org.eclipse.jgit.api.ResetCommand;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.diff.DiffEntry;
@@ -142,6 +140,7 @@ public class JGitUtils {
* Encapsulates the result of cloning or pulling from a repository.
*/
public static class CloneResult {
+ public String name;
public FetchResult fetchResult;
public boolean createdRepository;
}
@@ -175,12 +174,22 @@ public class JGitUtils {
* @return CloneResult
* @throws Exception
*/
- public static CloneResult cloneRepository(File repositoriesFolder, String name, String fromUrl, boolean bare,
- CredentialsProvider credentialsProvider) throws Exception {
+ public static CloneResult cloneRepository(File repositoriesFolder, String name, String fromUrl,
+ boolean bare, CredentialsProvider credentialsProvider) throws Exception {
CloneResult result = new CloneResult();
- if (bare && !name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
- name += Constants.DOT_GIT_EXT;
+ if (bare) {
+ // bare repository, ensure .git suffix
+ if (!name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
+ name += Constants.DOT_GIT_EXT;
+ }
+ } else {
+ // normal repository, strip .git suffix
+ if (name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
+ name = name.substring(0, name.indexOf(Constants.DOT_GIT_EXT));
+ }
}
+ result.name = name;
+
File folder = new File(repositoriesFolder, name);
if (folder.exists()) {
File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);