pivotal_git_scripts 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pivotal_git_scripts (1.1.2)
4
+ pivotal_git_scripts (1.1.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -16,16 +16,18 @@ These scripts are helpers for managing developer workflow when using git repos h
16
16
 
17
17
  ## git-pair
18
18
 
19
- $ git pair js sp
19
+ Configures git authors when pair programming.
20
+
21
+ git pair sp js
20
22
  user.name=Josh Susser & Sam Pierson
21
23
  user.email=pair+jsusser+sam@pivotallabs.com
22
24
 
23
25
 
24
- Use `git pair` to set the git config user info that sets the commit user metadata. You'll need to create a `.pairs` config file to map initials to names and email ids. The example file:
26
+ Create a `.pairs` config file in project root or your home folder.
25
27
 
26
28
  # .pairs - configuration for 'git pair'
27
- # place in project or home directory
28
29
  pairs:
30
+ # <initials>: <Firstname> <Lastname>[; <email-id>]
29
31
  eh: Edward Hieatt
30
32
  js: Josh Susser; jsusser
31
33
  sf: Serguei Filimonov; serguei
@@ -34,9 +36,14 @@ Use `git pair` to set the git config user info that sets the commit user metadat
34
36
  domain: pivotallabs.com
35
37
  #global: true
36
38
 
37
- You can put the .pairs file in your project repo root directory and check it into git, or you can put it in your ~ directory so it's available to all projects on the workstation.
38
39
 
39
- By default this command affects the configuration in the current project (.git/config). Use the `--global` option or add 'global: true' to your pairs file to set the global git configuration for all projects (~/.gitconfig).
40
+ By default this affects the current project (.git/config).<br/>
41
+ Use the `--global` option or add `global: true` to your `.pairs` file to set the global git configuration for all projects (~/.gitconfig).
42
+
43
+ Options are:
44
+ -g, --global Modify global git options instead of local
45
+ -v, --version Show Version
46
+ -h, --help Show this.
40
47
 
41
48
  ## git-project
42
49
 
@@ -53,6 +60,7 @@ Authors
53
60
  Copyright (c) 2010 [Pivotal Labs](http://pivotallabs.com). This software is licensed under the MIT License.
54
61
 
55
62
  ### [Contributors](https://github.com/pivotal/git_scripts/contributors)
63
+ - git-pair original author [Bryan Helmkamp](http://brynary.com)
56
64
  - lots of pivots :)
57
65
  - [James Sanders](https://github.com/jsanders)
58
66
  - [Todd Persen](https://github.com/toddboom)
data/bin/git-pair CHANGED
@@ -1,25 +1,52 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- # Configures the git author to a list of developers when pair programming,
4
- # alphabetized on first name
5
- #
6
- # Usage: git pair ls gw (Sets the repo specific author to 'Greg Woodward & Loren Siebert')
7
- # git pair (Unsets the repo specific author so the git global config takes effect)
8
- # git pair --global ls gw (Sets the global author to 'Greg Woodward & Loren Siebert')
9
- # git pair --global (Unsets the global author)
10
- #
11
- # Orginal Author: Bryan Helmkamp (http://brynary.com)
12
-
13
- #######################################################################
14
-
15
2
  require 'yaml'
3
+ require 'optparse'
4
+
5
+ def parse_cli_options(argv)
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ # copy-paste from readme
9
+ opts.banner = <<BANNER.sub('<br/>','')
10
+ Configures git authors when pair programming.
11
+
12
+ git pair sp js
13
+ user.name=Josh Susser & Sam Pierson
14
+ user.email=pair+jsusser+sam@pivotallabs.com
15
+
16
+
17
+ Create a `.pairs` config file in project root or your home folder.
18
+
19
+ # .pairs - configuration for 'git pair'
20
+ pairs:
21
+ # <initials>: <Firstname> <Lastname>[; <email-id>]
22
+ eh: Edward Hieatt
23
+ js: Josh Susser; jsusser
24
+ sf: Serguei Filimonov; serguei
25
+ email:
26
+ prefix: pair
27
+ domain: pivotallabs.com
28
+ #global: true
29
+
30
+
31
+ By default this affects the current project (.git/config).<br/>
32
+ Use the `--global` option or add `global: true` to your `.pairs` file to set the global git configuration for all projects (~/.gitconfig).
33
+
34
+ Options are:
35
+ BANNER
36
+ opts.on("-g", "--global", "Modify global git options instead of local") { options[:global] = true }
37
+ opts.on("-v", "--version", "Show Version") do
38
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
39
+ require "pivotal_git_scripts/version"
40
+ puts PivotalGitScripts::VERSION
41
+ exit
42
+ end
43
+ opts.on("-h", "--help", "Show this.") { puts opts; exit }
44
+ end.parse!(argv)
16
45
 
17
- git_dir = `git rev-parse --git-dir`.chomp
18
- exit 1 unless File.exists?(git_dir)
19
-
20
- ## Configuration
46
+ options
47
+ end
21
48
 
22
- def get_pairs_config
49
+ def read_pairs_config
23
50
  pairs_file_path = nil
24
51
  candidate_file_path = '.pairs'
25
52
  until pairs_file_path || File.expand_path(candidate_file_path) == '/.pairs' do
@@ -29,7 +56,6 @@ def get_pairs_config
29
56
  candidate_file_path = File.join("..", candidate_file_path)
30
57
  end
31
58
  end
32
- puts pairs_file_path.inspect
33
59
 
34
60
  unless pairs_file_path
35
61
  puts <<-INSTRUCTIONS
@@ -51,74 +77,72 @@ INSTRUCTIONS
51
77
  pairs_file_path ? YAML.load_file(pairs_file_path) : {}
52
78
  end
53
79
 
54
- def get_global_config(config)
55
- if ARGV.delete("--global") || config["global"]
56
- "--global"
80
+ def read_author_info_from_config(config, initials)
81
+ initials.map do |initials|
82
+ if full_name = config['pairs'][initials.downcase]
83
+ full_name
84
+ else
85
+ puts "Couldn't find author name for initials: #{initials}. Add this person to the .pairs file in your project or home directory."
86
+ exit 1
87
+ end
57
88
  end
58
89
  end
59
90
 
60
- ## End of configuration
61
- #######################################################################
62
-
63
- config = get_pairs_config
64
- global_config_string = get_global_config(config)
65
- authors = ARGV.map do |initials|
66
- if full_name = config['pairs'][initials.downcase]
67
- full_name
91
+ def build_email(emails, config)
92
+ if config.is_a?(Hash)
93
+ "#{([config['prefix']] + emails).compact.join('+')}@#{config['domain']}"
68
94
  else
69
- puts "Couldn't find author name for initials: #{initials}. Add this person to the .pairs file in your project or home directory."
70
- exit 1
95
+ config
96
+ end
97
+ end
98
+
99
+ def set_git_config(global_config_string, options)
100
+ options.each do |key,value|
101
+ key = "user.#{key}"
102
+ value = value ? %Q{#{key} "#{value}"} : "--unset #{key}"
103
+ system(%Q{git config#{global_config_string} #{value}})
71
104
  end
72
105
  end
73
106
 
74
- if authors.any?
107
+ def report_git_settings(git_dir, key)
108
+ global = `git config --global --get-regexp '^user\.#{key}'`
109
+ local = `git config -f #{git_dir}/config --get-regexp '^user\.#{key}'`
110
+ if global.length > 0 && local.length > 0
111
+ puts "NOTE: Overriding global user.#{key} setting with local."
112
+ end
113
+ puts "global: #{global}" if global.length > 0
114
+ puts "local: #{local}" if local.length > 0
115
+ end
116
+
117
+ def extract_author_names_and_email_ids_from_config(config, initials)
118
+ authors = read_author_info_from_config(config, initials)
75
119
  authors.sort!.uniq!
76
- names, emails = authors.collect do |a|
77
- both = a.split(";").collect {|s| s.strip}
78
- both << both[0].split(' ').first.downcase if both.length == 1 # default email to first name
79
- both
120
+ authors.map do |a|
121
+ full_name, email_id = a.split(";").map(&:strip)
122
+ email_id ||= full_name.split(' ').first.downcase
123
+ [full_name, email_id]
80
124
  end.transpose
125
+ end
81
126
 
82
- case authors.size
83
- when 1
84
- authors = names.first
85
- when 2
86
- authors = names.join(" & ")
87
- else
88
- authors = names[0..-2].join(", ") + " & " + names.last
89
- end
127
+ git_dir = `git rev-parse --git-dir`.chomp
128
+ exit 1 if git_dir.empty?
90
129
 
91
- email = if config['email'].is_a?(Hash)
92
- "#{([config['email']['prefix']] + emails).compact.join('+')}@#{config['email']['domain']}"
93
- else
94
- config['email']
95
- end
130
+ options = parse_cli_options(ARGV)
131
+ initials = ARGV
132
+ config = read_pairs_config
133
+ global = " --global" if options[:global] or config["global"]
96
134
 
97
- initials = ARGV.join(' ')
135
+ if initials.any?
136
+ author_names, email_ids = extract_author_names_and_email_ids_from_config(config, initials)
137
+ authors = [author_names[0..-2].join(", "), author_names.last].reject(&:empty?).join(" & ")
138
+ email = build_email(email_ids, config["email"])
98
139
 
99
- system(%Q{git config #{global_config_string} user.name "#{authors}"})
100
- system(%Q{git config #{global_config_string} user.email "#{email}"})
101
- system(%Q{git config #{global_config_string} user.initials "#{initials}"})
140
+ set_git_config global, :name => authors, :email => email, :initials => initials.join(" ")
102
141
  else
103
- system("git config #{global_config_string} --unset user.name")
104
- system("git config #{global_config_string} --unset user.email")
105
- system("git config #{global_config_string} --unset user.initials")
106
- puts "Unset #{global_config_string} user.name and user.email"
142
+ set_git_config global, :name => nil, :email => nil, :initials => nil
143
+ puts "Unset#{global} user.name, user.email, user.initials"
107
144
  end
108
145
 
109
- global_name_setting = `git config --global --get-regexp '^user\.name'`
110
- local_name_setting = `git config -f #{git_dir}/config --get-regexp '^user\.name'`
111
- if global_name_setting.length > 0 && local_name_setting.length > 0
112
- puts "NOTE: Overriding global user.name setting with local."
113
- end
114
- puts "global: #{global_name_setting}" if global_name_setting.length > 0
115
- puts "local: #{local_name_setting}" if local_name_setting.length > 0
116
-
117
-
118
- global_email_setting = `git config --global --get-regexp '^user\.email'`
119
- local_email_setting = `git config -f #{git_dir}/config --get-regexp '^user\.email'`
120
- if global_email_setting.length > 0 && local_email_setting.length > 0
121
- puts "NOTE: Overriding global user.email setting with local."
146
+ [:name, :email, :initials].each do |key|
147
+ report_git_settings(git_dir, key)
122
148
  end
123
- puts "global: #{global_email_setting}" if global_email_setting.length > 0
124
- puts "local: #{local_email_setting}" if local_email_setting.length > 0
@@ -1,3 +1,3 @@
1
1
  module PivotalGitScripts
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -78,10 +78,20 @@ describe "CLI" do
78
78
 
79
79
  prefix = (options[:global] ? "global: " : "local: ")
80
80
  result.should include "#{prefix}user.name #{name}"
81
- #result.should include "#{prefix}user.initials #{initials}" # TODO
81
+ result.should include "#{prefix}user.initials #{initials}"
82
82
  result.should include "#{prefix}user.email #{email}"
83
83
  end
84
84
 
85
+ it "prints help" do
86
+ result = run "git-pair --help"
87
+ result.should include("Configures git authors when pair programming")
88
+ end
89
+
90
+ it "prints version" do
91
+ result = run "git pair --version"
92
+ result.should =~ /\d+\.\d+\.\d+/
93
+ end
94
+
85
95
  context "with .pairs file" do
86
96
  before do
87
97
  write ".pairs", <<-YAML.unindent
@@ -156,7 +166,7 @@ describe "CLI" do
156
166
  run "git pair ab --global"
157
167
  run "git pair bc"
158
168
  result = run "git pair"
159
- #result.should include "Unset user.name, user.email and user.initials" #TODO
169
+ result.should include "Unset user.name, user.email, user.initials"
160
170
  expect_config result, "Aa Bb", "ab", "the-pair+aa@the-host.com", :global => true
161
171
  result.should_not include("local:")
162
172
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotal_git_scripts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: