Пример #1
0
  @Test
  public void testAutoCRLFInput() throws Exception {
    try (Git git = new Git(db)) {
      FileBasedConfig config = db.getConfig();

      // Make sure core.autocrlf is false before adding
      config.setEnum(
          ConfigConstants.CONFIG_CORE_SECTION,
          null,
          ConfigConstants.CONFIG_KEY_AUTOCRLF,
          AutoCRLF.FALSE);
      config.save();

      // File is already in repository with CRLF
      writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n");
      git.add().addFilepattern("crlf.txt").call();
      git.commit().setMessage("Add crlf.txt").call();

      // Now set core.autocrlf to input
      config.setEnum(
          ConfigConstants.CONFIG_CORE_SECTION,
          null,
          ConfigConstants.CONFIG_KEY_AUTOCRLF,
          AutoCRLF.INPUT);
      config.save();

      FileTreeIterator iterator = new FileTreeIterator(db);
      IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
      diff.diff();

      assertTrue(
          "Expected no modified files, but there were: " + diff.getModified(),
          diff.getModified().isEmpty());
    }
  }