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

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

Introduction

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

Prototype

String DEFAULT_REMOTE_NAME

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

Click Source Link

Document

Default remote name used by clone, push and fetch operations

Usage

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

License:Open Source License

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

        // get project/folder metadata
        WebRequest request = getGetFilesRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject project = new JSONObject(response.getText());

        String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
        JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
        String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
        String gitRemoteUri = gitSection.optString(GitConstants.KEY_REMOTE);

        // create local branch tracking origin/master
        final String BRANCH_NAME = "a";
        final String REMOTE_BRANCH = Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER;

        branch(branchesLocation, BRANCH_NAME, REMOTE_BRANCH);

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

        // add//from www.  jav  a  2s  .c o  m
        request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

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

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

        // TODO: replace with RESTful API for git pull when available
        // try to pull - up to date status is expected
        Git git = new Git(getRepositoryForContentLocation(cloneContentLocation));
        PullResult pullResults = git.pull().call();
        assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom());
        assertEquals(MergeStatus.ALREADY_UP_TO_DATE, pullResults.getMergeResult().getMergeStatus());
        assertNull(pullResults.getRebaseResult());

        // checkout branch which was created a moment ago
        response = checkoutBranch(cloneLocation, BRANCH_NAME);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // TODO: replace with RESTful API for git pull when available
        // try to pull again - now fast forward update is expected
        pullResults = git.pull().call();
        assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom());
        assertEquals(MergeStatus.FAST_FORWARD, pullResults.getMergeResult().getMergeStatus());
        assertNull(pullResults.getRebaseResult());
    }
}

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

License:Open Source License

@Test
public void testFetchRemoteBranchUpToDate() throws Exception {
    // clone a repo
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    clone(clonePath);//from ww w .ja  v a2 s . co m

    // 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 gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);

    // list remotes
    request = GitRemoteTest.getGetGitRemoteRequest(gitRemoteUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject remotes = new JSONObject(response.getText());
    JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, remotesArray.length());
    JSONObject remote = remotesArray.getJSONObject(0);
    assertNotNull(remote);
    assertEquals(Constants.DEFAULT_REMOTE_NAME, remote.getString(ProtocolConstants.KEY_NAME));
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);
    assertNotNull(remoteLocation);

    // get remote details
    JSONObject details = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER);
    String refId = details.getString(ProtocolConstants.KEY_ID);
    String remoteBranchLocation = details.getString(ProtocolConstants.KEY_LOCATION);

    // fetch
    fetch(remoteBranchLocation);

    // get remote details again
    String newRefId = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER).getString(ProtocolConstants.KEY_ID);
    // up to date
    assertEquals(refId, newRefId);
}

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

License:Open Source License

@Test
public void testFetchRemoteUpToDate() throws Exception {
    // clone a repo
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    clone(clonePath);/*from w ww.  j  av a2  s  .  com*/

    // 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);
    String gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);

    // list remotes
    JSONObject remote = getRemote(gitRemoteUri, 1, 0, Constants.DEFAULT_REMOTE_NAME);
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);

    // get remote details
    JSONObject details = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER);
    String refId = details.getString(ProtocolConstants.KEY_ID);

    // fetch
    fetch(remoteLocation);

    // get remote details again
    String newRefId = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER).getString(ProtocolConstants.KEY_ID);
    // up to date
    assertEquals(refId, newRefId);
}

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

License:Open Source License

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

    // clone1//from  w w w .  ja  v  a2  s.c o m
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    IPath clonePath1 = new Path("file").append(project1.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    String contentLocation1 = clone(clonePath1).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

    // get project1 metadata
    WebRequest request = getGetFilesRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());
    JSONObject gitSection1 = project1.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection1);
    String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);

    // clone2
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    String projectId2 = project2.getString(ProtocolConstants.KEY_ID);
    IPath clonePath2 = new Path("file").append(project2.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    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.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection2);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
    String gitIndexUri2 = gitSection2.getString(GitConstants.KEY_INDEX);
    String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD);

    // clone2: change
    request = getPutFileRequest(projectId2 + "/test.txt", "incoming change");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

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

    JSONObject masterDetails = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String refId1 = masterDetails.getString(ProtocolConstants.KEY_ID);
    String remoteBranchLocation = masterDetails.getString(ProtocolConstants.KEY_LOCATION);

    // clone1: fetch
    fetch(remoteBranchLocation);

    masterDetails = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String newRefId1 = masterDetails.getString(ProtocolConstants.KEY_ID);
    assertFalse(newRefId1.equals(refId1));

    // clone1: log master..origin/master
    // TODO replace with tests methods from GitLogTest, bug 340051
    Repository db1 = getRepositoryForContentLocation(contentLocation1);
    ObjectId master = db1.resolve(Constants.MASTER);
    ObjectId originMaster = db1
            .resolve(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + Constants.MASTER);
    Git git = new Git(db1);
    Iterable<RevCommit> commits = git.log().addRange(master, originMaster).call();
    int c = 0;
    for (RevCommit commit : commits) {
        assertEquals("incoming change commit", commit.getFullMessage());
        c++;
    }
    // a single incoming commit
    assertEquals(1, c);
}

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

