Java Code Examples for org.eclipse.jgit.api.RebaseResult#Status

The following examples show how to use org.eclipse.jgit.api.RebaseResult#Status . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitRebaseTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testRebaseSelf() throws Exception {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[] clonePaths = createTestProjects(workspaceLocation);

	for (IPath clonePath : clonePaths) {
		// clone a  repo
		String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

		// get project metadata
		WebRequest request = getGetRequest(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);
	}
}
 
Example 2
Source File: GitRebaseResult.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static RebaseStatus parseRebaseStatus (RebaseResult.Status rebaseStatus) {
    switch (rebaseStatus) {
        case EDIT:
            return RebaseStatus.STOPPED;
        case UNCOMMITTED_CHANGES:
            return RebaseStatus.FAILED;
        case INTERACTIVE_PREPARED:
            return RebaseStatus.STOPPED;
        case STASH_APPLY_CONFLICTS:
            return RebaseStatus.CONFLICTS;
            
    }
    return GitRebaseResult.RebaseStatus.valueOf(rebaseStatus.name());
}
 
Example 3
Source File: GitEnumsStateTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testRebaseStatus () {
    for (RebaseResult.Status status : RebaseResult.Status.values()) {
        assertNotNull(GitRebaseResult.parseRebaseStatus(status));
    }
}
 
Example 4
Source File: GitRebaseTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testRebase() throws Exception {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[] clonePaths = createTestProjects(workspaceLocation);

	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 = getGetRequest(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 gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);

		// create branch 'a'
		branch(branchesLocation, "a");

		// checkout 'a'
		Repository db1 = getRepositoryForContentLocation(contentLocation);
		Git git = Git.wrap(db1);
		assertBranchExist(git, "a");
		checkoutBranch(cloneLocation, "a");

		// modify while on 'a'
		JSONObject testTxt = getChild(project, "test.txt");
		modifyFile(testTxt, "change in a");

		// "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
		assertStatus(StatusResult.CLEAN, gitStatusUri);

		// checkout 'master'
		checkoutBranch(cloneLocation, Constants.MASTER);

		// modify a different file on master
		JSONObject folder = getChild(project, "folder");
		JSONObject folderTxt = getChild(folder, "folder.txt");
		modifyFile(folderTxt, "change in master");

		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
		assertStatus(StatusResult.CLEAN, gitStatusUri);

		// 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
		assertStatus(StatusResult.CLEAN, gitStatusUri);

		request = getGetRequest(testTxt.getString(ProtocolConstants.KEY_LOCATION));
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		assertEquals("change in a", response.getText());

		request = getGetRequest(folderTxt.getString(ProtocolConstants.KEY_LOCATION));
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		assertEquals("change in master", response.getText());
	}
}
 
Example 5
Source File: GitRebaseTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testRebaseOnRemote() throws Exception {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	IPath[][] clonePaths = createTestClonePairs(workspaceLocation);

	for (IPath[] clonePath : clonePaths) {
		// clone1
		String contentLocation1 = clone(clonePath[0]).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

		// get project1 metadata
		WebRequest request = getGetRequest(contentLocation1);
		WebResponse response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		JSONObject project1 = new JSONObject(response.getText());
		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 = getGetRequest(contentLocation2);
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		JSONObject project2 = new JSONObject(response.getText());
		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
		JSONObject testTxt2 = getChild(project2, "test.txt");
		modifyFile(testTxt2, "incoming change");

		// 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);
		ServerStatus status = waitForTask(response);
		assertTrue(status.toString(), status.isOK());

		// 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);

		JSONObject testTxt1 = getChild(project1, "test.txt");
		request = getGetRequest(testTxt1.getString(ProtocolConstants.KEY_LOCATION));
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
		assertEquals("incoming change", response.getText());
	}
}