_git.rb 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #
  2. # Cookbook:: workstation
  3. # Recipe:: _git
  4. #
  5. # Copyright:: 2022, The Authors, All Rights Reserved.
  6. node['my_workstation']['default_user'].each do |username, properties|
  7. user username do
  8. properties.each do |property, value|
  9. send(property, value)
  10. end
  11. manage_home true
  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 'git'
  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
  34. end