Ejemplo n.º 1
0
  // modified + checkout = clean
  @Test
  @Ignore("not supported yet")
  public void testCheckoutDotPath() 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);

    // 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 testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "change");

    JSONObject folder1 = getChild(project, "folder");
    JSONObject folderTxt = getChild(folder1, "folder.txt");
    modifyFile(folderTxt, "change");

    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String gitCloneUri = GitStatusTest.getCloneUri(gitStatusUri);

    request = getCheckoutRequest(gitCloneUri, new String[] {"."});
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    assertStatus(StatusResult.CLEAN, gitStatusUri);
  }
Ejemplo n.º 2
0
  // modified + checkout = clean
  @Test
  public void testCheckoutInFolder() 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);

    // 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 testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "change");

    JSONObject folder1 = getChild(project, "folder");
    JSONObject folderTxt = getChild(folder1, "folder.txt");
    modifyFile(folderTxt, "change");

    JSONObject gitSection = folder1.getJSONObject(GitConstants.KEY_GIT);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    // we should get a proper clone URI here: /git/clone/file/{projectId}/
    String gitCloneUri = GitStatusTest.getCloneUri(gitStatusUri);

    request = getCheckoutRequest(gitCloneUri, new String[] {"folder/folder.txt"});
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // 'test.txt' is still modified
    assertStatus(new StatusResult().setModifiedNames("test.txt"), gitStatusUri);
  }
Ejemplo n.º 3
0
  @Test
  public void testCheckoutAfterResetByPath() 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());

      JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
      String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
      String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
      String gitCloneUri = GitStatusTest.getCloneUri(gitStatusUri);

      JSONObject testTxt = getChild(folder, "test.txt");
      modifyFile(testTxt, "change");

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

      addFile(testTxt);

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

      // unstage
      request =
          GitResetTest.getPostGitIndexRequest(
              gitIndexUri, new String[] {"test.txt"}, null, (String) null);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

      // check status again
      assertStatus(new StatusResult().setModified(1), gitStatusUri);

      // checkout
      request = getCheckoutRequest(gitCloneUri, new String[] {"test.txt"});
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

      // check status one more time
      assertStatus(StatusResult.CLEAN, gitStatusUri);
    }
  }
Ejemplo n.º 4
0
  @Test
  public void testCheckoutPathInUri() 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);

    // 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 testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "change");

    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String gitCloneUri = GitStatusTest.getCloneUri(gitStatusUri);

    // TODO: don't create URIs out of thin air
    request = getCheckoutRequest(gitCloneUri + "test.txt", new String[] {});
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());
  }
Ejemplo n.º 5
0
  @Test
  public void testCheckoutUntrackedFile() 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);

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

    String fileName = "new.txt";
    request =
        getPostFilesRequest(
            project.getString(ProtocolConstants.KEY_LOCATION),
            getNewFileJSON(fileName).toString(),
            fileName);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String gitCloneUri = GitStatusTest.getCloneUri(gitStatusUri);

    // checkout the new file
    request = getCheckoutRequest(gitCloneUri, new String[] {fileName});
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // nothing has changed, checkout doesn't touch untracked files
    assertStatus(new StatusResult().setUntrackedNames(fileName), gitStatusUri);

    // discard the new file
    request = getCheckoutRequest(gitCloneUri, new String[] {fileName}, true);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    assertStatus(StatusResult.CLEAN, gitStatusUri);
  }
Ejemplo n.º 6
0
  @Test
  public void testDiffWithCommonAncestor() throws Exception {
    // clone: create
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    String projectId = project.getString(ProtocolConstants.KEY_ID);
    IPath clonePath =
        new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    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.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);

    String a = "a";
    branch(branchesLocation, a);

    // checkout 'a'
    checkoutBranch(cloneLocation, a);

    // modify while on 'a'
    request = getPutFileRequest(projectId + "/test.txt", "change in a");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);
    String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
    String gitDiffUri = gitSection.getString(GitConstants.KEY_DIFF);

    // "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
    request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject statusResponse = new JSONObject(response.getText());
    GitStatusTest.assertStatusClean(statusResponse);

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

    // modify the same file on master
    request = getPutFileRequest(projectId + "/test.txt", "change in master");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);
    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
    request = GitStatusTest.getGetGitStatusRequest(gitStatusUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    statusResponse = new JSONObject(response.getText());
    GitStatusTest.assertStatusClean(statusResponse);

    // TODO: replace with REST API for git log when ready, see bug 339104
    // TODO: don't create URIs out of thin air
    String enc = URLEncoder.encode(Constants.MASTER + ".." + a, "UTF-8");
    String location = gitDiffUri.replaceAll(GitConstants.KEY_DIFF_DEFAULT, enc);
    location += "test.txt";

    request = getGetFilesRequest(location + "?parts=uris,diff");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    String[] parts = parseMultiPartResponse(response);

    assertDiffUris(
        location,
        new String[] {"change in master", "change in a", "test"},
        new JSONObject(parts[0]));
  }
Ejemplo n.º 7
0
  @Test
  public void testCheckoutFileOutsideCurrentFolder() throws Exception {
    // see bug 347847
    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());

      JSONObject testTxt = getChild(folder, "test.txt");
      modifyFile(testTxt, "change in file.txt");

      JSONObject folder1 = getChild(folder, "folder");
      JSONObject folderTxt = getChild(folder1, "folder.txt");
      modifyFile(folderTxt, "change folder/folder.txt");

      // check status
      JSONObject folder1GitSection = folder1.getJSONObject(GitConstants.KEY_GIT);
      String folder1GitStatusUri = folder1GitSection.getString(GitConstants.KEY_STATUS);
      String folder1GitCloneUri = GitStatusTest.getCloneUri(folder1GitStatusUri);

      request = GitStatusTest.getGetGitStatusRequest(folder1GitStatusUri);
      assertStatus(
          new StatusResult()
              .setModifiedNames("folder/folder.txt", "test.txt")
              .setModifiedPaths("folder.txt", "../test.txt"),
          folder1GitStatusUri);

      // use KEY_NAME not KEY_PATH
      // request = getCheckoutRequest(gitCloneUri, new String[]
      // {testTxt.getString(ProtocolConstants.KEY_PATH)});
      request =
          getCheckoutRequest(
              folder1GitCloneUri, new String[] {testTxt.getString(ProtocolConstants.KEY_NAME)});
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

      // 'folder/folder.txt' is still modified
      assertStatus(new StatusResult().setModifiedNames("folder/folder.txt"), folder1GitStatusUri);
    }
  }