Skip to content

Instantly share code, notes, and snippets.

@leobessa
Created April 12, 2010 07:00
Show Gist options
  • Save leobessa/363341 to your computer and use it in GitHub Desktop.
Save leobessa/363341 to your computer and use it in GitHub Desktop.
pair authoring script for git
#!/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