<tr><th>req=</th><th>name=</th><th>post body</th><th>response body</th></tr>\r
<tr><td colspan='5'><em>web.enableRpcServlet=true</em></td></tr>\r
<tr><td>LIST_REPOSITORIES</td><td>-</td><td>-</td><td>-</td><td>Map<String, RepositoryModel></td></tr>\r
+<tr><td>LIST_BRANCHES</td><td>-</td><td>-</td><td>-</td><td>Map<String, List<String>></td></tr>\r
<tr><td colspan='5'><em>web.enableRpcManagement=true</em></td></tr>\r
<tr><td>CREATE_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>RepositoryModel</td><td>-</td></tr>\r
<tr><td>EDIT_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>RepositoryModel</td><td>-</td></tr>\r
<pre>\r
{\r
"bootDate": "2011-10-22T12:13:00Z",\r
+ "version": "0.7.0-SNAPSHOT",\r
+ "releaseDate": "PENDING",\r
+ "isGO": true,\r
"systemProperties": {\r
"file.encoding": "Cp1252",\r
"java.home": "C:\\Program Files\\Java\\jdk1.6.0_26\\jre",\r
},\r
"heapAllocated": 128057344,\r
"heapFree": 120399168,\r
- "heapSize": 1899560960\r
+ "heapSize": 1899560960,\r
+ "servletContainer": "jetty/7.4.3.v20110701"\r
}\r
</pre>
\ No newline at end of file
* a client.\r
*/\r
public static enum RpcRequest {\r
- LIST_REPOSITORIES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,\r
+ LIST_REPOSITORIES, LIST_BRANCHES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,\r
LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS,\r
SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS,\r
LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS, EDIT_SETTINGS,\r
super(message);\r
}\r
\r
+ public GitBlitException(Throwable cause) {\r
+ super(cause);\r
+ }\r
+\r
/**\r
* Exception to indicate that the client should prompt for credentials\r
* because the requested action requires authentication.\r
return;\r
}\r
\r
- boolean adminRequest = requestType.exceeds(RpcRequest.LIST_REPOSITORIES);\r
+ boolean adminRequest = requestType.exceeds(RpcRequest.LIST_BRANCHES);\r
\r
// conditionally reject all rpc requests\r
if (!GitBlit.getBoolean(Keys.web.enableRpcServlet, true)) {\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import org.eclipse.jgit.lib.Repository;\r
+\r
import com.gitblit.Constants.RpcRequest;\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.HttpUtils;\r
+import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.RpcUtils;\r
\r
/**\r
repositories.put(url, model);\r
}\r
result = repositories;\r
+ } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {\r
+ // list all branches in all repositories accessible to user\r
+ Map<String, List<String>> allBranches = new HashMap<String, List<String>>();\r
+ List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);\r
+ for (RepositoryModel model : models) {\r
+ if (!model.hasCommits) {\r
+ // skip empty repository\r
+ continue;\r
+ }\r
+ // get branches\r
+ Repository repository = GitBlit.self().getRepository(model.name);\r
+ List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);\r
+ refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));\r
+ if (refs.size() > 0) {\r
+ List<String> branches = new ArrayList<String>();\r
+ for (RefModel ref : refs) {\r
+ branches.add(ref.getName());\r
+ }\r
+ allBranches.put(model.name, branches);\r
+ }\r
+ repository.close();\r
+ }\r
+ result = allBranches;\r
} else if (RpcRequest.LIST_USERS.equals(reqType)) {\r
// list users\r
List<String> names = GitBlit.self().getAllUsernames();\r
private static final Type SETS_TYPE = new TypeToken<Collection<FederationSet>>() {\r
}.getType();\r
\r
+ private static final Type BRANCHES_TYPE = new TypeToken<Map<String, Collection<String>>>() {\r
+ }.getType();\r
+\r
/**\r
* \r
* @param remoteURL\r
return status;\r
}\r
\r
+ /**\r
+ * Retrieves a map of all branches in the Gitblit server keyed by\r
+ * repository.\r
+ * \r
+ * @param serverUrl\r
+ * @param account\r
+ * @param password\r
+ * @return\r
+ * @throws IOException\r
+ */\r
+ public static Map<String, Collection<String>> getAllBranches(String serverUrl,\r
+ String account, char[] password) throws IOException {\r
+ String url = asLink(serverUrl, RpcRequest.LIST_BRANCHES);\r
+ Map<String, Collection<String>> allReferences = JsonUtils.retrieveJson(url,\r
+ BRANCHES_TYPE, account, password);\r
+ return allReferences;\r
+ }\r
+\r
/**\r
* Do the specified administrative action on the Gitblit server.\r
* \r
package com.gitblit.tests;\r
\r
import java.io.IOException;\r
+import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
\r
public void testUpdateSettings() throws Exception {\r
Map<String, String> updated = new HashMap<String, String>();\r
- \r
+\r
// grab current setting\r
ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray());\r
boolean showSizes = settings.get(Keys.web.showRepositorySizes).getBoolean(true);\r
showSizes = !showSizes;\r
- \r
+\r
// update setting\r
updated.put(Keys.web.showRepositorySizes, String.valueOf(showSizes));\r
boolean success = RpcUtils.updateSettings(updated, "http://localhost:8080/gb", account,\r
password.toCharArray());\r
assertTrue("Failed to update server settings", success);\r
- \r
+\r
// confirm setting change\r
settings = RpcUtils.getSettings(url, account, password.toCharArray());\r
boolean newValue = settings.get(Keys.web.showRepositorySizes).getBoolean(false);\r
assertEquals(newValue, showSizes);\r
- \r
+\r
// restore setting\r
newValue = !newValue;\r
updated.put(Keys.web.showRepositorySizes, String.valueOf(newValue));\r
}\r
+\r
+ public void testBranches() throws Exception {\r
+ Map<String, Collection<String>> branches = RpcUtils.getAllBranches(url, account,\r
+ password.toCharArray());\r
+ assertTrue(branches != null);\r
+ assertTrue(branches.size() > 0);\r
+ }\r
}\r