Skip to content

Instantly share code, notes, and snippets.

@Marak
Forked from gerhard/gist:372205
Created January 10, 2011 03:12
Show Gist options
  • Save Marak/772298 to your computer and use it in GitHub Desktop.
Save Marak/772298 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Configures the git author to a list of developers when pair programming
#
# Usage: pair cr pf (Sets the author to 'Charlie Robbins, and Paolo Fragomeni')
# pair (Unsets the author so the git global config takes effect)
#
# Author: Bryan Helmkamp (http://brynary.com)
#######################################################################
## Configuration
PAIR_EMAIL = "charlie.robbins@gmail.com"
AUTHORS = {
"cr" => "Charlie Robbins",
"pf" => "Paolo Fragomeni",
"ms" => "Marak Squires"
}
## End of configuration
#######################################################################
unless File.exists?(".git")
puts "This doesn't look like a git repository."
exit 1
end
authors = ARGV.map do |initials|
if AUTHORS[initials.downcase]
AUTHORS[initials.downcase]
else
puts "Couldn't find author name for initials: #{initials}"
exit 1
end
end
if authors.any?
if authors.size == 1
authors = authors.first
elsif authors.size == 2
authors = authors.join(" and ")
else
authors = authors[0..-2].join(", ") + " and " + authors.last
end
`git config user.name '#{authors}'`
`git config user.email '#{PAIR_EMAIL}'`
puts "user.name = #{authors}"
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