mynewsdesk-git-pair 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ Autotest.add_hook :initialize do |autotest|
2
+ [/\.git/, /pkg\//, /\.gemspec$/, /\.log$/].each do |regexp|
3
+ autotest.add_exception regexp
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ pkg
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create ruby-1.8.7-p302@git-pair
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in git-pair.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mynewsdesk-git-pair (0.2.3)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ builder (3.0.0)
10
+ cucumber (1.0.2)
11
+ builder (>= 2.1.2)
12
+ diff-lcs (>= 1.1.2)
13
+ gherkin (~> 2.4.5)
14
+ json (>= 1.4.6)
15
+ term-ansicolor (>= 1.0.5)
16
+ diff-lcs (1.1.2)
17
+ gherkin (2.4.14)
18
+ json (>= 1.4.6)
19
+ json (1.5.3)
20
+ rspec (2.6.0)
21
+ rspec-core (~> 2.6.0)
22
+ rspec-expectations (~> 2.6.0)
23
+ rspec-mocks (~> 2.6.0)
24
+ rspec-core (2.6.4)
25
+ rspec-expectations (2.6.0)
26
+ diff-lcs (~> 1.1.2)
27
+ rspec-mocks (2.6.0)
28
+ term-ansicolor (1.0.6)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ cucumber (~> 1.0)
35
+ mynewsdesk-git-pair!
36
+ rspec (~> 2.6.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Chris Kampmeier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # git-pair
2
+
3
+ A git porcelain for changing `user.name` and `user.email` so you can commit as
4
+ more than one author.
5
+
6
+ ## Usage
7
+
8
+ Install the gem:
9
+
10
+ gem install edgecase-git-pair
11
+
12
+ And here's how to use it!
13
+
14
+ $ git pair
15
+
16
+ General Syntax:
17
+ git pair [reset | authors | options]
18
+
19
+ Options:
20
+ -a, --add AUTHOR Add an author. Format: "Author Name <author@example.com>"
21
+ -r, --remove NAME Remove an author. Use the full name.
22
+ -d, --reset Reset current author to default (global) config
23
+
24
+ Switching authors:
25
+ git pair aa [bb] Where AA and BB are any abbreviation of an
26
+ author's name. You can specify one or more authors.
27
+
28
+ Current config:
29
+ Author list: Adam McCrea
30
+ Jon Distad
31
+
32
+ Current author: Jon Distad + Adam McCrea
33
+ Current email: devs+jd+am@edgecase.com
34
+
35
+ ## How does it work?
36
+
37
+ The list of authors is maintained in the global git configuration file.
38
+ The current author is set in the git configuration local to the project.
39
+ The email address for a pair is generated using the default email address
40
+ from the global configuration along with the developer abbreviations.
41
+
42
+ ## About this version
43
+
44
+ This was forked from http://github.com/chrisk/git-pair. Many thanks to
45
+ Chris Kampmeier for the original version. Our version added the --reset
46
+ option, modified how email addresses are handled, and refactored much of
47
+ the code.
48
+
49
+ ## License
50
+
51
+ Copyright (c) 2009 Chris Kampmeier. See `LICENSE` for details.
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ begin
5
+ require 'cucumber/rake/task'
6
+ Cucumber::Rake::Task.new(:features)
7
+
8
+ task :features => :check_dependencies
9
+ rescue LoadError
10
+ task :features do
11
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
12
+ end
13
+ end
14
+
15
+ task :default => :features
16
+
17
+ # Don't print commands when shelling out (for example, running Cucumber)
18
+ RakeFileUtils.verbose(false)
19
+
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "edgecase-git-pair"
8
+ gem.summary = "Configure git to commit as more than one author"
9
+ gem.description = "A git porcelain for pair programming. Changes " +
10
+ "git-config's user.name and user.email settings so you " +
11
+ "can commit as more than one author."
12
+ gem.email = "adam@edgecase.com"
13
+ gem.homepage = "http://github.com/edgecase/git-pair"
14
+ gem.authors = ["Chris Kampmeier", "Adam McCrea", "Jon Distad"]
15
+ gem.add_development_dependency "cucumber", ">= 0"
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ begin
23
+ require 'cucumber/rake/task'
24
+ Cucumber::Rake::Task.new(:features)
25
+
26
+ task :features => :check_dependencies
27
+ rescue LoadError
28
+ task :features do
29
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
30
+ end
31
+ end
32
+
33
+ task :default => :features
34
+
35
+ # Don't print commands when shelling out (for example, running Cucumber)
36
+ RakeFileUtils.verbose(false)
37
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.2
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
+
5
+ require 'git-pair'
6
+
7
+ GitPair::Command.run!(ARGV)
8
+
@@ -0,0 +1,3 @@
1
+ default: --format progress --color features
2
+ autotest: --format pretty
3
+ autotest-all: --profile default
@@ -0,0 +1,27 @@
1
+ Feature: Adding an author
2
+ In order to commit as a pair
3
+ A user should be able to
4
+ add a name and email to the list of authors
5
+
6
+ Scenario: adding a name and email
7
+ When I add the author "Linus Torvalds <linus@example.org>"
8
+ Then `git pair` should display "Linus Torvalds" in its author list
9
+
10
+ Scenario: adding the same name and email twice
11
+ When I add the author "Linus Torvalds <linus@example.org>"
12
+ And I add the author "Linus Torvalds <linus@example.org>"
13
+ Then `git pair` should display "Linus Torvalds" in its author list only once
14
+ And the gitconfig should include "Linus Torvalds" in its author list only once
15
+
16
+ Scenario: adding the same name twice with different emails
17
+ When I add the author "Linus Torvalds <linus@example.org>"
18
+ And I add the author "Linus Torvalds <linus@example.com>"
19
+ Then `git pair` should display "Linus Torvalds" in its author list only once
20
+ And the gitconfig should include "Linus Torvalds" in its author list only once
21
+ And the gitconfig should include "linus@example.org" as the email of "Linus Torvalds"
22
+
23
+ Scenario: adding a malformed author string
24
+ When I add the author " "
25
+ And I add the author "Bob Dole"
26
+ And I add the author "Jimmy <asdf"
27
+ Then the config file should have no authors
@@ -0,0 +1,39 @@
1
+ Feature: Configuring address style
2
+ In order to control the address of the committing email
3
+ A user should be able to
4
+ change the address style settings
5
+
6
+ Scenario: Pairing with two authors
7
+ Given I have added the author "Linus Torvalds <linus@example.org>"
8
+ And I have added the author "Junio C Hamano <junio@example.org>"
9
+ And my global Git configuration is setup with email "devs@example.com"
10
+ When I switch to the pair "LT JCH"
11
+ Then `git pair` should display "Junio C Hamano + Linus Torvalds" for the current author
12
+ And `git pair` should display "devs+jch+lt@example.com" for the current email
13
+
14
+ Scenario: Pairing with email pattern configured to use names
15
+ Given I have added the author "Linus Torvalds <linus@example.org>"
16
+ And I have added the author "Junio C Hamano <junio@example.org>"
17
+ And my global Git configuration is setup with email "devs@example.com"
18
+ And I add the email configuration pattern "foo+%name+%name@test.com"
19
+ When I switch to the pair "LT JCH"
20
+ Then `git pair` should display "Junio C Hamano + Linus Torvalds" for the current author
21
+ And `git pair` should display "foo+junio+linus@test.com" for the current email
22
+
23
+ Scenario: Pairing with email pattern set to use global domain
24
+ Given I have added the author "Linus Torvalds <linus@example.org>"
25
+ And I have added the author "Junio C Hamano <junio@example.org>"
26
+ And my global Git configuration is setup with email "devs@test.com"
27
+ And I add the email configuration pattern "devs+%abbr+%abbr@%domain"
28
+ When I switch to the pair "LT JCH"
29
+ Then `git pair` should display "Junio C Hamano + Linus Torvalds" for the current author
30
+ And `git pair` should display "devs+jch+lt@test.com" for the current email
31
+
32
+ Scenario: Pairing with email pattern set to use abbreviations
33
+ Given I have added the author "Linus Torvalds <linus@example.org>"
34
+ And I have added the author "Junio C Hamano <junio@example.org>"
35
+ And my global Git configuration is setup with email "devs@example.com"
36
+ And I add the email configuration pattern "developers+%abbr+%abbr@test.com"
37
+ When I switch to the pair "LT JCH"
38
+ Then `git pair` should display "Junio C Hamano + Linus Torvalds" for the current author
39
+ And `git pair` should display "developers+jch+lt@test.com" for the current email
@@ -0,0 +1,19 @@
1
+ Feature: Adding an author
2
+ In order remove old pairing partners
3
+ A user should be able to
4
+ remove a name from the list of authors
5
+
6
+ Scenario: removing a name
7
+ When I add the author "Linus Torvalds <linus@example.org>"
8
+ And I add the author "Junio C Hamano <junio@example.org>"
9
+ And I remove the name "Junio C Hamano"
10
+ Then `git pair` should display the following author list:
11
+ | name |
12
+ | Linus Torvalds |
13
+
14
+ Scenario: removing all names
15
+ When I add the author "Linus Torvalds <linus@example.org>"
16
+ And I add the author "Junio C Hamano <junio@example.org>"
17
+ And I remove the name "Linus Torvalds"
18
+ And I remove the name "Junio C Hamano"
19
+ Then `git pair` should display an empty author list
@@ -0,0 +1,11 @@
1
+ Feature: Resetting the current authors
2
+ In order to revert to original settings
3
+ A user should be able to
4
+ reset the current pair
5
+
6
+ Scenario: resetting the current authors
7
+ Given I have added the author "Linus Torvalds <linus@example.org>"
8
+ And my global Git configuration is setup with user "Global User"
9
+ And I switch to the pair "LT"
10
+ When I reset the current authors
11
+ Then `git pair` should display "Global User" for the current author
@@ -0,0 +1,106 @@
1
+ Given /^I have added the author "([^\"]*)"$/ do |name_and_email|
2
+ When %(I add the author "#{name_and_email}")
3
+ end
4
+
5
+ Given /^my global Git configuration is setup with user "([^\"]*)"$/ do |name|
6
+ git_config "--global user.name \"#{name}\""
7
+ end
8
+
9
+ Given /^my global Git configuration is setup with email "([^\"]*)"$/ do |email|
10
+ git_config "--global user.email \"#{email}\""
11
+ end
12
+
13
+ When /^I add the author "([^\"]*)"$/ do |name_and_email|
14
+ git_pair %(--add "#{name_and_email}")
15
+ end
16
+
17
+ When /^I remove the name "([^\"]*)"$/ do |name|
18
+ git_pair %(--remove "#{name}")
19
+ end
20
+
21
+ When /^I (?:try to )?switch to the pair "([^\"]*)"$/ do |abbreviations|
22
+ @output = git_pair abbreviations
23
+ end
24
+
25
+ When /^I reset the current authors$/ do
26
+ git_pair '--reset'
27
+ end
28
+
29
+ Then /^`git pair` should display "([^\"]*)" in its author list$/ do |name|
30
+ output = git_pair
31
+ authors = authors_list_from_output(output)
32
+ assert authors.include?(name)
33
+ end
34
+
35
+ Then /^`git pair` should display "([^\"]*)" in its author list only once$/ do |name|
36
+ output = git_pair
37
+ authors = authors_list_from_output(output)
38
+ assert_equal 1, authors.select { |author| author == name}.size
39
+ end
40
+
41
+ Then /^`git pair` should display no authors$/ do
42
+ output = git_pair
43
+ authors = authors_list_from_output(output)
44
+ authors.size.should be_zero
45
+ end
46
+
47
+
48
+ Then /^`git pair` should display "([^\"]*)" for the current author$/ do |names|
49
+ output = git_pair
50
+ assert_equal names, current_author_from_output(output)
51
+ end
52
+
53
+ Then /^`git pair` should display "([^\"]*)" for the current email$/ do |email|
54
+ output = git_pair
55
+ assert_equal email, current_email_from_output(output)
56
+ end
57
+
58
+ Then /^the gitconfig should include "([^\"]*)" in its author list only once$/ do |name|
59
+ output = git_config
60
+ authors = output.split("\n").map { |line| line =~ /^git-pair\.authors=(.*) <[^>]+>$/; $1 }.compact
61
+ assert_equal 1, authors.select { |author| author == name}.size
62
+ end
63
+
64
+ Then /^the gitconfig should include "([^\"]*)" as the email of "([^\"]*)"$/ do |email, name|
65
+ output = git_config
66
+ authors = output.split("\n").map { |line| line =~ /^git-pair\.authors=.* <([^>]+)>$/; $1 }.compact
67
+ assert_equal 1, authors.select { |author| author == email}.size
68
+ end
69
+
70
+ Then /^`git pair` should display the following author list:$/ do |table|
71
+ output = git_pair
72
+ names = authors_list_from_output(output).map { |name| {"name" => name} }
73
+ table.diff! names
74
+ end
75
+
76
+ Then /^`git pair` should display an empty author list$/ do
77
+ output = git_pair
78
+ assert authors_list_from_output(output).empty?
79
+ end
80
+
81
+ Then /^the last command's output should include "([^\"]*)"$/ do |output|
82
+ assert @output.include?(output)
83
+ end
84
+
85
+ Then /^the config file should have no authors$/ do
86
+ git_config(%(--global --get-all git-pair.authors)).should == ''
87
+ end
88
+
89
+ Then /^I add the email configuration pattern "([^"]*)"$/ do |pattern_string|
90
+ git_pair %(--pattern "#{pattern_string}")
91
+ end
92
+
93
+ def authors_list_from_output(output)
94
+ output =~ /Author list: (.*?)\n\s?\n/im
95
+ $1.strip.split("\n").map { |name| name.strip }
96
+ end
97
+
98
+ def current_author_from_output(output)
99
+ output =~ /Current author: (.*?)\n/im
100
+ $1.strip
101
+ end
102
+
103
+ def current_email_from_output(output)
104
+ output =~ /Current email: (.*?)\n/im
105
+ $1.strip
106
+ end
@@ -0,0 +1,48 @@
1
+ require 'tmpdir'
2
+ require 'test/unit/assertions'
3
+ World(Test::Unit::Assertions)
4
+
5
+ module RepositoryHelper
6
+ # TODO: use 1.8.7's Dir.mktmpdir?
7
+ TEST_REPO_PATH = File.join(Dir::tmpdir, "git-pair-test-repo")
8
+ TEST_REPO_DOT_GIT_PATH = "#{TEST_REPO_PATH}/.git"
9
+
10
+ PROJECT_PATH = File.join(File.dirname(__FILE__), "../..")
11
+ GIT_PAIR = "#{PROJECT_PATH}/bin/git-pair"
12
+ CONFIG_BACKUP_PATH = "#{PROJECT_PATH}/tmp"
13
+
14
+ def git_pair(options = "")
15
+ output = `HOME=#{TEST_REPO_PATH} GIT_DIR=#{TEST_REPO_DOT_GIT_PATH} #{GIT_PAIR} #{options} 2>&1`
16
+ output.gsub(/\e\[\d\d?m/, '') # strip any ANSI colors
17
+ end
18
+
19
+ def git_config(options = nil)
20
+ options ||= "--list"
21
+ `HOME=#{TEST_REPO_PATH} GIT_DIR=#{TEST_REPO_DOT_GIT_PATH} git config #{options} 2>&1`
22
+ end
23
+
24
+ def backup_gitconfigs
25
+ FileUtils.mkdir_p CONFIG_BACKUP_PATH
26
+ FileUtils.cp File.expand_path("~/.gitconfig"), "#{CONFIG_BACKUP_PATH}/.gitconfig.backup"
27
+ FileUtils.cp "#{PROJECT_PATH}/.git/config", "#{CONFIG_BACKUP_PATH}/config.backup"
28
+ end
29
+
30
+ def restore_gitconfigs
31
+ FileUtils.cp "#{CONFIG_BACKUP_PATH}/config.backup", "#{PROJECT_PATH}/.git/config"
32
+ FileUtils.cp "#{CONFIG_BACKUP_PATH}/.gitconfig.backup", File.expand_path("~/.gitconfig")
33
+ FileUtils.rm_rf CONFIG_BACKUP_PATH
34
+ end
35
+ end
36
+
37
+ World(RepositoryHelper)
38
+
39
+ Before do
40
+ backup_gitconfigs
41
+ FileUtils.mkdir_p RepositoryHelper::TEST_REPO_PATH
42
+ `cd #{RepositoryHelper::TEST_REPO_PATH} && git init`
43
+ end
44
+
45
+ After do
46
+ FileUtils.rm_rf RepositoryHelper::TEST_REPO_PATH
47
+ restore_gitconfigs
48
+ end
@@ -0,0 +1,22 @@
1
+ Feature: Switching authors
2
+ In order to indicate which authors are committing
3
+ A user should be able to
4
+ change the currently active pair
5
+
6
+ Scenario: No authors have been added
7
+ When I try to switch to the pair "AA BB"
8
+ Then the last command's output should include "Please add some authors first"
9
+
10
+ Scenario: Pairing with a single author
11
+ Given I have added the author "Linus Torvalds <linus@example.org>"
12
+ When I switch to the pair "LT"
13
+ Then `git pair` should display "Linus Torvalds" for the current author
14
+ And `git pair` should display "linus@example.org" for the current email
15
+
16
+ Scenario: Pairing with two authors
17
+ Given I have added the author "Linus Torvalds <linus@example.org>"
18
+ And I have added the author "Junio C Hamano <junio@example.org>"
19
+ And my global Git configuration is setup with email "devs@example.com"
20
+ When I switch to the pair "LT JCH"
21
+ Then `git pair` should display "Junio C Hamano + Linus Torvalds" for the current author
22
+ And `git pair` should display "devs+jch+lt@example.com" for the current email
@@ -0,0 +1,12 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'git-pair/command'
4
+ require 'git-pair/author'
5
+ require 'git-pair/config'
6
+
7
+ module GitPair
8
+
9
+ class NoMatchingAuthorsError < ArgumentError; end
10
+ class MissingConfigurationError < RuntimeError; end
11
+
12
+ end
@@ -0,0 +1,71 @@
1
+ module GitPair
2
+ class Author
3
+
4
+ ValidAuthorStringRegex = /^\s*([^<]+)<([^>]+)>\s*$/
5
+
6
+ class InvalidAuthorString < TypeError; end
7
+
8
+ def self.all
9
+ Config.all_author_strings.map { |string| new(string) }
10
+ end
11
+
12
+ def self.find_all(abbrs)
13
+ raise MissingConfigurationError, "Please add some authors first" if all.empty?
14
+ abbrs.map { |abbr| self.find(abbr) }
15
+ end
16
+
17
+ def self.find(abbr)
18
+ all.find { |author| author.match?(abbr) } ||
19
+ raise(NoMatchingAuthorsError, "no authors matched #{abbr}")
20
+ end
21
+
22
+ def self.email(authors)
23
+ if authors.length == 1
24
+ authors.first.email
25
+ else
26
+ initials_string = '+' + authors.map { |a| a.initials }.join('+')
27
+ Config.default_email.sub("@", "#{initials_string}@")
28
+ end
29
+ end
30
+
31
+ def self.exists?(author)
32
+ self.all.find { |a| a.name == author.name }
33
+ end
34
+
35
+ def self.valid_string?(author_string)
36
+ author_string =~ ValidAuthorStringRegex
37
+ end
38
+
39
+ attr_reader :name, :email
40
+
41
+ def initialize(string)
42
+ unless Author.valid_string?(string)
43
+ raise(InvalidAuthorString, "\"#{string}\" is not a valid name and email")
44
+ end
45
+
46
+ string =~ ValidAuthorStringRegex
47
+ @name = $1.to_s.strip
48
+ @email = $2.to_s.strip
49
+ end
50
+
51
+ def <=>(other)
52
+ first_name <=> other.first_name
53
+ end
54
+
55
+ def initials
56
+ name.split.map { |word| word[0].chr }.join.downcase
57
+ end
58
+
59
+ def first_name
60
+ name.split.first.downcase
61
+ end
62
+
63
+ def last_name
64
+ name.split.last.downcase
65
+ end
66
+
67
+ def match?(abbr)
68
+ abbr.downcase == initials
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,104 @@
1
+ require 'optparse'
2
+
3
+ module GitPair
4
+ module Command
5
+ extend self
6
+
7
+ C_BOLD, C_REVERSE, C_RED, C_RESET = "\e[1m", "\e[7m", "\e[91m", "\e[0m"
8
+
9
+ def run!(args)
10
+ parser = OptionParser.new do |opts|
11
+ opts.banner = highlight('General Syntax:')
12
+ opts.separator ' git pair [reset | authors | options]'
13
+
14
+ opts.separator ' '
15
+ opts.separator highlight('Options:')
16
+ opts.on '-a', '--add AUTHOR', 'Add an author. Format: "Author Name <author@example.com>"' do |author|
17
+ Config.add_author Author.new(author)
18
+ end
19
+ opts.on '-r', '--remove NAME', 'Remove an author. Use the full name.' do |name|
20
+ Config.remove_author name
21
+ end
22
+ opts.on '-d', '--reset', 'Reset current author to default (global) config' do
23
+ Config.reset
24
+ end
25
+ opts.on '--pattern PATTERN', "Set email pattern. Example: \"dev+%name+%name@%domain\"\n" +
26
+ " %name - First name\n" +
27
+ " %last - Last name\n" +
28
+ " %abbr - Abbreviation\n" +
29
+ " %domain - Use domain from global config\n" do |pattern|
30
+ Config.set_pattern(pattern)
31
+ end
32
+ opts.on'--remove-pattern', 'Reset the current email pattern to default.' do
33
+ Config.remove_pattern
34
+ end
35
+
36
+ opts.separator ' '
37
+ opts.separator highlight('Switching authors:')
38
+ opts.separator ' git pair aa [bb] Where AA and BB are any abbreviation of an'
39
+ opts.separator ' '*37 + 'author\'s name. You can specify one or more authors.'
40
+
41
+ opts.separator ' '
42
+ opts.separator highlight('Current config:')
43
+ opts.separator author_list.split("\n")
44
+ opts.separator pattern_info
45
+ opts.separator ' '
46
+ opts.separator current_author_info.split("\n")
47
+ end
48
+
49
+ authors = parser.parse!(args.dup)
50
+
51
+ if args.empty?
52
+ puts parser.help
53
+ elsif authors.empty?
54
+ puts author_list
55
+ puts pattern_info
56
+ puts
57
+ puts current_author_info
58
+ else
59
+ Config.switch Author.find_all(authors)
60
+ puts current_author_info
61
+ end
62
+
63
+ rescue OptionParser::MissingArgument
64
+ abort "missing required argument", parser.help
65
+ rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => e
66
+ abort e.message.sub(':', ''), parser.help
67
+ rescue NoMatchingAuthorsError => e
68
+ abort e.message, "\n" + author_list
69
+ rescue MissingConfigurationError => e
70
+ abort e.message, parser.help
71
+ rescue Author::InvalidAuthorString => e
72
+ abort e.message, parser.help
73
+ end
74
+
75
+ def author_list
76
+ " #{bold 'Author list:'} #{Author.all.sort.map { |a| a.name }.join("\n ")}\n\ "
77
+ end
78
+
79
+ def pattern_info
80
+ " #{bold ' Email pattern:'} #{Config.pattern}\n"
81
+ end
82
+
83
+ def current_author_info
84
+ " #{bold 'Current author:'} #{Config.current_author}\n" +
85
+ " #{bold 'Current email:'} #{Config.current_email}"
86
+ end
87
+
88
+ def abort(error_message, extra = "")
89
+ super red(" Error: #{error_message}\n") + extra
90
+ end
91
+
92
+ def highlight(string)
93
+ "#{C_REVERSE}#{string}#{C_RESET}"
94
+ end
95
+
96
+ def bold(string)
97
+ "#{C_BOLD}#{string}#{C_RESET}"
98
+ end
99
+
100
+ def red(string)
101
+ "#{C_RED}#{C_REVERSE}#{string}#{C_RESET}"
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,97 @@
1
+ module GitPair
2
+ module Config
3
+ extend self
4
+
5
+ DEFAULT_PATTERN = "devs+%abbr+%abbr@%domain"
6
+
7
+ def all_author_strings
8
+ `git config --global --get-all git-pair.authors`.split("\n")
9
+ end
10
+
11
+ def pattern
12
+ if get_pattern.length > 0
13
+ get_pattern
14
+ else
15
+ DEFAULT_PATTERN
16
+ end
17
+ end
18
+
19
+ def get_pattern
20
+ `git config --get git-pair.pattern`.strip
21
+ end
22
+
23
+ def set_pattern(pattern)
24
+ `git config --global --replace-all git-pair.pattern "#{pattern}"`
25
+ end
26
+
27
+ def remove_pattern
28
+ `git config --global --unset-all git-pair.pattern`
29
+ end
30
+
31
+ def add_author(author)
32
+ unless Author.exists?(author)
33
+ `git config --global --add git-pair.authors "#{author.name} <#{author.email}>"`
34
+ end
35
+ end
36
+
37
+ def remove_author(name)
38
+ `git config --global --unset-all git-pair.authors "^#{name} <"`
39
+ `git config --global --remove-section git-pair` if all_author_strings.empty?
40
+ end
41
+
42
+ def switch(authors)
43
+ authors.sort!
44
+ `git config user.name "#{authors.map { |a| a.name }.join(' + ')}"`
45
+ `git config user.email "#{pair_email(authors)}"`
46
+ end
47
+
48
+ def reset
49
+ `git config --remove-section user`
50
+ end
51
+
52
+ def default_email
53
+ `git config --global --get user.email`.strip
54
+ end
55
+
56
+ def default_domain
57
+ default_email.split('@').last
58
+ end
59
+
60
+ def current_author
61
+ `git config --get user.name`.strip
62
+ end
63
+
64
+ def current_email
65
+ `git config --get user.email`.strip
66
+ end
67
+
68
+ private
69
+ def pair_email(authors)
70
+ if authors.size == 1
71
+ return authors.first.email
72
+ end
73
+
74
+ email = pattern.dup
75
+
76
+ authors.each do |author|
77
+ email.sub! '%name', author.first_name
78
+ email.sub! '%last', author.last_name
79
+ email.sub! '%abbr', author.initials
80
+ end
81
+
82
+ if email =~ /%domain/
83
+ email.sub!('%domain', domain(authors.first))
84
+ end
85
+
86
+ email
87
+ end
88
+
89
+ def domain(author)
90
+ if default_domain.length > 0
91
+ default_domain
92
+ else
93
+ author.email.split('@').last
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ module Git
2
+ module Pair
3
+ VERSION = "0.2.3"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "git-pair/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mynewsdesk-git-pair"
7
+ s.version = Git::Pair::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Kampmeier", "Adam McCrea", "Jon Distad", "Ingemar"]
10
+ s.email = "dev@mynewsdesk.com"
11
+ s.homepage = "http://github.com/mynewsdesk/git-pair"
12
+ s.summary = "Configure git to commit as more than one author"
13
+ s.description = "A git porcelain for pair programming. Changes git-config's user.name and user.email settings so you can commit as more than one author."
14
+
15
+
16
+ s.rubyforge_project = "git-pair"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency 'cucumber', "~> 1.0"
24
+ s.add_development_dependency 'rspec', "~> 2.6.0"
25
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mynewsdesk-git-pair
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 3
10
+ version: 0.2.3
11
+ platform: ruby
12
+ authors:
13
+ - Chris Kampmeier
14
+ - Adam McCrea
15
+ - Jon Distad
16
+ - Ingemar
17
+ autorequire:
18
+ bindir: bin
19
+ cert_chain: []
20
+
21
+ date: 2011-09-08 00:00:00 Z
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: cucumber
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ hash: 15
32
+ segments:
33
+ - 1
34
+ - 0
35
+ version: "1.0"
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 23
47
+ segments:
48
+ - 2
49
+ - 6
50
+ - 0
51
+ version: 2.6.0
52
+ type: :development
53
+ version_requirements: *id002
54
+ description: A git porcelain for pair programming. Changes git-config's user.name and user.email settings so you can commit as more than one author.
55
+ email: dev@mynewsdesk.com
56
+ executables:
57
+ - git-pair
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - .autotest
64
+ - .gitignore
65
+ - .rvmrc
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE
69
+ - README.markdown
70
+ - Rakefile
71
+ - Rakefilex
72
+ - VERSION
73
+ - bin/git-pair
74
+ - config/cucumber.yml
75
+ - features/adding_an_author.feature
76
+ - features/configuring_pair_email.feature
77
+ - features/removing_an_author.feature
78
+ - features/resetting_the_pair.feature
79
+ - features/step_definitions/config_steps.rb
80
+ - features/support/env.rb
81
+ - features/switching_authors.feature
82
+ - lib/git-pair.rb
83
+ - lib/git-pair/author.rb
84
+ - lib/git-pair/command.rb
85
+ - lib/git-pair/config.rb
86
+ - lib/git-pair/version.rb
87
+ - mynewsdesk-git-pair.gemspec
88
+ homepage: http://github.com/mynewsdesk/git-pair
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project: git-pair
117
+ rubygems_version: 1.8.6
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Configure git to commit as more than one author
121
+ test_files:
122
+ - features/adding_an_author.feature
123
+ - features/configuring_pair_email.feature
124
+ - features/removing_an_author.feature
125
+ - features/resetting_the_pair.feature
126
+ - features/step_definitions/config_steps.rb
127
+ - features/support/env.rb
128
+ - features/switching_authors.feature