summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPiotr Janik2011-07-29 10:21:14 (EDT)
committer Tomasz Zarna2011-07-29 10:21:14 (EDT)
commit5c2cad5db4ed8c089e341bed295d24a220e23484 (patch)
treecb907629938f08397c4b6ca4bc86542e7dda38b5
parentb2763576023711485aa5553c2c31f18a5f2d3e7f (diff)
downloadorg.eclipse.orion.server-5c2cad5db4ed8c089e341bed295d24a220e23484.zip
org.eclipse.orion.server-5c2cad5db4ed8c089e341bed295d24a220e23484.tar.gz
org.eclipse.orion.server-5c2cad5db4ed8c089e341bed295d24a220e23484.tar.bz2
bug 346285 - [server][tag] Tagging with a tag name that already exist
should not throw 500 error https://bugs.eclipse.org/bugs/show_bug.cgi?id=346285
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java30
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitTagHandlerV1.java36
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTagTest.java71
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTest.java4
4 files changed, 114 insertions, 27 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 28259ac..821dc4c 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
@@ -570,21 +570,29 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
return false;
}
- private boolean tag(HttpServletRequest request, HttpServletResponse response, Repository db, String commitId, String tagName, boolean isRoot) throws AmbiguousObjectException, IOException, JGitInternalException, GitAPIException, JSONException, URISyntaxException {
+ private boolean tag(HttpServletRequest request, HttpServletResponse response, Repository db, String commitId, String tagName, boolean isRoot) throws JSONException, URISyntaxException, ServletException {
Git git = new Git(db);
- ObjectId objectId = db.resolve(commitId);
-
RevWalk walk = new RevWalk(db);
- RevCommit revCommit = walk.lookupCommit(objectId);
- walk.parseBody(revCommit);
+ try {
+ ObjectId objectId = db.resolve(commitId);
+ RevCommit revCommit = walk.lookupCommit(objectId);
+ walk.parseBody(revCommit);
- GitTagHandlerV1.tag(git, revCommit, tagName);
- Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(db);
+ GitTagHandlerV1.tag(git, revCommit, tagName);
+ Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(db);
- JSONObject result = toJSON(db, revCommit, commitToBranchMap, OrionServlet.getURI(request), null, isRoot);
- OrionServlet.writeJSONResponse(request, response, result);
- walk.dispose();
- return true;
+ JSONObject result = toJSON(db, revCommit, commitToBranchMap, OrionServlet.getURI(request), null, isRoot);
+ OrionServlet.writeJSONResponse(request, response, result);
+ return true;
+ } catch (IOException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when tagging.", e));
+ } catch (GitAPIException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when tagging.", e));
+ } catch (JGitInternalException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when tagging.", e));
+ } finally {
+ walk.dispose();
+ }
}
// from https://gist.github.com/839693, credits to zx
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitTagHandlerV1.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitTagHandlerV1.java
index 40b87fe..bd5de87 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitTagHandlerV1.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitTagHandlerV1.java
@@ -77,26 +77,34 @@ public class GitTagHandlerV1 extends ServletResourceHandler<String> {
return true;
}
- private boolean handlePost(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, JSONException, CoreException, JGitInternalException, GitAPIException {
+ private boolean handlePost(HttpServletRequest request, HttpServletResponse response, String path) throws CoreException, IOException, JSONException, ServletException {
IPath p = new Path(path);
File gitDir = GitUtils.getGitDir(p);
Repository db = new FileRepository(gitDir);
Git git = new Git(db);
- JSONObject toPut = OrionServlet.readJSONRequest(request);
- String tagName = toPut.getString(ProtocolConstants.KEY_NAME);
- String commitId = toPut.getString(GitConstants.KEY_TAG_COMMIT);
- ObjectId objectId = db.resolve(commitId);
-
RevWalk walk = new RevWalk(db);
- RevCommit revCommit = walk.lookupCommit(objectId);
+ try {
+ JSONObject toPut = OrionServlet.readJSONRequest(request);
+ String tagName = toPut.getString(ProtocolConstants.KEY_NAME);
+ String commitId = toPut.getString(GitConstants.KEY_TAG_COMMIT);
+ ObjectId objectId = db.resolve(commitId);
+ RevCommit revCommit = walk.lookupCommit(objectId);
- RevTag revTag = tag(git, revCommit, tagName);
- JSONObject result = new JSONObject();
- result.put(ProtocolConstants.KEY_NAME, revTag.getTagName());
- result.put(ProtocolConstants.KEY_CONTENT_LOCATION, OrionServlet.getURI(request));
- OrionServlet.writeJSONResponse(request, response, result);
- walk.dispose();
- return true;
+ RevTag revTag = tag(git, revCommit, tagName);
+ JSONObject result = new JSONObject();
+ result.put(ProtocolConstants.KEY_NAME, revTag.getTagName());
+ result.put(ProtocolConstants.KEY_CONTENT_LOCATION, OrionServlet.getURI(request));
+ OrionServlet.writeJSONResponse(request, response, result);
+ return true;
+ } catch (IOException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when tagging.", e));
+ } catch (GitAPIException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when tagging.", e));
+ } catch (JGitInternalException e) {
+ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when tagging.", e));
+ } finally {
+ walk.dispose();
+ }
}
static RevTag tag(Git git, RevCommit revCommit, String tagName) throws JGitInternalException, GitAPIException {
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTagTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTagTest.java
index ef1146e..faebe66 100644
--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTagTest.java
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitTagTest.java
@@ -115,4 +115,75 @@ public class GitTagTest extends GitTest {
assertEquals("tag2", tags.getJSONObject(1).get(ProtocolConstants.KEY_NAME));
}
}
+
+ @Test
+ public void testTagFailed() 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 cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // get project/folder metadata
+ WebRequest request = getGetFilesRequest(cloneContentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject folder = new JSONObject(response.getText());
+ String folderLocation = folder.getString(ProtocolConstants.KEY_LOCATION);
+
+ JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
+ String gitTagUri = gitSection.getString(GitConstants.KEY_TAG);
+ String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+
+ // tag HEAD with 'tag'
+ JSONObject tag = tag(gitTagUri, "tag", Constants.HEAD);
+ assertEquals("tag", tag.getString(ProtocolConstants.KEY_NAME));
+ new URI(tag.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
+
+ // tag HEAD with 'tag' again (TagHandler) - should fail
+ request = getPostGitTagRequest(gitTagUri, "tag", Constants.HEAD);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());
+
+ // tag HEAD with 'tag' again (CommitHandler) - should fail
+ request = getPutGitCommitRequest(gitHeadUri, "tag");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());
+
+ // modify
+ request = getPutFileRequest(folderLocation + "/test.txt", "test.txt change");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // add
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "folder/folder.txt");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit
+ request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit", false);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // tag next commit with 'tag' again (TagHandler) - should fail
+ request = getPostGitTagRequest(gitTagUri, "tag", Constants.HEAD);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());
+
+ // tag HEAD with 'tag' again (CommitHandler) - should fail
+ request = getPutGitCommitRequest(gitHeadUri, "tag");
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());
+ }
+ }
+
}
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 02a54b2..1ffa9ee 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
@@ -978,7 +978,7 @@ public abstract class GitTest extends FileSystemTest {
return request;
}
- private static WebRequest getPostGitTagRequest(String location, String tagName, String commitId) throws JSONException, UnsupportedEncodingException {
+ protected static WebRequest getPostGitTagRequest(String location, String tagName, String commitId) throws JSONException, UnsupportedEncodingException {
assertTagUri(location);
String requestURI;
if (location.startsWith("http://"))
@@ -995,7 +995,7 @@ public abstract class GitTest extends FileSystemTest {
return request;
}
- private static WebRequest getPutGitCommitRequest(String location, String tagName) throws UnsupportedEncodingException, JSONException {
+ protected static WebRequest getPutGitCommitRequest(String location, String tagName) throws UnsupportedEncodingException, JSONException {
String requestURI;
if (location.startsWith("http://"))
requestURI = location;