aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Janik2011-07-29 08:27:46 (EDT)
committerTomasz Zarna2011-08-01 05:45:30 (EDT)
commit8c9a646ce05fa8d2434f7ca90de4068c4471b83f (patch)
treee9cb41f6acda4e05d334e1127ba3cc773bc83872
parent26db34f0acbf50386ecfa3f0c5bfa44a822af3be (diff)
downloadorg.eclipse.orion.server-8c9a646ce05fa8d2434f7ca90de4068c4471b83f.zip
org.eclipse.orion.server-8c9a646ce05fa8d2434f7ca90de4068c4471b83f.tar.gz
org.eclipse.orion.server-8c9a646ce05fa8d2434f7ca90de4068c4471b83f.tar.bz2
Bug 352202 - missing git push for remotebug352202
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitRemoteHandlerV1.java15
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java48
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java252
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTest.java18
4 files changed, 303 insertions, 30 deletions
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitRemoteHandlerV1.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitRemoteHandlerV1.java
index 5198ef9..09c2db5 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitRemoteHandlerV1.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitRemoteHandlerV1.java
@@ -176,7 +176,7 @@ public class GitRemoteHandlerV1 extends ServletResourceHandler<String> {
}
// remove remote
- private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path) throws CoreException, IOException, URISyntaxException, JSONException, ServletException {
+ private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path) throws CoreException, IOException, URISyntaxException {
Path p = new Path(path);
if (p.segment(1).equals("file")) { //$NON-NLS-1$
// expected path: /gitapi/remote/{remote}/file/{path}
@@ -221,11 +221,9 @@ public class GitRemoteHandlerV1 extends ServletResourceHandler<String> {
// if all went well, continue with fetch or push
if (fetch) {
- return fetch(request, response, cp, path, force);
- } else if (srcRef != null) {
+ return fetch(request, response, cp, path, force);
+ } else {
return push(request, response, path, cp, srcRef, tags, force);
- } else {
- return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Only Fetch:true is currently supported.", null));
}
}
}
@@ -298,8 +296,9 @@ public class GitRemoteHandlerV1 extends ServletResourceHandler<String> {
private boolean push(HttpServletRequest request, HttpServletResponse response, String path, GitCredentialsProvider cp, String srcRef, boolean tags, boolean force) throws ServletException, CoreException, IOException, JSONException, URISyntaxException {
Path p = new Path(path);
// FIXME: what if a remote or branch is named "file"?
- if (p.segment(2).equals("file")) { //$NON-NLS-1$
- // /git/remote/{remote}/{branch}/file/{path}
+ if (p.segment(1).equals("file") || (p.segment(2).equals("file") && srcRef != null)) { //$NON-NLS-1$
+ // /gitapi/remote/{remote}/file/{path} - specRef would be deduced from the repo config
+ // /gitapi/remote/{remote}/{branch}/file/{path} - srcRef is required
PushJob job = new PushJob(cp, p, srcRef, tags, force);
job.schedule();
@@ -312,7 +311,7 @@ public class GitRemoteHandlerV1 extends ServletResourceHandler<String> {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
return true;
}
- return false;
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Bad URI or PushSrcRef expected", null));
}
private URI createTaskLocation(URI baseLocation, String taskId) throws URISyntaxException {
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java
index 3fe5be7..7242d43 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.orion.server.git.servlets;
-import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashSet;
@@ -37,13 +36,16 @@ public class PushJob extends GitJob {
private final TaskInfo task;
private Path path;
+ private String remote;
private String srcRef;
private boolean tags;
private boolean force;
public PushJob(CredentialsProvider credentials, Path path, String srcRef, boolean tags, boolean force) {
super("Pushing", (GitCredentialsProvider) credentials);
+ // path: {remote}[/{branch}]/file/{...}
this.path = path;
+ this.remote = path.segment(0);
this.srcRef = srcRef;
this.tags = tags;
this.task = createTask();
@@ -58,22 +60,25 @@ public class PushJob extends GitJob {
}
private IStatus doPush() throws IOException, CoreException, JGitInternalException, InvalidRemoteException, URISyntaxException, JSONException {
- // /git/remote/{remote}/{branch}/file/{path}
- File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2));
- Repository db = new FileRepository(gitDir);
- Git git = new Git(db);
+ // /git/remote/{remote}[/{branch}]/file/{path}
+ Repository db = getRepository();
+ String branch = getRemoteBranch();
+ Git git = new Git(db);
PushCommand pushCommand = git.push();
- RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), path.segment(0));
+ RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote);
credentials.setUri(remoteConfig.getURIs().get(0));
- pushCommand.setCredentialsProvider(credentials);
- // ObjectId ref = db.resolve(srcRef);
- RefSpec spec = new RefSpec(srcRef + ":" + Constants.R_HEADS + path.segment(1)); //$NON-NLS-1$
- pushCommand.setRemote(path.segment(0)).setRefSpecs(spec);
- if (tags)
+ pushCommand.setCredentialsProvider(credentials);
+ pushCommand.setRemote(remote);
+ if (branch != null) {
+ RefSpec spec = new RefSpec(srcRef + ":" + Constants.R_HEADS + path.segment(1)); //$NON-NLS-1$
+ pushCommand.setRefSpecs(spec);
+ }
+ if (tags) {
pushCommand.setPushTags();
+ }
pushCommand.setForce(force);
Iterable<PushResult> resultIterable = pushCommand.call();
PushResult pushResult = resultIterable.iterator().next();
@@ -82,8 +87,9 @@ public class PushJob extends GitJob {
for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) {
final String rm = rru.getRemoteName();
// final String sr = rru.isDelete() ? null : rru.getSrcRef();
- // check status only for branch given in the URL or tags
- if (path.segment(1).equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) {
+ // if branch is specified, check status only for branch given in the URL or tags
+ // if not, check status for all branches
+ if (branch == null || branch.equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) {
RemoteRefUpdate.Status status = rru.getStatus();
// any status different from UP_TO_DATE and OK should generate warning
if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE)
@@ -101,6 +107,22 @@ public class PushJob extends GitJob {
return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name());
}
+ private Repository getRepository() throws IOException, CoreException {
+ IPath p = null;
+ if (path.segment(1).equals("file")) //$NON-NLS-1$
+ p = path.removeFirstSegments(1);
+ else
+ p = path.removeFirstSegments(2);
+ return new FileRepository(GitUtils.getGitDir(p));
+ }
+
+ private String getRemoteBranch() {
+ if (path.segment(1).equals("file")) //$NON-NLS-1$
+ return null;
+ else
+ return path.segment(1);
+ }
+
public TaskInfo getTask() {
return task;
}
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java
index 4b66c15..b4ad38a 100644
--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java
@@ -22,6 +22,7 @@ import java.net.URI;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
@@ -809,6 +810,257 @@ public class GitPushTest extends GitTest {
assertEquals(1, tags.length());
}
+ @Test
+ public void testPushRemote() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop1 = createProjectOrLink(workspaceLocation, getMethodName() + "-top1", null);
+ IPath clonePathTop1 = new Path("file").append(projectTop1.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectTop2 = createProjectOrLink(workspaceLocation, getMethodName() + "-top2", null);
+ IPath clonePathTop2 = new Path("file").append(projectTop2.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder1 = createProjectOrLink(workspaceLocation, getMethodName() + "-folder1", null);
+ IPath clonePathFolder1 = new Path("file").append(projectFolder1.getString(ProtocolConstants.KEY_ID)).append("folder1").makeAbsolute();
+
+ JSONObject projectFolder2 = createProjectOrLink(workspaceLocation, getMethodName() + "-folder2", null);
+ IPath clonePathFolder2 = new Path("file").append(projectFolder2.getString(ProtocolConstants.KEY_ID)).append("folder2").makeAbsolute();
+
+ JSONObject projectTop3 = createProjectOrLink(workspaceLocation, getMethodName() + "-top3", null);
+ IPath clonePathTop3 = new Path("file").append(projectTop3.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder3 = createProjectOrLink(workspaceLocation, getMethodName() + "-folder3", null);
+ IPath clonePathFolder3 = new Path("file").append(projectFolder3.getString(ProtocolConstants.KEY_ID)).append("folder1").makeAbsolute();
+
+ IPath[] clonePathsTop = new IPath[] {clonePathTop1, clonePathTop2};
+ IPath[] clonePathsFolder = new IPath[] {clonePathFolder1, clonePathFolder2};
+ IPath[] clonePathsMixed = new IPath[] {clonePathTop3, clonePathFolder3};
+ IPath[][] clonePaths = new IPath[][] {clonePathsTop, clonePathsFolder, clonePathsMixed};
+
+ for (IPath[] clonePath : clonePaths) {
+ // clone 1
+ JSONObject clone1 = clone(clonePath[0]);
+ String cloneLocation1 = clone1.getString(ProtocolConstants.KEY_LOCATION);
+ String contentLocation1 = clone1.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+ String branchesLocation1 = clone1.getString(GitConstants.KEY_BRANCH);
+
+ // clone 1 - get project1 metadata
+ WebRequest request = getGetFilesRequest(contentLocation1);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project1 = new JSONObject(response.getText());
+ String projectLocation1 = project1.getString(ProtocolConstants.KEY_LOCATION);
+ JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
+ String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);
+ String gitIndexUri1 = gitSection1.getString(GitConstants.KEY_INDEX);
+ String gitHeadUri1 = gitSection1.getString(GitConstants.KEY_HEAD);
+
+ // clone 1 - create branch "a"
+ final String newBranchName = "a";
+ response = branch(branchesLocation1, newBranchName);
+
+ // clone 1 - checkout "a"
+ response = checkoutBranch(cloneLocation1, newBranchName);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - change
+ request = getPutFileRequest(projectLocation1 + "/test.txt", "clone1 change");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - add
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri1);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - commit
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "clone1 change commit", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - push origin
+ // HEAD should be used as refSpec, as no remote branch or refSpec in config is specified
+ JSONObject remote1 = getRemote(gitRemoteUri1, 1, 0, Constants.DEFAULT_REMOTE_NAME);
+ String remoteLocation1 = remote1.getString(ProtocolConstants.KEY_LOCATION);
+
+ ServerStatus pushStatus = push(remoteLocation1, null, false);
+ assertEquals(true, pushStatus.isOK());
+
+ // clone 1 - list remote branches - expect 2
+ request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation1);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ remote1 = new JSONObject(response.getText());
+ JSONArray refsArray = remote1.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(2, refsArray.length());
+ JSONObject ref = refsArray.getJSONObject(0);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + newBranchName, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+ ref = refsArray.getJSONObject(1);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+
+ // clone 2
+ JSONObject clone2 = clone(clonePath[1]);
+ String contentLocation2 = clone2.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // clone 2 - get project2 metadata
+ request = getGetFilesRequest(contentLocation2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project2 = new JSONObject(response.getText());
+ JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
+ String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
+
+ // clone 2 - check if the branch "a" is available
+ JSONObject remote2 = getRemote(gitRemoteUri2, 1, 0, Constants.DEFAULT_REMOTE_NAME);
+ String remoteLocation2 = remote2.getString(ProtocolConstants.KEY_LOCATION);
+
+ request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ remote2 = new JSONObject(response.getText());
+ refsArray = remote2.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(2, refsArray.length());
+ ref = refsArray.getJSONObject(0);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+ ref = refsArray.getJSONObject(1);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + newBranchName, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+
+ // cleanup before next iteration
+ // as t repo is used as remote for test projects
+ Git git = new Git(db);
+ git.branchDelete().setBranchNames(newBranchName).setForce(true).call();
+ }
+ }
+
+ @Test
+ public void testPushRemoteAndUseConfigRefSpec() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop1 = createProjectOrLink(workspaceLocation, getMethodName() + "-top1", null);
+ IPath clonePathTop1 = new Path("file").append(projectTop1.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectTop2 = createProjectOrLink(workspaceLocation, getMethodName() + "-top2", null);
+ IPath clonePathTop2 = new Path("file").append(projectTop2.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder1 = createProjectOrLink(workspaceLocation, getMethodName() + "-folder1", null);
+ IPath clonePathFolder1 = new Path("file").append(projectFolder1.getString(ProtocolConstants.KEY_ID)).append("folder1").makeAbsolute();
+
+ JSONObject projectFolder2 = createProjectOrLink(workspaceLocation, getMethodName() + "-folder2", null);
+ IPath clonePathFolder2 = new Path("file").append(projectFolder2.getString(ProtocolConstants.KEY_ID)).append("folder2").makeAbsolute();
+
+ JSONObject projectTop3 = createProjectOrLink(workspaceLocation, getMethodName() + "-top3", null);
+ IPath clonePathTop3 = new Path("file").append(projectTop3.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder3 = createProjectOrLink(workspaceLocation, getMethodName() + "-folder3", null);
+ IPath clonePathFolder3 = new Path("file").append(projectFolder3.getString(ProtocolConstants.KEY_ID)).append("folder1").makeAbsolute();
+
+ IPath[] clonePathsTop = new IPath[] {clonePathTop1, clonePathTop2};
+ IPath[] clonePathsFolder = new IPath[] {clonePathFolder1, clonePathFolder2};
+ IPath[] clonePathsMixed = new IPath[] {clonePathTop3, clonePathFolder3};
+ IPath[][] clonePaths = new IPath[][] {clonePathsTop, clonePathsFolder, clonePathsMixed};
+
+ for (IPath[] clonePath : clonePaths) {
+ // clone 1
+ JSONObject clone1 = clone(clonePath[0]);
+ String cloneLocation1 = clone1.getString(ProtocolConstants.KEY_LOCATION);
+ String contentLocation1 = clone1.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+ String branchesLocation1 = clone1.getString(GitConstants.KEY_BRANCH);
+
+ // clone 1 - get project1 metadata
+ WebRequest request = getGetFilesRequest(contentLocation1);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project1 = new JSONObject(response.getText());
+ String projectLocation1 = project1.getString(ProtocolConstants.KEY_LOCATION);
+ JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
+ String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);
+ String gitIndexUri1 = gitSection1.getString(GitConstants.KEY_INDEX);
+ String gitHeadUri1 = gitSection1.getString(GitConstants.KEY_HEAD);
+ String gitConfigUri1 = gitSection1.getString(GitConstants.KEY_CONFIG);
+
+ // clone 1 - create branch "a"
+ final String newBranchName1 = "a";
+ response = branch(branchesLocation1, newBranchName1);
+
+ // clone 1 - checkout "a"
+ response = checkoutBranch(cloneLocation1, newBranchName1);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - change
+ request = getPutFileRequest(projectLocation1 + "/test.txt", "clone1 change");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - add
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri1);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - commit
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "clone1 change commit", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone 1 - set remote.origin.push to "refs/heads/a:refs/heads/b"
+ // to force name mapping from "a" to "b"
+ final String newBranchName2 = "b";
+ String pushRefSpec = "refs/heads/" + newBranchName1 + ":refs/heads/" + newBranchName2;
+ request = GitConfigTest.getPostGitConfigRequest(gitConfigUri1, "remote.origin.push", pushRefSpec);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
+
+ // clone 1 - push origin
+ // refSpec from config should be used, as it was specified a moment ago
+ JSONObject remote1 = getRemote(gitRemoteUri1, 1, 0, Constants.DEFAULT_REMOTE_NAME);
+ String remoteLocation1 = remote1.getString(ProtocolConstants.KEY_LOCATION);
+
+ ServerStatus pushStatus = push(remoteLocation1, null, false);
+ assertEquals(true, pushStatus.isOK());
+
+ // clone 1 - list remote branches - expect 2
+ request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation1);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ remote1 = new JSONObject(response.getText());
+ JSONArray refsArray = remote1.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(2, refsArray.length());
+ JSONObject ref = refsArray.getJSONObject(0);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + newBranchName2, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+ ref = refsArray.getJSONObject(1);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+
+ // clone 2
+ JSONObject clone2 = clone(clonePath[1]);
+ String contentLocation2 = clone2.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // clone 2 - get project2 metadata
+ request = getGetFilesRequest(contentLocation2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project2 = new JSONObject(response.getText());
+ JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
+ String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
+
+ // clone 2 - check if the branch "b" is available
+ JSONObject remote2 = getRemote(gitRemoteUri2, 1, 0, Constants.DEFAULT_REMOTE_NAME);
+ String remoteLocation2 = remote2.getString(ProtocolConstants.KEY_LOCATION);
+
+ request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ remote2 = new JSONObject(response.getText());
+ refsArray = remote2.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(2, refsArray.length());
+ ref = refsArray.getJSONObject(0);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+ ref = refsArray.getJSONObject(1);
+ assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + newBranchName2, ref.getString(ProtocolConstants.KEY_FULL_NAME));
+
+ // cleanup before next iteration
+ // as t repo is used as remote for test projects
+ Git git = new Git(db);
+ git.branchDelete().setBranchNames(newBranchName2).setForce(true).call();
+ }
+ }
+
static WebRequest getPostGitRemoteRequest(String location, String srcRef, boolean tags, boolean force) throws JSONException, UnsupportedEncodingException {
String requestURI;
if (location.startsWith("http://"))
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTest.java
index 1ffa9ee..df9946f 100644
--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTest.java
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTest.java
@@ -481,9 +481,9 @@ public abstract class GitTest extends FileSystemTest {
}
/**
- * Pushes the changes from the the source ref to the given remote branch.
+ * Pushes the changes from the the source ref to the given remote or remote branch.
*
- * @param gitRemoteBranchUri remote branch URI
+ * @param gitRemoteUri remote or remote branch URI
* @param srcRef the source ref to push
* @param tags <code>true</code> to push tags
* @return JSON object representing response
@@ -491,14 +491,14 @@ public abstract class GitTest extends FileSystemTest {
* @throws SAXException
* @throws JSONException
*/
- protected ServerStatus push(String gitRemoteBranchUri, String srcRef, boolean tags) throws IOException, SAXException, JSONException {
- return push(gitRemoteBranchUri, srcRef, tags, false);
+ protected ServerStatus push(String gitRemoteUri, String srcRef, boolean tags) throws IOException, SAXException, JSONException {
+ return push(gitRemoteUri, srcRef, tags, false);
}
/**
- * Pushes the changes from the the source ref to the given remote branch.
+ * Pushes the changes from the the source ref to the given remote or remote branch.
*
- * @param gitRemoteBranchUri remote branch URI
+ * @param gitRemoteUri remote or remote branch URI
* @param srcRef the source ref to push
* @param tags <code>true</code> to push tags
* @param force <code>true</code> to force push
@@ -507,9 +507,9 @@ public abstract class GitTest extends FileSystemTest {
* @throws SAXException
* @throws JSONException
*/
- protected ServerStatus push(String gitRemoteBranchUri, String srcRef, boolean tags, boolean force) throws IOException, SAXException, JSONException {
- assertRemoteOrRemoteBranchLocation(gitRemoteBranchUri);
- WebRequest request = GitPushTest.getPostGitRemoteRequest(gitRemoteBranchUri, srcRef, tags, force);
+ protected ServerStatus push(String gitRemoteUri, String srcRef, boolean tags, boolean force) throws IOException, SAXException, JSONException {
+ assertRemoteOrRemoteBranchLocation(gitRemoteUri);
+ WebRequest request = GitPushTest.getPostGitRemoteRequest(gitRemoteUri, srcRef, tags, force);
WebResponse response = webConversation.getResponse(request);
assertEquals(HttpURLConnection.HTTP_ACCEPTED, response.getResponseCode());
String taskLocation = response.getHeaderField(ProtocolConstants.HEADER_LOCATION);