summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPiotr Janik2011-05-23 10:18:47 (EDT)
committer Tomasz Zarna2011-05-23 10:18:47 (EDT)
commit3feeddddf0721361c1590190f1352f3e3af2cdff (patch)
tree62032374da15ddf0bee9fd9467b9a8c296b4cfcf
parentb1dc248a244efb604a15cebddbba8baee1b454a4 (diff)
downloadorg.eclipse.orion.server-3feeddddf0721361c1590190f1352f3e3af2cdff.zip
org.eclipse.orion.server-3feeddddf0721361c1590190f1352f3e3af2cdff.tar.gz
org.eclipse.orion.server-3feeddddf0721361c1590190f1352f3e3af2cdff.tar.bz2
bug 339190 - [server] Allow to commit a single filev20110523-2020
https://bugs.eclipse.org/bugs/show_bug.cgi?id=339190
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java18
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitCommitTest.java16
2 files changed, 18 insertions, 16 deletions
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 893aa20..fe34e3a 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
@@ -20,8 +20,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.core.runtime.*;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.MergeResult;
+import org.eclipse.jgit.api.*;
import org.eclipse.jgit.api.errors.*;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
@@ -339,11 +338,6 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
if (newCommitToCreatelocation != null)
return createCommitLocation(request, response, db, newCommitToCreatelocation);
- // continue with commit
- if (path.segmentCount() > 3) {
- return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_IMPLEMENTED, "Committing by path is not yet supported.", null));
- }
-
ObjectId refId = db.resolve(path.segment(0));
if (refId == null || !Constants.HEAD.equals(path.segment(0))) {
String msg = NLS.bind("Commit failed. Ref must be HEAD and is {0}", path.segment(0)); //$NON-NLS-1$
@@ -357,10 +351,16 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null));
- Git git = new Git(db);
+ CommitCommand commit = new Git(db).commit();
+
+ // support for committing by path: "git commit -o path"
+ if (path.segmentCount() > 3) {
+ String p = path.removeFirstSegments(3).toString();
+ commit.setOnly(p);
+ }
// "git commit [--amend] -m '{message}' [-a|{path}]"
try {
- git.commit().setAmend(amend).setMessage(message).call();
+ commit.setAmend(amend).setMessage(message).call();
return true;
} catch (GitAPIException e) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "An error occured when commiting.", e));
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitCommitTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitCommitTest.java
index bea4505..34e1323 100644
--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitCommitTest.java
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitCommitTest.java
@@ -35,7 +35,6 @@ import com.meterware.httpunit.WebResponse;
public class GitCommitTest extends GitTest {
@Test
- @Ignore("not yet implemented, see bug 339190")
public void testCommit() throws Exception {
URI workspaceLocation = createWorkspace(getMethodName());
@@ -43,10 +42,6 @@ public class GitCommitTest extends GitTest {
JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString());
String projectId = project.getString(ProtocolConstants.KEY_ID);
- WebRequest request = getPutFileRequest(projectId + "/test.txt", "change to commit");
- WebResponse response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
-
JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
assertNotNull(gitSection);
String gitIndexUri = gitSection.optString(GitConstants.KEY_INDEX, null);
@@ -56,15 +51,23 @@ public class GitCommitTest extends GitTest {
String gitCommitUri = gitSection.optString(GitConstants.KEY_COMMIT, null);
assertNotNull(gitCommitUri);
+ // modify first file and add it to index
+ WebRequest request = getPutFileRequest(projectId + "/test.txt", "change to commit");
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// TODO: don't create URIs out of thin air
request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt");
response = webConversation.getResponse(request);
assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
- // TODO: don't create URIs out of thin air
+ // modify second file and add it to index
request = getPutFileRequest(projectId + "/folder/folder.txt", "change to commit");
response = webConversation.getResponse(request);
assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ // TODO: don't create URIs out of thin air
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "folder/folder.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
response = webConversation.getResponse(request);
@@ -74,7 +77,6 @@ public class GitCommitTest extends GitTest {
assertEquals(0, statusArray.length());
statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_CHANGED);
assertEquals(2, statusArray.length());
- assertEquals("test.txt", statusArray.getJSONObject(0).getString(ProtocolConstants.KEY_NAME));
statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MISSING);
assertEquals(0, statusArray.length());
statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MODIFIED);