コード例 #1
0
ファイル: BlameTest.java プロジェクト: JSansalone/NetBeansIDE
  public void testBlameRename() throws Exception {
    File f = new File(workDir, "f");
    File f2 = new File(workDir, "f2");
    write(f, "aaa\nbbb\nccc\n");
    File[] files = {f, f2};
    add(files);
    GitClient client = getClient(workDir);
    String revision1 =
        client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();

    client.rename(f, f2, false, NULL_PROGRESS_MONITOR);
    write(f2, "aaa\nbbb\nddd\n");
    add(f2);
    String revision2 =
        client.commit(files, "rename", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
    GitBlameResult result = client.blame(f, revision2, NULL_PROGRESS_MONITOR);
    assertNull(result);
    result = client.blame(f, revision1, NULL_PROGRESS_MONITOR);
    assertEquals(f, result.getBlamedFile());
    assertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
    assertLineDetails(f, 1, revision1, USER1, USER1, result.getLineDetails(1));
    assertLineDetails(f, 2, revision1, USER1, USER1, result.getLineDetails(2));
    result = client.blame(f2, null, NULL_PROGRESS_MONITOR);
    assertEquals(f2, result.getBlamedFile());
    assertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
    assertLineDetails(f, 1, revision1, USER1, USER1, result.getLineDetails(1));
    assertLineDetails(f2, 2, revision2, USER1, USER1, result.getLineDetails(2));
  }
コード例 #2
0
ファイル: BlameTest.java プロジェクト: JSansalone/NetBeansIDE
  public void testBlameMixedLineEndings() throws Exception {
    File f = new File(workDir, "f");
    String content = "";
    for (int i = 0; i < 10000; ++i) {
      content += i + "\r\n";
    }
    write(f, content);

    // lets turn autocrlf on
    StoredConfig cfg = repository.getConfig();
    cfg.setString(
        ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true");
    cfg.save();

    File[] files = new File[] {f};
    GitClient client = getClient(workDir);
    client.add(files, NULL_PROGRESS_MONITOR);
    GitRevisionInfo info = client.commit(files, "commit", null, null, NULL_PROGRESS_MONITOR);

    content = content.replaceFirst("0", "01");
    write(f, content);

    // it should be up to date again
    // JGit does not work either:
    org.eclipse.jgit.api.BlameCommand cmd = new Git(repository).blame();
    cmd.setFilePath("f");
    BlameResult blameResult = cmd.call();
    assertNull(blameResult.getSourceCommit(1));

    // stupid workaround for JGit
    cmd = new Git(repository).blame();
    cmd.setFilePath("f");
    cmd.setTextComparator(RawTextComparator.WS_IGNORE_TRAILING);
    blameResult = cmd.call();
    assertEquals(info.getRevision(), blameResult.getSourceCommit(1).getName());

    GitBlameResult res = client.blame(f, null, NULL_PROGRESS_MONITOR);
    assertNull(res.getLineDetails(0));
    assertLineDetails(
        f, 1, info.getRevision(), info.getAuthor(), info.getCommitter(), res.getLineDetails(1));

    // without autocrlf it should all be modified
    cfg.setString(
        ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "false");
    cfg.save();
    res = client.blame(f, null, NULL_PROGRESS_MONITOR);
    assertNull(res.getLineDetails(1));
  }
コード例 #3
0
ファイル: BlameTest.java プロジェクト: JSansalone/NetBeansIDE
  public void testBlameAddLine() throws Exception {
    File f = new File(workDir, "f");
    write(f, "aaa\nccc\n");
    File[] files = {f};
    add(files);
    GitClient client = getClient(workDir);
    String revision1 =
        client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();

    write(f, "aaa\nbbb\nccc\n");
    add(f);
    String revision2 =
        client.commit(files, "add line", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
    GitBlameResult result = client.blame(f, revision2, NULL_PROGRESS_MONITOR);
    assertEquals(f, result.getBlamedFile());
    assertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
    assertLineDetails(f, 1, revision2, USER1, USER1, result.getLineDetails(1));
    assertLineDetails(f, 1, revision1, USER1, USER1, result.getLineDetails(2));
  }
コード例 #4
0
ファイル: BlameTest.java プロジェクト: JSansalone/NetBeansIDE
  public void testBlameSimple() throws Exception {
    File f = new File(workDir, "f");
    write(f, "aaa\nbbb\nccc\n");
    File[] files = {f};
    add(files);
    GitClient client = getClient(workDir);
    String revision1 =
        client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
    GitBlameResult result = client.blame(f, revision1, NULL_PROGRESS_MONITOR);
    assertEquals(f, result.getBlamedFile());
    assertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
    // the same authors should be the same one instance
    assertSame(result.getLineDetails(0).getAuthor(), result.getLineDetails(1).getAuthor());
    assertSame(result.getLineDetails(1).getAuthor(), result.getLineDetails(2).getAuthor());
    assertSame(result.getLineDetails(0).getAuthor(), result.getLineDetails(0).getCommitter());
    assertSame(result.getLineDetails(0).getCommitter(), result.getLineDetails(1).getCommitter());
    assertSame(result.getLineDetails(1).getCommitter(), result.getLineDetails(2).getCommitter());
    // the same commits should be the same one instance
    assertSame(
        result.getLineDetails(0).getRevisionInfo(), result.getLineDetails(1).getRevisionInfo());
    assertSame(
        result.getLineDetails(1).getRevisionInfo(), result.getLineDetails(2).getRevisionInfo());

    write(f, "aaa\nzzz\nccc\n");
    add(files);
    String revision2 =
        client.commit(files, "change 1", USER2, USER1, NULL_PROGRESS_MONITOR).getRevision();
    result = client.blame(f, revision2, NULL_PROGRESS_MONITOR);
    assertEquals(f, result.getBlamedFile());
    assertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
    assertLineDetails(f, 1, revision2, USER2, USER1, result.getLineDetails(1));
    assertLineDetails(f, 2, revision1, USER1, USER1, result.getLineDetails(2));

    write(f, "aaa\nzzz\nyyy\n");
    add(files);
    String revision3 =
        client.commit(files, "change 2", USER1, USER2, NULL_PROGRESS_MONITOR).getRevision();
    result = client.blame(f, revision3, NULL_PROGRESS_MONITOR);
    assertEquals(f, result.getBlamedFile());
    assertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
    assertLineDetails(f, 1, revision2, USER2, USER1, result.getLineDetails(1));
    assertLineDetails(f, 2, revision3, USER1, USER2, result.getLineDetails(2));
  }