Skip to content

Instantly share code, notes, and snippets.

@deobald
Created February 7, 2014 02:46
Show Gist options
  • Save deobald/8856646 to your computer and use it in GitHub Desktop.
Save deobald/8856646 to your computer and use it in GitHub Desktop.
pair git commit script
#!/usr/bin/env ruby
# Configures the git author to a list of developers when pair programming
#
# Usage: pair lm bh (Sets the author to 'Luke Melia and Bryan Helmkamp')
# pair (Unsets the author so the git global config takes effect)
#
# Author: Bryan Helmkamp (http://brynary.com)
# http://www.brynary.com/2008/9/1/setting-the-git-commit-author-to-pair-programmers-names
#######################################################################
## Configuration
AUTHORS = {
"ab" => "Alex Baranosky",
"ak" => "Aninda Kundu",
"dc" => "David Chelimsky",
"kt" => "Kasim Tuman",
"mn" => "Michael Nygard",
"nid" => "Nivedita Priyadarshini",
"ph7" => "Philippe Hanrigou",
"pr" => "Punit Rathore",
"rn" => "Ryan Neufeld",
"sd" => "Steven Deobald",
"ss" => "Steve Sloan",
"tb" => "Tim Brooks"
}
## End of configuration
#######################################################################
def to_sentence(things)
if things.size < 3
things.join(" and ")
else
"#{things.first}, #{to_sentence(things.drop(1))}"
end
end
def git_config_set(name, value)
`git config "#{name}" "#{value}"`
puts "#{name} = \"#{value}\""
end
def git_config_unset(name)
`git config --unset "#{name}"`
puts "Unset #{name}"
end
unless File.exists?(".git")
abort "This doesn't look like a git repository."
end
initials = ARGV.map(&:downcase).map(&:strip).reject(&:empty?).uniq
authors = initials.map do |initial|
AUTHORS[initial] or abort("Couldn't find author name for initials: #{initial}")
end
if authors.any?
git_config_set('user.name', to_sentence(authors))
git_config_set('user.initials', initials.join('/'))
else
git_config_unset('user.name')
git_config_unset('user.initials')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment