Storvild's Blog
Заметки программиста

GitLab: Отображение русских символов в файлах с кодировкой Win1251

Чтобы в GitLab корректно отображались русские символы при работе с файлами в кодировке Win1251, необходимо изменить два файла:
/opt/gitlab/embedded/service/gitaly-ruby/lib/gitlab/encoding_helper.rb
и
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/encoding_helper.rb

Для доступа к редактированию под root выполняем:

sudo su

Вместо:

      if detect && detect[:encoding] && detect[:confidence] > ENCODING_CONFIDENCE_THRESHOLD
        # force detected encoding if we have sufficient confidence.
        message.force_encoding(detect[:encoding])
      end

Пишем:

      # force detected encoding if we have sufficient confidence.
      if detect && detect[:encoding]
        message.force_encoding("windows-1251")
        message.encode("utf-8", "windows-1251", undef: :replace, replace: "", invalid: :replace)
      end

Далее переконфигурируем и перезапускаем gitlab:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

Опробовано на версии GitLab 14.0.5

На основе статьи: https://nlinberg.com/gitlab-encoding-windows-1251/ (GitLab 9.0.5)


Теги:
Программирование Git GitLab
Настройки