License:Open Source License

@Test
public void testPushAndFetchWithPrivateKeyAndPassphrase() throws Exception {

    Assume.assumeTrue(sshRepo2 != null);
    Assume.assumeTrue(knownHosts2 != null);
    Assume.assumeTrue(privateKey != null);
    Assume.assumeTrue(passphrase != null);

    URI workspaceLocation = createWorkspace(getMethodName());
    URIish uri = new URIish(sshRepo2);

    // clone1: create
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    IPath clonePath = new Path("file").append(project1.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    WebRequest request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath)
            .setKnownHosts(knownHosts2).setPrivateKey(privateKey).setPublicKey(publicKey)
            .setPassphrase(passphrase).getWebRequest();
    String cloneContentLocation1 = clone(request);

    // clone1: get project/folder metadata
    request = getGetFilesRequest(cloneContentLocation1);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());

    // clone1: get git links
    JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);

    // clone2: create
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    String projectId2 = project2.getString(ProtocolConstants.KEY_ID);
    clonePath = new Path("file").append(projectId2).makeAbsolute();
    request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath).setKnownHosts(knownHosts2)
            .setPrivateKey(privateKey).setPublicKey(publicKey).setPassphrase(passphrase).getWebRequest();
    String cloneContentLocation2 = clone(request);

    // clone2: get project/folder metadata
    request = getGetFilesRequest(cloneContentLocation2);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());

    // clone2: get git links
    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);

    // clone2: change
    request = getPutFileRequest(projectId2 + "/test.txt", "incoming change");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // 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, null,
            knownHosts2, privateKey, publicKey, passphrase, true);
    assertEquals(true, pushStatus.isOK());

    JSONObject details = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String refId1 = details.getString(ProtocolConstants.KEY_ID);
    String remoteBranchLocation = details.getString(ProtocolConstants.KEY_LOCATION);

    // clone1: fetch
    fetch(remoteBranchLocation, null, knownHosts2, privateKey, publicKey, passphrase, true);

    details = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String newRefId1 = details.getString(ProtocolConstants.KEY_ID);
    assertFalse(newRefId1.equals(refId1));

    // clone1: log master..origin/master
    // TODO replace with tests methods from GitLogTest, bug 340051
    Repository db1 = getRepositoryForContentLocation(cloneContentLocation1);
    ObjectId master = db1.resolve(Constants.MASTER);
    ObjectId originMaster = db1//from w w w .  j a v  a2s  . c o  m
            .resolve(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + Constants.MASTER);
    Git git = new Git(db1);
    Iterable<RevCommit> commits = git.log().addRange(master, originMaster).call();
    int c = 0;
    for (RevCommit commit : commits) {
        assertEquals("incoming change commit", commit.getFullMessage());
        c++;
    }
    // a single incoming commit
    assertEquals(1, c);
}

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

