module FastIgnore::GlobalGitignore

Public Class Methods

path(root:) click to toggle source
# File lib/fast_ignore/global_gitignore.rb, line 6
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 Class Methods

default_global_gitignore_path() click to toggle source
# File lib/fast_ignore/global_gitignore.rb, line 33
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
gitconfig_gitignore_path(config_path) click to toggle source
# File lib/fast_ignore/global_gitignore.rb, line 16
def gitconfig_gitignore_path(config_path)
  return unless config_path
  return unless ::File.exist?(config_path)

  ignore_path = ::File.readlines(config_path).find { |l| l.sub!(/\A\s*excludesfile\s*=/, '') }
  return unless ignore_path

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

  ::File.expand_path(ignore_path)
end
xdg_config_home() click to toggle source
# File lib/fast_ignore/global_gitignore.rb, line 41
def xdg_config_home
  ::ENV['XDG_CONFIG_HOME']
end
xdg_config_home?() click to toggle source
# File lib/fast_ignore/global_gitignore.rb, line 45
def xdg_config_home?
  xdg_config_home && (not xdg_config_home.empty?)
end
xdg_config_path() click to toggle source
# File lib/fast_ignore/global_gitignore.rb, line 29
def xdg_config_path
  xdg_config_home? && ::File.expand_path('git/config', xdg_config_home)
end