simple-git-pair 0.0.1

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.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ ## TL;DR
2
+ Simple way to add your pair to a git commit message.
3
+
4
+ ## Description
5
+ Unlike many other gems it doesn NOT change your email address in git config, so Github can associate your commit to github account properly.
6
+ This is especially useful for Github graphs and statistics.
7
+
8
+ ## Usage
9
+ `git pair nt ae` # changes your git user.name to "Nicola Tesla & Alfred Einstein"
10
+
11
+ ## Configuration
12
+ Create and keep your pairs in `.git_pairs` file in your home directory in yaml format, e.g.
13
+ ```yml
14
+ nt: Nicola Tesla
15
+ ae: Alfred Einstein
16
+ ...
17
+ ```
18
+
19
+ ## Future Development
20
+ - git pair init # creates simple .git_pairs file
21
+ - git pair add <initial> <full_name> # adds an author to .git_pairs
22
+ - git pair delete <initial> # deletes a pair from .git_pairs
23
+ - git pair list # lists all available pairs
24
+
25
+ ## Issues and Contributions
26
+ Feel free to submit issues or pull requests.
data/bin/git-pair ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'simple-git-pair'
3
+
4
+ SimpleGitPair::Cli.new(ARGV).run!
@@ -0,0 +1,2 @@
1
+ require 'simple-git-pair/helper'
2
+ require 'simple-git-pair/cli'
@@ -0,0 +1,26 @@
1
+ require 'simple-git-pair/helper'
2
+
3
+ module SimpleGitPair
4
+ class Cli
5
+ attr_accessor :opts
6
+
7
+ def initialize(opts = {})
8
+ self.opts = opts
9
+ end
10
+
11
+ def run!
12
+ if opts.delete "--help" or opts.delete "-h" or opts.empty?
13
+ Helper.show_help
14
+ exit 0
15
+ end
16
+
17
+ unless Helper.pairs_file_exists?
18
+ Helper.complain_about_pairs_file
19
+ exit 1
20
+ end
21
+
22
+ system "git config user.name '#{(Helper.names_for ARGV).join ' & '}'"
23
+ system "git config user.name" # output current username
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ require 'yaml'
2
+
3
+ module SimpleGitPair
4
+ module Helper
5
+ class << self
6
+ PAIRS_FILE = File.expand_path('~/.git_pairs')
7
+
8
+ def show_help
9
+ puts <<-EOS
10
+
11
+ Changes your git user.name to specified names from #{PAIRS_FILE}
12
+ Usage: git-pair <initial1> <initial2>
13
+ EOS
14
+ end
15
+
16
+ def complain_about_pairs_file
17
+ puts <<-EOS
18
+
19
+ Please create #{PAIRS_FILE.split("/").last} file in your home directory in yaml format:
20
+ ae: Alfred Einstein
21
+ nt: Nikola Tesla
22
+ EOS
23
+ end
24
+
25
+ def names_for args
26
+ pairs = YAML.load_file PAIRS_FILE
27
+
28
+ names = []
29
+ args.each do |opt|
30
+ raise "There is no entry for #{opt} in #{PAIRS_FILE}" unless pairs[opt]
31
+ names << pairs[opt]
32
+ end
33
+
34
+ names
35
+ end
36
+
37
+ def pairs_file_exists?
38
+ File.exist? PAIRS_FILE
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleGitPair
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,64 @@
1
+ require 'simple-git-pair/cli'
2
+
3
+ describe SimpleGitPair::Cli do
4
+ before { Object.stub(:system) }
5
+ let(:opts) { [] }
6
+ let(:cli) { described_class.new opts }
7
+
8
+ describe "#run!" do
9
+ subject { cli.run! }
10
+
11
+ context "there is no option passed in" do
12
+ let(:opts) { [] }
13
+ it "shows help" do
14
+ SimpleGitPair::Helper.should_receive :show_help
15
+ expect { subject }.to raise_error SystemExit
16
+ end
17
+ end
18
+
19
+ context "with --help or -h option" do
20
+ let(:opts) { ['--help', '-h'] }
21
+ it "shows help" do
22
+ SimpleGitPair::Helper.should_receive :show_help
23
+ expect { subject }.to raise_error SystemExit
24
+ end
25
+ end
26
+
27
+ context "there is NO pairs file" do
28
+ before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return false }
29
+ let(:opts) { ["some_initials"] }
30
+ it "complains and exit" do
31
+ SimpleGitPair::Helper.should_receive :complain_about_pairs_file
32
+ expect { subject }.to raise_error SystemExit
33
+ end
34
+ end
35
+
36
+ context "there is a pairs file" do
37
+ context "and multiple initials are passed in" do
38
+ before {
39
+ SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return true
40
+ SimpleGitPair::Helper.stub(:names_for).and_return ["Super Mario", "Pac Man"]
41
+ cli.stub! :system
42
+ }
43
+ let(:opts) { ['sm', 'pm'] }
44
+ it "changes only username to pair name" do
45
+ cli.should_receive(:system).with("git config user.name 'Super Mario & Pac Man'")
46
+ subject
47
+ end
48
+ end
49
+
50
+ context "and single initial is passed in" do
51
+ before {
52
+ SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return true
53
+ SimpleGitPair::Helper.stub(:names_for).and_return ["Pac Man"]
54
+ cli.stub! :system
55
+ }
56
+ let(:opts) { ['pm'] }
57
+ it "changes only username to single name" do
58
+ cli.should_receive(:system).with("git config user.name 'Pac Man'")
59
+ subject
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,39 @@
1
+ require 'simple-git-pair/helper'
2
+
3
+ describe SimpleGitPair::Helper do
4
+ describe :names_for do
5
+ before do
6
+ YAML.stub(:load_file).and_return(
7
+ { "pm" => "Pac Man", "sm" => "Super Mario" }
8
+ )
9
+ end
10
+
11
+ subject {described_class.names_for initials}
12
+
13
+ context "there is NO user in pairs file" do
14
+ let(:initials) { ["non_existent_pair"] }
15
+ it { expect { subject }.to raise_error }
16
+ end
17
+
18
+ context "there are users in pairs file" do
19
+ let(:initials) { ["pm", "sm"] }
20
+ it 'returns array with user names' do
21
+ subject.should == ["Pac Man", "Super Mario"]
22
+ end
23
+ end
24
+ end
25
+
26
+ describe :pairs_file_exists? do
27
+ subject { described_class.pairs_file_exists? }
28
+
29
+ context "pairs file exists" do
30
+ before { File.stub(:exist?).and_return true }
31
+ it { should be_true }
32
+ end
33
+
34
+ context "there is no pairs file" do
35
+ before { File.stub(:exist?).and_return false }
36
+ it { should be_false }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ Rspec.configure do |config|
4
+ config.color_enabled = true
5
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-git-pair
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Tamoykin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70211604747240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70211604747240
25
+ - !ruby/object:Gem::Dependency
26
+ name: debugger
27
+ requirement: &70211604746720 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70211604746720
36
+ description: Changes only user.name setting in git config, so github
37
+ can still understand under which account a code was committed
38
+ email:
39
+ - a.tamoykin@gmail.com
40
+ executables:
41
+ - git-pair
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - lib/simple-git-pair/cli.rb
46
+ - lib/simple-git-pair/helper.rb
47
+ - lib/simple-git-pair/version.rb
48
+ - lib/simple-git-pair.rb
49
+ - bin/git-pair
50
+ - README.md
51
+ - spec/lib/simple-git-pair/cli_spec.rb
52
+ - spec/lib/simple-git-pair/helper_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: http://github.com/fsproru/simple-git-pair
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.10
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Adds your pair to a commit message
78
+ test_files:
79
+ - spec/lib/simple-git-pair/cli_spec.rb
80
+ - spec/lib/simple-git-pair/helper_spec.rb
81
+ - spec/spec_helper.rb