forked from vmware-archive/git_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-pair
More file actions
executable file
·94 lines (83 loc) · 2.5 KB
/
Copy pathgit-pair
File metadata and controls
executable file
·94 lines (83 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env ruby
# Configures the git author to a list of developers when pair programming,
# alphabetized on first name
#
# Usage: git pair ls gw (Sets the author to 'Greg Woodward & Loren Siebert')
# git pair (Unsets the author so the git global config takes effect)
#
# Orginal Author: Bryan Helmkamp (http://brynary.com)
#######################################################################
require 'yaml'
unless File.exists?(".git")
puts "This doesn't look like a git repository."
exit 1
end
## Configuration
def get_pairs_config
pairs_file_path = nil
until pairs_file_path || Dir.pwd == File.expand_path('/') do
if File.exists?(".pairs")
pairs_file_path = File.expand_path(".pairs")
else
Dir.chdir ".."
end
end
unless pairs_file_path
puts <<-INSTRUCTIONS
Could not find a .pairs file. Create a YAML file in your project or home directory.
Format: <initials>: <name>[; <email>]
Example:
# .pairs - configuration for 'git pair'
# place in project or home directory
pairs:
eh: Edward Hieatt
js: Josh Susser; jsusser
sf: Serguei Filimonov; serguei
email:
prefix: pair
domain: pivotallabs.com
INSTRUCTIONS
exit(1)
end
pairs_file_path ? YAML.load_file(".pairs") : {}
end
## End of configuration
#######################################################################
config = get_pairs_config
authors = ARGV.map do |initials|
if full_name = config['pairs'][initials.downcase]
full_name
else
puts "Couldn't find author name for initials: #{initials}. Add this person to the .pairs file in your project or home directory."
exit 1
end
end
if authors.any?
authors.sort!.uniq!
names, emails = authors.collect do |a|
both = a.split(";").collect {|s| s.strip}
both << both[0].split(' ').first.downcase if both.length == 1 # default email to first name
both
end.transpose
case authors.size
when 1
authors = names.first
when 2
authors = names.join(" & ")
else
authors = names[0..-2].join(", ") + " & " + names.last
end
email =
if email_prefix = config['email']['prefix']
"#{([config['email']['prefix']] + emails).join('+')}@#{config['email']['domain']}"
else
config['email']
end
system("git", "config", "--global", "user.name", "#{authors}")
system("git", "config", "--global", "user.email", "#{email}")
else
`git config --global --unset user.name`
`git config --global --unset user.email`
puts "Unset user.name and user.email"
end
puts `git config --global -l | grep user | tail -2`