Sha256: 3abf884de954a7a6d6e14abc97f5d24b601dc377550b8605c40dac8a0898dfd8

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

class FastIgnore
  module GlobalGitignore
    class << self
      def path(root:)
        gitconfig_gitignore_path(::File.expand_path('.git/config', root)) ||
          gitconfig_gitignore_path(::File.expand_path('~/.gitconfig')) ||
          gitconfig_gitignore_path(xdg_config_path) ||
          gitconfig_gitignore_path('/etc/gitconfig') ||
          default_global_gitignore_path
      end

      private

      def gitconfig_gitignore_path(config_path)
        return unless config_path
        return unless ::File.readable?(config_path)

        ignore_path = ::FastIgnore::GitconfigParser.parse(config_path)
        return unless ignore_path

        ignore_path.strip!
        return '' if ignore_path.empty? # don't expand path in this case

        ::File.expand_path(ignore_path)
      end

      def xdg_config_path
        xdg_config_home? && ::File.expand_path('git/config', xdg_config_home)
      end

      def default_global_gitignore_path
        if xdg_config_home?
          ::File.expand_path('git/ignore', xdg_config_home)
        else
          ::File.expand_path('~/.config/git/ignore')
        end
      end

      def xdg_config_home
        ::ENV['XDG_CONFIG_HOME']
      end

      def xdg_config_home?
        xdg_config_home && (not xdg_config_home.empty?)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fast_ignore-0.16.0 lib/fast_ignore/global_gitignore.rb