summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPiotr Janik2011-07-25 09:30:08 (EDT)
committer Szymon Brandys2011-07-25 10:09:55 (EDT)
commit3d685987876e60a48df9ef292e93b34c7053da9b (patch)
tree118bd13316dd681ccff7cbc7a1881ef26779836a
parent6c564cd39d529cfd055492fb70118aefd6fabb7b (diff)
downloadorg.eclipse.orion.server-3d685987876e60a48df9ef292e93b34c7053da9b.zip
org.eclipse.orion.server-3d685987876e60a48df9ef292e93b34c7053da9b.tar.gz
org.eclipse.orion.server-3d685987876e60a48df9ef292e93b34c7053da9b.tar.bz2
Bug 351429 - [git] Add git rebase
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/AdditionalRebaseStatus.java29
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/GitConstants.java6
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java50
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitStatusHandlerV1.java3
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/AllGitTests.java2
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitRebaseTest.java736
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTest.java19
7 files changed, 844 insertions, 1 deletions
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/AdditionalRebaseStatus.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/AdditionalRebaseStatus.java
new file mode 100644
index 0000000..d3fdbfd
--- /dev/null
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/AdditionalRebaseStatus.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.orion.server.git;
+
+public enum AdditionalRebaseStatus {
+ /**
+ * Failed due to an invalid repository state;
+ * action started earlier should be finished (i.e. rebasing, merging etc.)
+ */
+ FAILED_WRONG_REPOSITORY_STATE,
+ /**
+ * Failed due to unmerged paths;
+ * conflicts should be resolved before rebase can be continued
+ */
+ FAILED_UNMERGED_PATHS,
+ /**
+ * Failed due to pending changes (unstaged or uncommited);
+ * changes should be commited or stashed
+ */
+ FAILED_PENDING_CHANGES;
+}
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/GitConstants.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/GitConstants.java
index b73057b..96d8cc0 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/GitConstants.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/GitConstants.java
@@ -51,6 +51,8 @@ public class GitConstants {
public static final String KEY_REPOSITORY_PATH = "RepositoryPath"; //$NON-NLS-1$
+ public static final String KEY_REPOSITORY_STATE = "RepositoryState"; //$NON-NLS-1$
+
public static final String KEY_DEFAULT_REMOTE_BRANCH = "DefaultRemoteBranchLocation"; //$NON-NLS-1$
public static final String KEY_TAG = "TagLocation"; //$NON-NLS-1$
@@ -153,6 +155,10 @@ public class GitConstants {
public static final String KEY_MERGE = "Merge"; //$NON-NLS-1$
+ public static final String KEY_REBASE = "Rebase"; //$NON-NLS-1$
+
+ public static final String KEY_OPERATION = "Operation"; //$NON-NLS-1$
+
public static final String KEY_CHERRY_PICK = "Cherry-Pick"; //$NON-NLS-1$
public static final String KEY_PUSH_SRC_REF = "PushSrcRef"; //$NON-NLS-1$
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java
index b6d981f..731ed33 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java
@@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.core.runtime.*;
import org.eclipse.jgit.api.*;
+import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.errors.*;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
@@ -362,6 +363,12 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
return merge(request, response, db, commitToMerge);
}
+ String commitToRebase = requestObject.optString(GitConstants.KEY_REBASE, null);
+ String rebaseOperation = requestObject.optString(GitConstants.KEY_OPERATION, null);
+ if (commitToRebase != null) {
+ return rebase(request, response, db, commitToRebase, rebaseOperation);
+ }
+
String commitToCherryPick = requestObject.optString(GitConstants.KEY_CHERRY_PICK, null);
if (commitToCherryPick != null) {
return cherryPick(request, response, db, commitToCherryPick);
@@ -429,6 +436,49 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
}
}
+ private boolean rebase(HttpServletRequest request, HttpServletResponse response, Repository db, String commitToRebase, String rebaseOperation) throws ServletException, JSONException, AmbiguousObjectException, IOException {
+ JSONObject result = new JSONObject();
+ try {
+ Git git = new Git(db);
+ RebaseCommand rebase = git.rebase();
+ Operation operation;
+ if (rebaseOperation != null) {
+ operation = Operation.valueOf(rebaseOperation);
+ } else {
+ operation = Operation.BEGIN;
+ }
+ if (commitToRebase != null && !commitToRebase.isEmpty()) {
+ ObjectId objectId = db.resolve(commitToRebase);
+ rebase.setUpstream(objectId);
+ } else if (operation.equals(Operation.BEGIN)) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Missing commit refId.", null));
+ }
+ rebase.setOperation(operation);
+ RebaseResult rebaseResult = rebase.call();
+ result.put(GitConstants.KEY_RESULT, rebaseResult.getStatus().name());
+ } catch (UnmergedPathsException e) {
+ // this error should be handled by client, so return a proper status
+ result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_UNMERGED_PATHS.name());
+ } catch (WrongRepositoryStateException e) {
+ // this error should be handled by client, so return a proper status
+ result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_WRONG_REPOSITORY_STATE.name());
+ } catch (IllegalArgumentException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Invalid rebase operation.", e));
+ } catch (GitAPIException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when rebasing.", e));
+ } catch (JGitInternalException e) {
+ // get cause and try to handle
+ if (e.getCause() instanceof org.eclipse.jgit.errors.CheckoutConflictException) {
+ // this error should be handled by client, so return a proper status
+ result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_PENDING_CHANGES.name());
+ } else {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when rebasing.", e));
+ }
+ }
+ OrionServlet.writeJSONResponse(request, response, result);
+ return true;
+ }
+
private boolean cherryPick(HttpServletRequest request, HttpServletResponse response, Repository db, String commitToCherryPick) throws ServletException, JSONException {
try {
ObjectId objectId = db.resolve(commitToCherryPick);
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitStatusHandlerV1.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitStatusHandlerV1.java
index c7872bd..766fe3a 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitStatusHandlerV1.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitStatusHandlerV1.java
@@ -86,6 +86,9 @@ public class GitStatusHandlerV1 extends ServletResourceHandler<String> {
children = toJSONArray(status.getConflicting(), basePath, baseLocation, GitConstants.KEY_DIFF_DEFAULT);
result.put(GitConstants.KEY_STATUS_CONFLICTING, children);
+ // return repository state
+ result.put(GitConstants.KEY_REPOSITORY_STATE, db.getRepositoryState().name());
+
result.put(GitConstants.KEY_INDEX, statusToIndexLocation(baseLocation));
result.put(GitConstants.KEY_COMMIT, statusToCommitLocation(baseLocation, Constants.HEAD));
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/AllGitTests.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/AllGitTests.java
index 87e86fd..7e86363 100644
--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/AllGitTests.java
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/AllGitTests.java
@@ -18,7 +18,7 @@ import org.junit.runners.Suite.SuiteClasses;
* Runs all automated server tests for git support.
*/
@RunWith(Suite.class)
-@SuiteClasses({GitUriTest.class, GitCloneTest.class, GitInitTest.class, GitDiffTest.class, GitStatusTest.class, GitIndexTest.class, GitAddTest.class, GitResetTest.class, GitCommitTest.class, GitConfigTest.class, GitRemoteTest.class, GitFetchTest.class, GitMergeTest.class, GitPushTest.class, GitLogTest.class, GitTagTest.class, GitUtilsTest.class, GitCheckoutTest.class, GitBranchTest.class, GitCherryPickTest.class})
+@SuiteClasses({GitUriTest.class, GitCloneTest.class, GitInitTest.class, GitDiffTest.class, GitStatusTest.class, GitIndexTest.class, GitAddTest.class, GitResetTest.class, GitCommitTest.class, GitConfigTest.class, GitRemoteTest.class, GitFetchTest.class, GitMergeTest.class, GitRebaseTest.class, GitPushTest.class, GitLogTest.class, GitTagTest.class, GitUtilsTest.class, GitCheckoutTest.class, GitBranchTest.class, GitCherryPickTest.class})
public class AllGitTests {
//goofy junit4, no class body needed
}
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitRebaseTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitRebaseTest.java
new file mode 100644
index 0000000..a9f8d03
--- /dev/null
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitRebaseTest.java
@@ -0,0 +1,736 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.orion.server.tests.servlets.git;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URI;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.RebaseCommand.Operation;
+import org.eclipse.jgit.api.RebaseResult;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.orion.internal.server.servlets.ProtocolConstants;
+import org.eclipse.orion.server.core.ServerStatus;
+import org.eclipse.orion.server.git.AdditionalRebaseStatus;
+import org.eclipse.orion.server.git.GitConstants;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.Test;
+
+import com.meterware.httpunit.PostMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+public class GitRebaseTest extends GitTest {
+ @Test
+ public void testRebaseSelf() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
+ IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
+ IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)).append("folder").makeAbsolute();
+
+ IPath[] clonePaths = new IPath[] {clonePathTop, clonePathFolder};
+
+ for (IPath clonePath : clonePaths) {
+ // clone a repo
+ String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // get project metadata
+ WebRequest request = getGetFilesRequest(contentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project = new JSONObject(response.getText());
+ JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
+
+ String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+
+ // "git rebase master"
+ JSONObject rebase = rebase(gitHeadUri, Constants.MASTER);
+ RebaseResult.Status rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.UP_TO_DATE, rebaseResult);
+ }
+ }
+
+ @Test
+ public void testRebase() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
+ IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
+ IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)).append("folder").makeAbsolute();
+
+ IPath[] clonePaths = new IPath[] {clonePathTop, clonePathFolder};
+
+ for (IPath clonePath : clonePaths) {
+ // clone a repo
+ JSONObject clone = clone(clonePath);
+
+ String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+ String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
+ String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);
+
+ // get project metadata
+ WebRequest request = getGetFilesRequest(contentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project = new JSONObject(response.getText());
+ String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
+
+ JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
+
+ String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+ String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
+
+ // create branch 'a'
+ branch(branchesLocation, "a");
+
+ // checkout 'a'
+ Repository db1 = getRepositoryForContentLocation(contentLocation);
+ Git git = new Git(db1);
+ assertBranchExist(git, "a");
+ checkoutBranch(cloneLocation, "a");
+
+ // modify while on 'a'
+ request = getPutFileRequest(projectLocation + "/test.txt", "change in a");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit on a", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+
+ // checkout 'master'
+ checkoutBranch(cloneLocation, Constants.MASTER);
+
+ // modify a different file on master
+ request = getPutFileRequest(projectLocation + "/folder/folder.txt", "change in master");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ gitSection = project.getJSONObject(GitConstants.KEY_GIT);
+ gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+ gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
+ gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit on master", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+
+ // rebase: "git rebase a"
+ JSONObject rebase = rebase(gitHeadUri, "a");
+ RebaseResult.Status rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.OK, rebaseResult);
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+
+ request = getGetFilesRequest(projectLocation + "/test.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("change in a", response.getText());
+
+ request = getGetFilesRequest(projectLocation + "/folder/folder.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("change in master", response.getText());
+ }
+ }
+
+ @Test
+ public void testRebaseStopOnConflictAndAbort() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
+ IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
+ IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)).append("folder").makeAbsolute();
+
+ IPath[] clonePaths = new IPath[] {clonePathTop, clonePathFolder};
+
+ for (IPath clonePath : clonePaths) {
+ // clone a repo
+ JSONObject clone = clone(clonePath);
+
+ String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+ String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
+ String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);
+
+ // get project metadata
+ WebRequest request = getGetFilesRequest(contentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project = new JSONObject(response.getText());
+ String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
+
+ JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
+
+ String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+ String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
+
+ // modify file while on 'master'
+ request = getPutFileRequest(projectLocation + "/test.txt", "1\n2\n3");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "first commit on master", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // create branch 'a'
+ branch(branchesLocation, "a");
+
+ // modify file while on 'master'
+ request = getPutFileRequest(projectLocation + "/test.txt", "1master\n2\n3");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "second commit on master", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // checkout 'a'
+ Repository db1 = getRepositoryForContentLocation(contentLocation);
+ Git git = new Git(db1);
+ assertBranchExist(git, "a");
+ checkoutBranch(cloneLocation, "a");
+
+ // modify while on 'a' - conflicting change (first line) and non-conflicting (last line)
+ request = getPutFileRequest(projectLocation + "/test.txt", "1a\n2\n3\n4a");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "first commit on a", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+
+ // rebase: "git rebase master"
+ JSONObject rebase = rebase(gitHeadUri, "master");
+ RebaseResult.Status rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.STOPPED, rebaseResult);
+
+ // check conflicting file
+ request = getGetFilesRequest(projectLocation + "/test.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("<<<<<<< OURS\n1master\n=======\n1a\n>>>>>>> THEIRS\n2\n3\n4a\n", response.getText());
+
+ // abort rebase
+ rebase = rebase(gitHeadUri, Operation.ABORT);
+ rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.ABORTED, rebaseResult);
+
+ // file should reset to "a" branch
+ request = getGetFilesRequest(projectLocation + "/test.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("1a\n2\n3\n4a", response.getText());
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+ }
+ }
+
+ @Test
+ public void testRebaseStopOnConflictAndContinue() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
+ IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
+ IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)).append("folder").makeAbsolute();
+
+ IPath[] clonePaths = new IPath[] {clonePathTop, clonePathFolder};
+
+ for (IPath clonePath : clonePaths) {
+ // clone a repo
+ JSONObject clone = clone(clonePath);
+
+ String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+ String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
+ String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);
+
+ // get project metadata
+ WebRequest request = getGetFilesRequest(contentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project = new JSONObject(response.getText());
+ String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
+
+ JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
+
+ String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+ String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
+
+ // modify file while on 'master'
+ request = getPutFileRequest(projectLocation + "/test.txt", "1\n2\n3");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "first commit on master", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // create branch 'a'
+ branch(branchesLocation, "a");
+
+ // modify file while on 'master'
+ request = getPutFileRequest(projectLocation + "/test.txt", "1master\n2\n3");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "second commit on master", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // checkout 'a'
+ Repository db1 = getRepositoryForContentLocation(contentLocation);
+ Git git = new Git(db1);
+ assertBranchExist(git, "a");
+ checkoutBranch(cloneLocation, "a");
+
+ // modify while on 'a' - conflicting change (first line) and non-conflicting (last line)
+ request = getPutFileRequest(projectLocation + "/test.txt", "1a\n2\n3\n4a");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "first commit on a", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+
+ // rebase: "git rebase master"
+ JSONObject rebase = rebase(gitHeadUri, "master");
+ RebaseResult.Status rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.STOPPED, rebaseResult);
+
+ // check conflicting file
+ request = getGetFilesRequest(projectLocation + "/test.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("<<<<<<< OURS\n1master\n=======\n1a\n>>>>>>> THEIRS\n2\n3\n4a\n", response.getText());
+
+ // continue rebase without conflict resolving
+ rebase = rebase(gitHeadUri, Operation.CONTINUE);
+ AdditionalRebaseStatus errRebaseResult = AdditionalRebaseStatus.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(AdditionalRebaseStatus.FAILED_UNMERGED_PATHS, errRebaseResult);
+
+ // resolve conflict
+ request = getPutFileRequest(projectLocation + "/test.txt", "1amaster\n2\n3\n4a");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // and add
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // continue rebase
+ rebase = rebase(gitHeadUri, Operation.CONTINUE);
+ rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.OK, rebaseResult);
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+ }
+ }
+
+ @Test
+ public void testRebaseStopOnConflictAndSkipPatch() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
+ IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
+ IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)).append("folder").makeAbsolute();
+
+ IPath[] clonePaths = new IPath[] {clonePathTop, clonePathFolder};
+
+ for (IPath clonePath : clonePaths) {
+ // clone a repo
+ JSONObject clone = clone(clonePath);
+
+ String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+ String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
+ String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);
+
+ // get project metadata
+ WebRequest request = getGetFilesRequest(contentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project = new JSONObject(response.getText());
+ String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
+
+ JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
+
+ String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+ String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
+
+ // modify file while on 'master'
+ request = getPutFileRequest(projectLocation + "/test.txt", "1\n2\n3");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "first commit on master", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // create branch 'a'
+ branch(branchesLocation, "a");
+
+ // modify file while on 'master'
+ request = getPutFileRequest(projectLocation + "/test.txt", "1master\n2\n3");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "second commit on master", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // checkout 'a'
+ Repository db1 = getRepositoryForContentLocation(contentLocation);
+ Git git = new Git(db1);
+ assertBranchExist(git, "a");
+ checkoutBranch(cloneLocation, "a");
+
+ // modify while on 'a' - conflicting change (first line) and non-conflicting (last line)
+ request = getPutFileRequest(projectLocation + "/test.txt", "1a\n2\n3\n4a");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "first commit on a", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+
+ // rebase: "git rebase master"
+ JSONObject rebase = rebase(gitHeadUri, "master");
+ RebaseResult.Status rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.STOPPED, rebaseResult);
+
+ // check conflicting file
+ request = getGetFilesRequest(projectLocation + "/test.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("<<<<<<< OURS\n1master\n=======\n1a\n>>>>>>> THEIRS\n2\n3\n4a\n", response.getText());
+
+ // continue rebase without conflict resolving - error expected
+ rebase = rebase(gitHeadUri, Operation.CONTINUE);
+ AdditionalRebaseStatus errRebaseResult = AdditionalRebaseStatus.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(AdditionalRebaseStatus.FAILED_UNMERGED_PATHS, errRebaseResult);
+
+ // continue rebase
+ rebase = rebase(gitHeadUri, Operation.SKIP);
+ rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.OK, rebaseResult);
+
+ // file should reset to "master" branch
+ request = getGetFilesRequest(projectLocation + "/test.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("1master\n2\n3", response.getText());
+
+ // assert clean
+ request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ statusResponse = new JSONObject(response.getText());
+ GitStatusTest.assertStatusClean(statusResponse);
+ }
+ }
+
+ @Test
+ public void testRebaseInvalidOperation() throws Exception {
+ URI workspaceLocation = createWorkspace(getMethodName());
+ JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
+ IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
+ IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)).append("folder").makeAbsolute();
+
+ IPath[] clonePaths = new IPath[] {clonePathTop, clonePathFolder};
+
+ for (IPath clonePath : clonePaths) {
+ // clone a repo
+ String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // get project metadata
+ WebRequest request = getGetFilesRequest(contentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project = new JSONObject(response.getText());
+ JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
+
+ String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+
+ JSONObject rebase = rebase(gitHeadUri, Operation.CONTINUE);
+ AdditionalRebaseStatus errRebaseResult = AdditionalRebaseStatus.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(AdditionalRebaseStatus.FAILED_WRONG_REPOSITORY_STATE, errRebaseResult);
+
+ rebase = rebase(gitHeadUri, Operation.ABORT);
+ errRebaseResult = AdditionalRebaseStatus.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(AdditionalRebaseStatus.FAILED_WRONG_REPOSITORY_STATE, errRebaseResult);
+
+ rebase = rebase(gitHeadUri, Operation.SKIP);
+ errRebaseResult = AdditionalRebaseStatus.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(AdditionalRebaseStatus.FAILED_WRONG_REPOSITORY_STATE, errRebaseResult);
+ }
+ }
+
+ @Test
+ public void testRebaseOnRemote() 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) {
+ // clone1
+ String contentLocation1 = clone(clonePath[0]).getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // 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 project1Location = project1.getString(ProtocolConstants.KEY_LOCATION);
+ JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
+ String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);
+
+ // clone2
+ String contentLocation2 = clone(clonePath[1]).getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // get project2 metadata
+ request = getGetFilesRequest(contentLocation2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project2 = new JSONObject(response.getText());
+ String project2Location = project2.getString(ProtocolConstants.KEY_LOCATION);
+ JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
+ String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
+ String gitIndexUri2 = gitSection2.getString(GitConstants.KEY_INDEX);
+ String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD);
+
+ // clone1: get remote details
+ JSONObject details = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
+ String refId1 = details.getString(ProtocolConstants.KEY_ID);
+ String remoteBranchLocation1 = details.getString(ProtocolConstants.KEY_LOCATION);
+
+ // clone2: change
+ request = getPutFileRequest(project2Location + "/test.txt", "incoming change");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone2: add
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone2: commit
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri2, "incoming change commit", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // clone2: push
+ ServerStatus pushStatus = push(gitRemoteUri2, 1, 0, Constants.MASTER, Constants.HEAD, false);
+ assertEquals(true, pushStatus.isOK());
+
+ // clone1: fetch
+ request = GitFetchTest.getPostGitRemoteRequest(remoteBranchLocation1, true, false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_ACCEPTED, response.getResponseCode());
+ String taskLocation = response.getHeaderField(ProtocolConstants.HEADER_LOCATION);
+ assertNotNull(taskLocation);
+ waitForTaskCompletion(taskLocation);
+
+ // clone1: get remote details again
+ JSONObject remoteBranch = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
+ String newRefId1 = remoteBranch.getString(ProtocolConstants.KEY_ID);
+ // an incoming commit
+ assertFalse(refId1.equals(newRefId1));
+
+ String gitHeadUri = remoteBranch.getString(GitConstants.KEY_HEAD);
+ assertNotNull(gitHeadUri);
+
+ // rebase
+ JSONObject rebase = rebase(gitHeadUri, newRefId1);
+ RebaseResult.Status rebaseResult = RebaseResult.Status.valueOf(rebase.getString(GitConstants.KEY_RESULT));
+ assertEquals(RebaseResult.Status.FAST_FORWARD, rebaseResult);
+
+ request = getGetFilesRequest(project1Location + "/test.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ assertEquals("incoming change", response.getText());
+ }
+ }
+
+ public static WebRequest getPostGitRebaseRequest(String location, String commit, Operation operation) throws JSONException, UnsupportedEncodingException {
+ String requestURI;
+ if (location.startsWith("http://"))
+ requestURI = location;
+ else
+ requestURI = SERVER_LOCATION + GIT_SERVLET_LOCATION + GitConstants.COMMIT_RESOURCE + location;
+
+ JSONObject body = new JSONObject();
+ body.put(GitConstants.KEY_REBASE, commit);
+ if (operation != null)
+ body.put(GitConstants.KEY_OPERATION, operation.name());
+ WebRequest request = new PostMethodWebRequest(requestURI, getJsonAsStream(body.toString()), "UTF-8");
+ request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
+ setAuthentication(request);
+ return request;
+ }
+
+}
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 0aa7150..05d7fcb 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
@@ -45,6 +45,7 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.tests.harness.FileSystemHelper;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Constants;
@@ -449,6 +450,24 @@ public abstract class GitTest extends FileSystemTest {
return new JSONObject(response.getText());
}
+ // rebase
+
+ protected JSONObject rebase(String gitHeadUri, Operation operation) throws IOException, SAXException, JSONException {
+ assertCommitUri(gitHeadUri);
+ WebRequest request = GitRebaseTest.getPostGitRebaseRequest(gitHeadUri, "", operation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ return new JSONObject(response.getText());
+ }
+
+ protected JSONObject rebase(String gitHeadUri, String commit) throws IOException, SAXException, JSONException {
+ assertCommitUri(gitHeadUri);
+ WebRequest request = GitRebaseTest.getPostGitRebaseRequest(gitHeadUri, commit, null);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ return new JSONObject(response.getText());
+ }
+
// push
protected ServerStatus push(String gitRemoteUri, int size, int i, String name, String srcRef, boolean tags) throws IOException, SAXException, JSONException {