-
-
Save leobessa/363341 to your computer and use it in GitHub Desktop.
pair authoring script for git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "yaml" | |
info = File.open( "#{ENV["HOME"]}/.git_authoring.yml" ) { |yf| YAML::load( yf ) } | |
PAIR_EMAIL = info['email'] | |
AUTHORS = info['authors'] | |
unless File.exists?(".git") | |
puts "This doesn't look like a git repository." | |
exit 1 | |
end | |
if ARGV.all?{ |arg| AUTHORS.has_key?(arg) } | |
authors = ARGV.map{ |arg| AUTHORS[arg] } | |
else | |
puts "Couldn't find author name for initials: #{initials}" | |
exit 1 | |
end | |
if authors.any? | |
if authors.size == 1 | |
user_name = authors.first | |
else | |
user_name = authors[0..-2].join(", ") + " e " + authors.last | |
end | |
`git config user.name '#{user_name}'` | |
`git config user.email '#{PAIR_EMAIL}'` | |
puts "user.name = #{user_name}" | |
puts "user.email = #{PAIR_EMAIL}" | |
else | |
`git config --unset user.name` | |
`git config --unset user.email` | |
puts "Unset user.name and user.email" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment