summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPiotr Janik2011-06-13 10:31:57 (EDT)
committer Szymon Brandys2011-06-13 10:31:57 (EDT)
commit1bc9254ef2a3bb989b5726377b2bb96257ab345d (patch)
treec2f144fa56e99b1be2aa600e4cf6890523a29647
parentf5e4c18e0635bdc362496e79ed598d2691cdb9ce (diff)
downloadorg.eclipse.orion.server-1bc9254ef2a3bb989b5726377b2bb96257ab345d.zip
org.eclipse.orion.server-1bc9254ef2a3bb989b5726377b2bb96257ab345d.tar.gz
org.eclipse.orion.server-1bc9254ef2a3bb989b5726377b2bb96257ab345d.tar.bz2
bug 343247 - [server][git] Git Commit operation returns empty response
https://bugs.eclipse.org/bugs/show_bug.cgi?id=343247
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java17
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitCommitTest.java10
2 files changed, 22 insertions, 5 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 2ae4893..4567e0f 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
@@ -258,7 +258,9 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
JSONArray diffs = new JSONArray();
final TreeWalk tw = new TreeWalk(db);
- tw.reset(revCommit.getParent(0).getTree(), revCommit.getTree());
+ final RevWalk rw = new RevWalk(db);
+ RevCommit parent = rw.parseCommit(revCommit.getParent(0));
+ tw.reset(parent.getTree(), revCommit.getTree());
tw.setRecursive(true);
if (filter != null)
@@ -357,16 +359,23 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null));
- CommitCommand commit = new Git(db).commit();
+ Git git = new Git(db);
+ CommitCommand commit = git.commit();
// support for committing by path: "git commit -o path"
+ boolean isRoot = true;
String pattern = GitUtils.getRelativePath(path.removeFirstSegments(1), set.iterator().next().getKey());
if (!pattern.isEmpty()) {
commit.setOnly(pattern);
+ isRoot = false;
}
- // "git commit [--amend] -m '{message}' [-a|{path}]"
+
try {
- commit.setAmend(amend).setMessage(message).call();
+ // "git commit [--amend] -m '{message}' [-a|{path}]"
+ RevCommit lastCommit = commit.setAmend(amend).setMessage(message).call();
+
+ JSONObject result = toJSON(db, lastCommit, getURI(request), null, isRoot);
+ OrionServlet.writeJSONResponse(request, response, result);
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 59b8273..3dea2d9 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
@@ -88,10 +88,18 @@ public class GitCommitTest extends GitTest {
// TODO: don't create URIs out of thin air
// "git commit -m 'message' -- test.txt
- request = getPostGitCommitRequest(gitHeadUri + "test.txt", "message", false);
+ final String commitMessage = "message";
+ request = getPostGitCommitRequest(gitHeadUri + "test.txt", commitMessage, false);
response = webConversation.getResponse(request);
assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ // check if response contains most important parts and if commit
+ // message is valid
+ JSONObject commit = new JSONObject(response.getText());
+ assertNotNull(commit.optString(ProtocolConstants.KEY_LOCATION, null));
+ assertNotNull(commit.optString(ProtocolConstants.KEY_NAME, null));
+ assertEquals(commitMessage, commit.getString(GitConstants.KEY_COMMIT_MESSAGE));
+
request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
response = webConversation.getResponse(request);
assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());