package 'git'

if node[:platform] == 'darwin'
  package 'gh'
else
  github_release 'gh' do
    v = "1.2.1"
    name = "gh_#{v}_#{node[:kernel][:name].downcase}_amd64"

    repo 'cli/cli'
    version "v#{v}"
    archive "#{name}.tar.gz"
    checksum "gh_#{v}_checksums.txt"
    bin "#{name}/bin/gh"
  end
end

if node[:platform] == 'darwin'
  prefix = brew_prefix
  link "#{prefix}/bin/diff-highlight" do
    to "#{prefix}/share/git-core/contrib/diff-highlight/diff-highlight"
  end
end

if codespaces?
  dir = '/usr/share/doc/git/contrib/diff-highlight'

  execute "build diff-highlight" do
    command "make"
    cwd dir
  end
  execute "chmod +x #{dir}/diff-highlight"
  link "#{default_prefix}/bin/diff-highlight" do
    to "#{dir}/diff-highlight"
  end
end

dotfile '.gitconfig'
dotfile '.gitignore_global'
dotfile '.git_template'
dotfile_template '.gitconfig.local' do
  source File.expand_path('../templates/gitconfig_local.erb', __FILE__)
end
