Example usage for org.eclipse.jgit.lib Constants MASTER

List of usage examples for org.eclipse.jgit.lib Constants MASTER

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants MASTER.

Prototype

String MASTER

To view the source code for org.eclipse.jgit.lib Constants MASTER.

Click Source Link

Document

Default main branch name

Usage

From source file:org.eclipse.orion.server.tests.servlets.git.GitLogTest.java

License:Open Source License

@Test
public void testLogWithBranch() 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);
        String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);

        // get project metadata
        WebRequest request = getGetFilesRequest(cloneContentLocation);
        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 gitCommitUri = gitSection.getString(GitConstants.KEY_COMMIT);

        JSONArray commitsArray = log(gitCommitUri, true);
        assertEquals(1, commitsArray.length());

        branch(branchesLocation, "branch");

        commitsArray = log(gitCommitUri, true);
        assertEquals(1, commitsArray.length());

        JSONArray branchesArray = commitsArray.getJSONObject(0).getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(3, branchesArray.length());
        assertEquals(Constants.R_HEADS + "branch",
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));
        assertEquals(Constants.R_HEADS + Constants.MASTER,
                branchesArray.getJSONObject(1).get(ProtocolConstants.KEY_FULL_NAME));
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER,
                branchesArray.getJSONObject(2).get(ProtocolConstants.KEY_FULL_NAME));
    }//from   w w w.  ja v  a 2 s  . c o m
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitLogTest.java

License:Open Source License

@Test
public void testLogAllBranches() 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 cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
        String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);
        String gitCommitUri = clone.getString(GitConstants.KEY_COMMIT);

        // get project metadata
        WebRequest request = getGetFilesRequest(cloneContentLocation);
        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 gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

        // create branch
        final String newBranchName = "branch";
        branch(branchesLocation, newBranchName);

        // modify
        String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
        request = getPutFileRequest(projectLocation + "test.txt", "first change");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // add/*from   w w  w .j av a  2  s.c om*/
        request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // commit1
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit1", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // checkout "branch"
        checkoutBranch(cloneLocation, newBranchName);

        // modify again
        request = getPutFileRequest(projectLocation + "test.txt", "second change");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // add
        request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // commit2
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit2", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // get standard log for HEAD - only init and commit2 should be visible
        JSONArray commitsArray = log(gitHeadUri, false);
        assertEquals(2, commitsArray.length());

        JSONObject commit = commitsArray.getJSONObject(0);
        assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE));

        commit = commitsArray.getJSONObject(1);
        assertEquals("Initial commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE));

        // get log for all branches - initial commit, commit1 and commit2 should be visible
        commitsArray = log(gitCommitUri, false);
        assertEquals(3, commitsArray.length());

        commit = commitsArray.getJSONObject(0);
        assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE));
        JSONArray branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(1, branchesArray.length());
        assertEquals(Constants.R_HEADS + newBranchName,
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));

        commit = commitsArray.getJSONObject(1);
        assertEquals("commit1", commit.get(GitConstants.KEY_COMMIT_MESSAGE));
        branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(1, branchesArray.length());
        assertEquals(Constants.R_HEADS + Constants.MASTER,
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));

        commit = commitsArray.getJSONObject(2);
        assertEquals("Initial commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE));
        branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(1, branchesArray.length());
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER,
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));
    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitLogTest.java

License:Open Source License

@Test
public void testToRefKey() 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);

        // git log for HEAD
        request = GitCommitTest.getGetGitCommitRequest(gitHeadUri, false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject log = new JSONObject(response.getText());

        // project contains only initial commit, so HEAD points to master branch
        // information about master branch is expected
        JSONObject toRef = log.getJSONObject(GitConstants.KEY_LOG_TO_REF);

        assertEquals(gitHeadUri, toRef.getString(GitConstants.KEY_HEAD));
        assertEquals(gitSection.getString(GitConstants.KEY_CLONE), toRef.getString(GitConstants.KEY_CLONE));
        assertEquals(GitConstants.KEY_BRANCH_NAME, toRef.getString(ProtocolConstants.KEY_TYPE));
        assertEquals(Constants.MASTER, toRef.getString(ProtocolConstants.KEY_NAME));
        assertEquals(true, toRef.getBoolean(GitConstants.KEY_BRANCH_CURRENT));
    }/*from  ww  w  .j  av  a 2 s .  c o m*/
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitLogTest.java

