public static void writeGitHeader(@NotNull Writer writer,
                                    @Nullable Path basePath,
                                    @NotNull FilePatch filePatch, @NotNull @NonNls String lineSeparator)
    throws IOException {
    writer.write(String.format(GIT_DIFF_HEADER,
                               UnifiedDiffWriter.A_PREFIX + filePatch.getBeforeName(),
                               UnifiedDiffWriter.B_PREFIX + filePatch.getAfterName()));
    writer.write(lineSeparator);
    if (filePatch.isDeletedFile()) {
      writer.write(getFileModeHeader(FileStatus.DELETED, REGULAR_FILE_MODE));
      writer.write(lineSeparator);
    }
    else if (filePatch.isNewFile()) {
      Path afterFile = basePath == null ? Paths.get(filePatch.getAfterName()) : basePath.resolve(filePatch.getAfterName());
      writer.write(getFileModeHeader(FileStatus.ADDED, !SystemInfo.isWindows && afterFile.toFile().canExecute()
                                                       ? EXECUTABLE_FILE_MODE : REGULAR_FILE_MODE));
      writer.write(lineSeparator);
    }
    else if (!StringUtil.equals(filePatch.getBeforeName(), filePatch.getAfterName())) {
      //movement
      writer.write(String.format(FILE_RENAME_FROM_HEADER, filePatch.getBeforeName()));
      writer.write(lineSeparator);
      writer.write(String.format(FILE_RENAME_TO_HEADER, filePatch.getAfterName()));
      writer.write(lineSeparator);
    }
  }
public static void writeGitHeader(@NotNull Writer writer,
                                    @Nullable Path basePath,
                                    @NotNull FilePatch filePatch, @NotNull @NonNls String lineSeparator)