[jbosstools-commits] JBoss Tools SVN: r35511 - trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Oct 10 08:02:05 EDT 2011


Author: adietish
Date: 2011-10-10 08:02:05 -0400 (Mon, 10 Oct 2011)
New Revision: 35511

Modified:
   trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java
Log:
[JBIDE-9793] added EgitUtils#addRemoteTo

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java	2011-10-10 12:00:31 UTC (rev 35510)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java	2011-10-10 12:02:05 UTC (rev 35511)
@@ -11,6 +11,7 @@
 package org.jboss.ide.eclipse.as.egit.core;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
@@ -30,6 +31,7 @@
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
 import org.eclipse.jgit.lib.UserConfig;
 import org.eclipse.jgit.transport.RefSpec;
 import org.eclipse.jgit.transport.RemoteConfig;
@@ -399,6 +401,33 @@
 		return remoteName;
 	}
 
+	/**
+	 * Adds the given uri of a remote repository to the given repository by the
+	 * given name.
+	 * 
+	 * @param remoteName
+	 *            the name to use for the remote repository
+	 * @param uri
+	 *            the uri of the remote repository
+	 * @param repository
+	 *            the repository to add the remote to
+	 * @throws URISyntaxException
+	 *             the uRI syntax exception
+	 * @throws MalformedURLException
+	 *             the malformed url exception
+	 * @throws IOException
+	 *             Signals that an I/O exception has occurred.
+	 */
+	public static void addRemoteTo(String remoteName, URIish uri, Repository repository)
+			throws URISyntaxException, MalformedURLException,
+			IOException {
+		StoredConfig config = repository.getConfig();
+		RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
+		remoteConfig.addURI(uri);
+		remoteConfig.update(config);
+		config.save();
+	}
+
 	private static IStatus createStatus(Exception e, String message, String... arguments) throws CoreException {
 		IStatus status = null;
 		if (e == null) {
@@ -408,5 +437,4 @@
 		}
 		return status;
 	}
-
 }



More information about the jbosstools-commits mailing list