git-pair 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ pkg
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,48 @@
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 git-pair
11
+
12
+ And here's how to use it!
13
+
14
+ $ git pair
15
+
16
+ Configuration:
17
+ git pair [options]
18
+ -a, --add NAME Add an author. Use the full name.
19
+ -r, --remove NAME Remove an author. Use the full name.
20
+ -e, --set-email TEMPLATE Set the email template. A value like devs@example.com
21
+ will be interpolated with the current authors' initials
22
+ into something like devs+aa+bb@example.com.
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
+ Once you've added authors, running `git pair` with no options will also print
29
+ out their names, the current pair, and some other information.
30
+
31
+ ## Known issues
32
+
33
+ * I just shoved everything into a gem. Refactor into separate files.
34
+ * Needs `git pair --reset` to restore the original `user.name` and `user.email`.
35
+ For now, just `git config --edit` and remove the `[user]` section to go back
36
+ to your global config.
37
+ * It'd be better if you could specify an email address for each author instead
38
+ of just automatically using the authors' initials. Especially if you have two
39
+ authors with the same initials. And also because when there's just one author,
40
+ it should use that person's email instead of an interpolation like
41
+ `devs+ck@example.com`.
42
+ * Don't add duplicate authors to the git-config (doesn't affect the proper
43
+ functioning of git-pair, but makes `git pair --add` not idempotent and
44
+ clutters up your config file).
45
+
46
+ ## License
47
+
48
+ Copyright (c) 2009 Chris Kampmeier. See `LICENSE` for details.
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "git-pair"
8
+ gem.version = File.read("lib/git-pair/VERSION").strip
9
+ gem.summary = %Q{Configure git to commit as more than one author}
10
+ gem.description = %Q{Configure git to commit as more than one author}
11
+ gem.email = "chris@kampers.net"
12
+ gem.homepage = "http://github.com/chrisk/git-pair"
13
+ gem.authors = ["Chris Kampmeier"]
14
+ gem.add_development_dependency "cucumber", ">= 0"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ begin
22
+ require 'cucumber/rake/task'
23
+ Cucumber::Rake::Task.new(:features)
24
+
25
+ task :features => :check_dependencies
26
+ rescue LoadError
27
+ task :features do
28
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
29
+ end
30
+ end
31
+
32
+ task :default => :features
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
+
4
+ require 'optparse'
5
+ require 'git-pair'
6
+
7
+ begin
8
+ banner = "\n#{$reverse} Configuration: #{$reset}"
9
+ parser = OptionParser.new do |opts|
10
+ opts.banner = banner
11
+ opts.separator " git pair [options]"
12
+ opts.on("-a", "--add NAME", "Add an author. Use the full name.") { |name| GitPair::Commands.add name }
13
+ opts.on("-r", "--remove NAME", "Remove an author. Use the full name.") { |name| GitPair::Commands.remove name }
14
+ opts.on("-e", "--set-email TEMPLATE", "Set the email template. A value like devs@example.com",
15
+ "will be interpolated with the current authors' initials",
16
+ "into something like devs+aa+bb@example.com.") { |email| GitPair::Commands.set_email_template email }
17
+
18
+ opts.separator " "
19
+ opts.separator ["#{$reverse} Switching authors: #{$reset}",
20
+ " git pair AA [BB] Where AA and BB are any abbreviation of an",
21
+ " "*37 + "author's name. You can specify one or more authors."]
22
+
23
+ opts.separator " "
24
+ opts.separator ["#{$reverse} Current config: #{$reset}",
25
+ *(GitPair::Helpers.display_string_for_config.split("\n") + [" "] +
26
+ GitPair::Helpers.display_string_for_current_info.split("\n"))]
27
+ end
28
+
29
+ unused_options = parser.parse!
30
+
31
+ if GitPair::Commands.config_change_made?
32
+ puts GitPair::Helpers.display_string_for_config
33
+ elsif unused_options.any?
34
+ GitPair::Commands.switch(unused_options)
35
+ puts GitPair::Helpers.display_string_for_current_info
36
+ elsif ARGV.empty?
37
+ puts parser.help
38
+ end
39
+
40
+ rescue OptionParser::MissingArgument
41
+ GitPair::Helpers.abort "missing required argument", parser.help
42
+ rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => e
43
+ GitPair::Helpers.abort e.message.sub(':', ''), parser.help
44
+ rescue GitPair::NoMatchingAuthorsError => e
45
+ GitPair::Helpers.abort e.message, "\n" + GitPair::Helpers.display_string_for_config
46
+ rescue GitPair::MissingConfigurationError => e
47
+ GitPair::Helpers.abort e.message, parser.help
48
+ end
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'git-pair'
3
+
4
+ require 'test/unit/assertions'
5
+
6
+ World(Test::Unit::Assertions)
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{git-pair}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chris Kampmeier"]
12
+ s.date = %q{2009-12-06}
13
+ s.default_executable = %q{git-pair}
14
+ s.description = %q{Configure git to commit as more than one author}
15
+ s.email = %q{chris@kampers.net}
16
+ s.executables = ["git-pair"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.markdown"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "bin/git-pair",
27
+ "features/git-pair.feature",
28
+ "features/step_definitions/git-pair_steps.rb",
29
+ "features/support/env.rb",
30
+ "git-pair.gemspec",
31
+ "lib/git-pair.rb",
32
+ "lib/git-pair/VERSION"
33
+ ]
34
+ s.homepage = %q{http://github.com/chrisk/git-pair}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Configure git to commit as more than one author}
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<cucumber>, [">= 0"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<cucumber>, [">= 0"])
51
+ end
52
+ end
53
+
@@ -0,0 +1,107 @@
1
+ $bold, $reverse, $red, $reset = "\e[1m", "\e[7m", "\e[91m", "\e[0m"
2
+
3
+ module GitPair
4
+
5
+ VERSION = File.read(File.join(File.dirname(__FILE__), "git-pair", "VERSION")).strip
6
+
7
+ class NoMatchingAuthorsError < ArgumentError; end
8
+ class MissingConfigurationError < RuntimeError; end
9
+
10
+
11
+ module Commands
12
+ def add(name)
13
+ @config_changed = true
14
+ `git config --add git-pair.authors "#{name}"`
15
+ end
16
+
17
+ def remove(name)
18
+ @config_changed = true
19
+ `git config --unset-all git-pair.authors "^#{name}$"`
20
+ end
21
+
22
+ def set_email_template(email)
23
+ @config_changed = true
24
+ `git config git-pair.email "#{email}"`
25
+ end
26
+
27
+ def config_change_made?
28
+ @config_changed
29
+ end
30
+
31
+ def switch(abbreviations)
32
+ raise MissingConfigurationError, "Please add some authors first" if Helpers.author_names.empty?
33
+ raise MissingConfigurationError, "Please set the email template first" if Helpers.email_template.empty?
34
+
35
+ names = abbreviations.map { |abbrev|
36
+ name = Helpers.author_name_from_abbreviation(abbrev)
37
+ raise NoMatchingAuthorsError, "no authors matched #{abbrev}" if name.nil?
38
+ name
39
+ }
40
+
41
+ sorted_names = names.uniq.sort_by { |name| name.split.last }
42
+ `git config user.name "#{sorted_names.join(' + ')}"`
43
+ initials = sorted_names.map { |name| name.split.map { |word| word[0].chr }.join.downcase }
44
+ `git config user.email "#{Helpers.email(*initials)}"`
45
+ end
46
+
47
+ extend self
48
+ end
49
+
50
+
51
+ module Helpers
52
+ def display_string_for_config
53
+ "#{$bold} Email template: #{$reset}" + email("[aa]", "[bb]") + "\n" +
54
+ "#{$bold} Author list: #{$reset}" + author_names.join("\n ")
55
+ end
56
+
57
+ def display_string_for_current_info
58
+ "#{$bold} Current author: #{$reset}" + current_author + "\n" +
59
+ "#{$bold} Current email: #{$reset}" + current_email + "\n "
60
+ end
61
+
62
+ def author_names
63
+ names = `git config --get-all git-pair.authors`.split("\n")
64
+ names.uniq.sort_by { |name| name.split.last }
65
+ end
66
+
67
+ def email(*initials_list)
68
+ initials_string = initials_list.map { |initials| "+#{initials}" }.join
69
+ email_template.sub("@", "#{initials_string}@")
70
+ end
71
+
72
+ def email_template
73
+ `git config --get git-pair.email`.strip
74
+ end
75
+
76
+ def current_author
77
+ `git config --get user.name`.strip
78
+ end
79
+
80
+ def current_email
81
+ `git config --get user.email`.strip
82
+ end
83
+
84
+ def author_name_from_abbreviation(abbrev)
85
+ # initials
86
+ author_names.each do |name|
87
+ return name if abbrev.downcase == name.split.map { |word| word[0].chr }.join.downcase
88
+ end
89
+
90
+ # start of a name
91
+ author_names.each do |name|
92
+ return name if name.gsub(" ", "") =~ /^#{abbrev}/i
93
+ end
94
+
95
+ # includes the letters in order
96
+ author_names.detect do |name|
97
+ name =~ /#{abbrev.split("").join(".*")}/i
98
+ end
99
+ end
100
+
101
+ def abort(error_message, extra = "")
102
+ super "#{$red}#{$reverse} Error: #{error_message} #{$reset}\n" + extra
103
+ end
104
+
105
+ extend self
106
+ end
107
+ end
@@ -0,0 +1 @@
1
+ 0.1.0
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-pair
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Kampmeier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-06 00:00:00 -08:00
13
+ default_executable: git-pair
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cucumber
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Configure git to commit as more than one author
26
+ email: chris@kampers.net
27
+ executables:
28
+ - git-pair
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.markdown
34
+ files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README.markdown
38
+ - Rakefile
39
+ - bin/git-pair
40
+ - features/git-pair.feature
41
+ - features/step_definitions/git-pair_steps.rb
42
+ - features/support/env.rb
43
+ - git-pair.gemspec
44
+ - lib/git-pair.rb
45
+ - lib/git-pair/VERSION
46
+ has_rdoc: true
47
+ homepage: http://github.com/chrisk/git-pair
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.5
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Configure git to commit as more than one author
74
+ test_files: []
75
+