aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Janik2011-07-26 07:24:06 (EDT)
committerTomasz Zarna2011-07-26 07:24:06 (EDT)
commit806c6a80be47766bddd5c3fab030d19d3cbb7846 (patch)
tree42d0bb9141925c4c63a0a1783956d89ba3091ec9
parent677aee4c75e8552b6b0eb12d9a0a4612c013188b (diff)
downloadorg.eclipse.orion.server-806c6a80be47766bddd5c3fab030d19d3cbb7846.zip
org.eclipse.orion.server-806c6a80be47766bddd5c3fab030d19d3cbb7846.tar.gz
org.eclipse.orion.server-806c6a80be47766bddd5c3fab030d19d3cbb7846.tar.bz2
bug 350422 - [commit][status] Specify the committer and author
names/mails per commit https://bugs.eclipse.org/bugs/show_bug.cgi?id=350422
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCommitHandlerV1.java19
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitCommitTest.java196
2 files changed, 214 insertions, 1 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 731ed33..fec4f54 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
@@ -393,9 +393,28 @@ public class GitCommitHandlerV1 extends ServletResourceHandler<String> {
boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null));
+ String committerName = requestObject.optString(GitConstants.KEY_COMMITTER_NAME, null);
+ String committerEmail = requestObject.optString(GitConstants.KEY_COMMITTER_EMAIL, null);
+ String authorName = requestObject.optString(GitConstants.KEY_AUTHOR_NAME, null);
+ String authorEmail = requestObject.optString(GitConstants.KEY_AUTHOR_EMAIL, null);
+
Git git = new Git(db);
CommitCommand commit = git.commit();
+ // workaround of a bug in JGit which causes invalid
+ // support of null values of author/committer name/email
+ PersonIdent defPersonIdent = new PersonIdent(db);
+ if (committerName == null)
+ committerName = defPersonIdent.getName();
+ if (committerEmail == null)
+ committerEmail = defPersonIdent.getEmailAddress();
+ if (authorName == null)
+ authorName = committerName;
+ if (authorEmail == null)
+ authorEmail = committerEmail;
+ commit.setCommitter(committerName, committerEmail);
+ commit.setAuthor(authorName, authorEmail);
+
// support for committing by path: "git commit -o path"
boolean isRoot = true;
String pattern = GitUtils.getRelativePath(path.removeFirstSegments(1), set.iterator().next().getKey());
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 0f5a85a..04c4871 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
@@ -523,7 +523,193 @@ public class GitCommitTest extends GitTest {
}
}
- static WebRequest getPostGitCommitRequest(String location, String message, boolean amend) throws JSONException, UnsupportedEncodingException {
+ @Test
+ public void testCommitWithCommiterOverwritten() 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);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ final String commiterName = "committer name";
+ final String commiterEmail = "committer email";
+
+ request = getPostGitCommitRequest(gitHeadUri, "Comit message", false, commiterName, commiterEmail, null, null);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // log
+ JSONArray commitsArray = log(gitHeadUri, false);
+ assertEquals(2, commitsArray.length());
+
+ JSONObject commit = commitsArray.getJSONObject(0);
+ assertEquals(commiterName, commit.get(GitConstants.KEY_COMMITTER_NAME));
+ assertEquals(commiterEmail, commit.get(GitConstants.KEY_COMMITTER_EMAIL));
+ }
+ }
+
+ @Test
+ public void testCommitWithAuthorOverwritten() 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);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit all
+ final String commiterName = "committer name";
+ final String commiterEmail = "committer email";
+
+ request = getPostGitCommitRequest(gitHeadUri, "Comit message", false, commiterName, commiterEmail, null, null);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // log
+ JSONArray commitsArray = log(gitHeadUri, false);
+ assertEquals(2, commitsArray.length());
+
+ JSONObject commit = commitsArray.getJSONObject(0);
+ assertEquals(commiterName, commit.get(GitConstants.KEY_COMMITTER_NAME));
+ assertEquals(commiterEmail, commit.get(GitConstants.KEY_COMMITTER_EMAIL));
+ }
+ }
+
+ @Test
+ public void testCommitterAndAuthorFallback() 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);
+ String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
+ String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);
+
+ // set user.name and user.email
+ final String name = "name";
+ final String email = "email";
+ final String defaultName = "default name";
+ final String defaultEmail = "default email";
+ request = GitConfigTest.getPostGitConfigRequest(gitConfigUri, "user.name", defaultName);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
+ request = GitConfigTest.getPostGitConfigRequest(gitConfigUri, "user.email", defaultEmail);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
+
+ // "git add ."
+ request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // commit - author and commiter not specified
+ request = getPostGitCommitRequest(gitHeadUri, "1", false, null, null, null, null);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // log - expect default values
+ JSONArray commitsArray = log(gitHeadUri, false);
+ assertEquals(2, commitsArray.length());
+
+ JSONObject commit = commitsArray.getJSONObject(0);
+ assertEquals(defaultName, commit.get(GitConstants.KEY_COMMITTER_NAME));
+ assertEquals(defaultEmail, commit.get(GitConstants.KEY_COMMITTER_EMAIL));
+ assertEquals(defaultName, commit.get(GitConstants.KEY_AUTHOR_NAME));
+ assertEquals(defaultEmail, commit.get(GitConstants.KEY_AUTHOR_EMAIL));
+
+ // commit - only committer given
+ request = getPostGitCommitRequest(gitHeadUri, "2", true, name, email, null, null);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // log - expect author is the same as committer
+ commitsArray = log(gitHeadUri, false);
+ assertEquals(2, commitsArray.length());
+
+ commit = commitsArray.getJSONObject(0);
+ assertEquals(name, commit.get(GitConstants.KEY_COMMITTER_NAME));
+ assertEquals(email, commit.get(GitConstants.KEY_COMMITTER_EMAIL));
+ assertEquals(name, commit.get(GitConstants.KEY_AUTHOR_NAME));
+ assertEquals(email, commit.get(GitConstants.KEY_AUTHOR_EMAIL));
+
+ // commit - only committer name given
+ request = getPostGitCommitRequest(gitHeadUri, "3", true, name, null, null, null);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // log - expect author is the same as committer and their email is defaultEmail
+ commitsArray = log(gitHeadUri, false);
+ assertEquals(2, commitsArray.length());
+
+ commit = commitsArray.getJSONObject(0);
+ assertEquals(name, commit.get(GitConstants.KEY_COMMITTER_NAME));
+ assertEquals(defaultEmail, commit.get(GitConstants.KEY_COMMITTER_EMAIL));
+ assertEquals(name, commit.get(GitConstants.KEY_AUTHOR_NAME));
+ assertEquals(defaultEmail, commit.get(GitConstants.KEY_AUTHOR_EMAIL));
+ }
+ }
+
+ static WebRequest getPostGitCommitRequest(String location, String message, boolean amend, String committerName, String committerEmail, String authorName, String authorEmail) throws JSONException, UnsupportedEncodingException {
String requestURI;
if (location.startsWith("http://"))
requestURI = location;
@@ -535,12 +721,20 @@ public class GitCommitTest extends GitTest {
JSONObject body = new JSONObject();
body.put(GitConstants.KEY_COMMIT_MESSAGE, message);
body.put(GitConstants.KEY_COMMIT_AMEND, Boolean.toString(amend));
+ body.put(GitConstants.KEY_COMMITTER_NAME, committerName);
+ body.put(GitConstants.KEY_COMMITTER_EMAIL, committerEmail);
+ body.put(GitConstants.KEY_AUTHOR_NAME, authorName);
+ body.put(GitConstants.KEY_AUTHOR_EMAIL, authorEmail);
WebRequest request = new PostMethodWebRequest(requestURI, getJsonAsStream(body.toString()), "UTF-8");
request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
setAuthentication(request);
return request;
}
+ static WebRequest getPostGitCommitRequest(String location, String message, boolean amend) throws JSONException, UnsupportedEncodingException {
+ return getPostGitCommitRequest(location, message, amend, null, null, null, null);
+ }
+
static WebRequest getGetGitCommitRequest(String location, boolean body) {
return getGetGitCommitRequest(location, body, null, null);
}