License:Open Source License

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

    // clone1: create
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    String projectId1 = project1.getString(ProtocolConstants.KEY_ID);
    IPath clonePath1 = new Path("file").append(project1.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    JSONObject clone1 = clone(clonePath1);
    String cloneContentLocation1 = clone1.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
    String cloneLocation1 = clone1.getString(ProtocolConstants.KEY_LOCATION);
    String branchesLocation1 = clone1.getString(GitConstants.KEY_BRANCH);

    // get project1 metadata
    WebRequest request = getGetFilesRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());
    JSONObject gitSection1 = project1.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection1);/*  www  . j  a v a 2 s .  com*/
    String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);
    String gitIndexUri1 = gitSection1.getString(GitConstants.KEY_INDEX);
    String gitHeadUri1 = gitSection1.getString(GitConstants.KEY_HEAD);

    // clone1: branch 'a'
    Repository db1 = getRepositoryForContentLocation(cloneContentLocation1);
    Git git1 = new Git(db1);
    branch(branchesLocation1, "a");

    // clone1: push all
    // TODO: replace with REST API when bug 339115 is fixed
    git1.push().setPushAll().call();

    // clone2
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    IPath clonePath2 = new Path("file").append(project2.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    clone(clonePath2);
    // XXX: checked out 'a'

    // 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.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection2);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);

    // clone1: switch to 'a'
    assertBranchExist(git1, "a");
    checkoutBranch(cloneLocation1, "a");

    // clone1: change
    request = getPutFileRequest(projectId1 + "/test.txt", "branch 'a' change");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: add
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri1);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: commit
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "incoming branch 'a' commit", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: push
    ServerStatus pushStatus = push(gitRemoteUri1, 2, 0, "a", Constants.HEAD, false);
    assertTrue(pushStatus.isOK());

    // clone1: switch to 'master'
    checkoutBranch(cloneLocation1, Constants.MASTER);

    // clone1: change
    request = getPutFileRequest(projectId1 + "/test.txt", "branch 'master' change");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: add
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri1);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: commit
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "incoming branch 'master' commit", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone1: push
    pushStatus = push(gitRemoteUri1, 2, 0, Constants.MASTER, Constants.HEAD, false);
    assertTrue(pushStatus.isOK());

    // clone2: get remote details
    // XXX: checked out 'a'
    JSONObject masterDetails = getRemoteBranch(gitRemoteUri2, 2, 1, Constants.MASTER);
    String masterOldRefId = masterDetails.getString(ProtocolConstants.KEY_ID);
    JSONObject aDetails = getRemoteBranch(gitRemoteUri2, 2, 0, "a");
    String aOldRefId = aDetails.getString(ProtocolConstants.KEY_ID);

    // clone2: fetch all: 'master' and 'a'
    JSONObject remote = getRemote(gitRemoteUri2, 1, 0, Constants.DEFAULT_REMOTE_NAME);
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);
    fetch(remoteLocation);

    // clone2: assert both remote branches have new content
    masterDetails = getRemoteBranch(gitRemoteUri2, 2, 1, Constants.MASTER);
    String newRefId = masterDetails.getString(ProtocolConstants.KEY_ID);
    assertFalse(masterOldRefId.equals(newRefId));

    aDetails = getRemoteBranch(gitRemoteUri2, 2, 0, "a");
    newRefId = aDetails.getString(ProtocolConstants.KEY_ID);
    assertFalse(aOldRefId.equals(newRefId));
}

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  ww. j  av a2s . co 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  ww  .  j  av a2s.c  o m*/
        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.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 w w  w . jav a2 s.  c o  m

    // 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.GitPullTest.java

License:Open Source License

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

    // 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 gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

    // get HEAD/*from   w  w w .j  a va2  s .  co m*/
    JSONArray commitsArray = log(gitHeadUri);
    String headSha1 = commitsArray.getJSONObject(0).getString(ProtocolConstants.KEY_NAME);

    // list remotes
    request = GitRemoteTest.getGetGitRemoteRequest(gitRemoteUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject remotes = new JSONObject(response.getText());
    JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, remotesArray.length());
    JSONObject remote = remotesArray.getJSONObject(0);
    assertNotNull(remote);
    assertEquals(Constants.DEFAULT_REMOTE_NAME, remote.getString(ProtocolConstants.KEY_NAME));
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);
    assertNotNull(remoteLocation);

    // get remote details
    JSONObject details = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER);
    String refId = details.getString(ProtocolConstants.KEY_ID);

    // pull
    pull(cloneLocation);

    // get remote details again
    String newRefId = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER).getString(ProtocolConstants.KEY_ID);
    // up to date
    assertEquals(refId, newRefId);

    // get the current branch
    request = getGetRequest(gitHeadUri);
    response = webConversation.getResponse(request);
    ServerStatus status = waitForTask(response);
    assertTrue(status.toString(), status.isOK());
    JSONObject newHead = status.getJsonData();
    String newHeadSha1 = newHead.getJSONArray(ProtocolConstants.KEY_CHILDREN).getJSONObject(0)
            .getString(ProtocolConstants.KEY_NAME);
    assertEquals(headSha1, newHeadSha1);
}