License:Open Source License

@Test
public void testFromRefKey() 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 logUri = gitHeadUri.replace(Constants.HEAD, Constants.HEAD + ".." + Constants.HEAD);
        // git log for HEAD..HEAD
        request = GitCommitTest.getGetGitCommitRequest(logUri, false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject log = new JSONObject(response.getText());

        // project contains only initial commit, so HEAD points to master branch
        // information about master branch is expected
        JSONObject fromRef = log.getJSONObject(GitConstants.KEY_LOG_FROM_REF);

        assertEquals(gitHeadUri, fromRef.getString(GitConstants.KEY_HEAD));
        assertEquals(gitSection.getString(GitConstants.KEY_CLONE), fromRef.getString(GitConstants.KEY_CLONE));
        assertEquals(GitConstants.KEY_BRANCH_NAME, fromRef.getString(ProtocolConstants.KEY_TYPE));
        assertEquals(Constants.MASTER, fromRef.getString(ProtocolConstants.KEY_NAME));
        assertEquals(true, fromRef.getBoolean(GitConstants.KEY_BRANCH_CURRENT));
    }/*from   w ww .ja v a 2  s  .co  m*/
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitMergeSquashTest.java

License:Open Source License

@Test
public void testMergeSquashSelf() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());

    String projectName = getMethodName();
    JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString());

    JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);//from w w w.  j  a  v  a 2  s .c o m
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

    // "git merge master"
    JSONObject merge = merge(gitHeadUri, Constants.MASTER, true);
    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.ALREADY_UP_TO_DATE, mergeResult);
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitMergeSquashTest.java

License:Open Source License

@Test
public void testMergeSquash() throws Exception {
    // clone a repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    JSONObject clone = clone(clonePath);
    String cloneContentLocation = 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 = getGetFilesRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());

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

    // checkout 'a'
    Repository db1 = getRepositoryForContentLocation(cloneContentLocation);
    Git git = new Git(db1);
    assertBranchExist(git, "a");
    checkoutBranch(cloneLocation, "a");

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

    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String 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 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 folder1 = getChild(project, "folder");
    JSONObject folderTxt = getChild(folder1, "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);

    // merge: "git merge a"
    JSONObject merge = merge(gitHeadUri, "a", true);
    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.MERGED_SQUASHED, mergeResult);

    // assert clean
    //assertStatus(StatusResult.CLEAN, gitStatusUri);

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

    request = getGetFilesRequest(folderTxt.getString(ProtocolConstants.KEY_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals("change in master", response.getText());

    // TODO: check commits, bug 340051
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitMergeSquashTest.java

License:Open Source License

@Test
public void testMergeSquashAlreadyUpToDate() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());

    String projectName = getMethodName();
    JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString());

    JSONObject testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "change in master");

    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

    // "git add ."
    WebRequest request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    assertStatus(new StatusResult().setChanged(1), gitStatusUri);

    // "git merge master"
    JSONObject merge = merge(gitHeadUri, Constants.MASTER, true);
    MergeStatus mergeResult = MergeResult.MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, mergeResult);

    // status hasn't changed
    assertStatus(new StatusResult().setChanged(1), gitStatusUri);
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitMergeSquashTest.java

License:Open Source License

