_git.rb 965 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # Cookbook:: workstation
  3. # Recipe:: _git
  4. #
  5. # Copyright:: 2022, The Authors, All Rights Reserved.
  6. include_recipe 'git'
  7. username, properties = node['my_workstation']['default_user'].first
  8. user username do
  9. properties.each do |property, value|
  10. send(property, value)
  11. end
  12. end
  13. user_repo_directory = ::File.join(properties['home'], 'repo')
  14. directory user_repo_directory do
  15. owner username
  16. group username
  17. recursive true
  18. end
  19. include_recipe 'workstation::_ssh-ident'
  20. node['workstation']['_git'].each do |scope_git, git_options|
  21. if scope_git.match(/^file_/)
  22. gitconfig_file = $' # String after the match (ref: https://ruby-doc.org/core-2.5.1/Regexp.html#class-Regexp-label-Special+global+variables)
  23. scope_git = 'file'
  24. end
  25. git_options.each do |k, v|
  26. git_config k do
  27. value v.to_s
  28. scope scope_git
  29. user username if %w{global file}.include?(scope_git)
  30. config_file gitconfig_file if scope_git == 'file'
  31. end
  32. end
  33. end