@Test
public void testMergeSquashConflict() throws Exception {
    // clone a repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    JSONObject clone = clone(clonePath);
    String cloneContentLocation = 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 = getGetFilesRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());
    JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);/*from  w w  w.ja v  a 2  s  .  co m*/
    String gitRemoteUri = gitSection.optString(GitConstants.KEY_REMOTE, null);
    assertNotNull(gitRemoteUri);

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

    // checkout 'a'
    Repository db1 = getRepositoryForContentLocation(cloneContentLocation);
    Git git = new Git(db1);
    assertBranchExist(git, "a");
    checkoutBranch(cloneLocation, "a");

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

    gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String 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 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 the same file on master
    modifyFile(testTxt, "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);

    // merge: "git merge a"
    JSONObject merge = merge(gitHeadUri, "a", true);
    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.CONFLICTING, mergeResult);

    // check status
    assertStatus(new StatusResult().setConflictingNames("test.txt"), gitStatusUri);

    request = getGetFilesRequest(testTxt.getString(ProtocolConstants.KEY_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    String[] responseLines = response.getText().split("\n");
    assertEquals(5, responseLines.length);
    assertEquals("<<<<<<< HEAD", responseLines[0]);
    assertEquals("change in master", responseLines[1]);
    assertEquals("=======", responseLines[2]);
    assertEquals("change in a", responseLines[3]);
    // ignore the last line since it's different each time
    // assertEquals(">>>>>>> c5ddb0e22e7e829683bb3b336ca6cb24a1b5bb2e", responseLines[4]);

    // TODO: check commits, bug 340051
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitMergeSquashTest.java

License:Open Source License

@Test
public void testMergeSquashIntoLocalFailedDirtyWorkTree() throws Exception {
    // clone a repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    clone(clonePath);/*from  ww  w .  j  av  a 2 s.c om*/

    // get project metadata
    WebRequest request = getGetFilesRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());
    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
    String gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);

    // add a parallel commit in secondary clone and push it to the remote
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    IPath clonePath2 = getClonePath(workspaceId, project2);
    clone(clonePath2);

    // get project2 metadata
    request = getGetFilesRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());
    JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);

    JSONObject testTxt = getChild(project2, "test.txt");
    modifyFile(testTxt, "change in secondary");
    addFile(testTxt);
    commitFile(testTxt, "commit on branch", false);

    ServerStatus pushStatus = push(gitRemoteUri2, 1, 0, Constants.MASTER, Constants.HEAD, false);
    assertEquals(true, pushStatus.isOK());

    // modify on master and try to merge
    testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "dirty");

    JSONObject masterDetails = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER);
    String masterLocation = masterDetails.getString(ProtocolConstants.KEY_LOCATION);
    fetch(masterLocation);
    JSONObject merge = merge(gitHeadUri, Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER, true);

    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.FAILED, mergeResult);
    JSONObject failingPaths = merge.getJSONObject(GitConstants.KEY_FAILING_PATHS);
    assertEquals(1, failingPaths.length());
    assertEquals(MergeFailureReason.DIRTY_WORKTREE,
            MergeFailureReason.valueOf(failingPaths.getString("test.txt")));
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitMergeSquashTest.java

License:Open Source License

@Test
public void testMergeSquashFailedDirtyWorkTree() throws Exception {
    // clone a repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    JSONObject clone = clone(clonePath);
    String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
    String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);

    // get project metadata
    WebRequest request = getGetFilesRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());
    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);

    final String branch = "branch";

    branch(branchesLocation, branch);/*from w  ww .j a va2 s. c  o  m*/
    checkoutBranch(cloneLocation, branch);

    // create commit on branch
    JSONObject testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "change in a");
    addFile(testTxt);
    commitFile(testTxt, "commit on branch", false);

    // assert clean
    gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    assertStatus(StatusResult.CLEAN, gitStatusUri);

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

    // modify the same file on master
    modifyFile(testTxt, "change in master");

    gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

    addFile(testTxt);
    commitFile(testTxt, "commit on master", false);

    // modify again
    modifyFile(testTxt, "change in the working dir");

    // assert clean
    assertStatus(new StatusResult().setModified(1), gitStatusUri);

    // merge: "git merge branch"
    JSONObject merge = merge(gitHeadUri, branch, true);
    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.FAILED, mergeResult);
    JSONObject failingPaths = merge.getJSONObject(GitConstants.KEY_FAILING_PATHS);
    assertEquals(1, failingPaths.length());
    assertEquals(MergeFailureReason.DIRTY_WORKTREE,
            MergeFailureReason.valueOf(failingPaths.getString("test.txt")));
}