simple-git-pair 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,14 +1,26 @@
1
- ## 0.0.1
2
- - Initial release
1
+ ## 0.2.0
2
+ - New command: git pair delete
3
+ - New command: git pair list
4
+ - Added support ruby-1.9.2 spport
5
+ - Bugfix: `git pair add` doesn't add a same pair
3
6
 
4
- ## 0.0.2
5
- - Added rspec suite
6
- - Fixed ugly output if unknown pair is specified
7
+ ## 0.1.0
8
+ - New command: git pair add
9
+ - Added post install message
10
+ - Fixed noisy error message on failed validation
11
+ - Added some color to output
12
+
13
+ ## 0.0.4
14
+ - Interactive creation of a sample config
7
15
 
8
16
  ## 0.0.3
9
17
  - Added integration test suite
10
18
  - git pair init command
11
19
  - Improved documentation
12
20
 
13
- ## 0.0.4
14
- - Interactive creation of a sample config
21
+ ## 0.0.2
22
+ - Added rspec suite
23
+ - Fixed ugly output if unknown pair is specified
24
+
25
+ ## 0.0.1
26
+ - Initial release
data/README.md CHANGED
@@ -13,25 +13,22 @@ This is especially useful for Github graphs and statistics.
13
13
  ```sh
14
14
  gem install simple-git-pair
15
15
  git pair init
16
- git pair nt ae # changes your git user.name to "Nicola Tesla & Alfred Einstein"
16
+ git pair nt ae # changes your git user.name to "Nikola Tesla & Alfred Einstein"
17
17
  ```
18
18
 
19
- ## Configuration
20
- Keep your pairs in `.git_pairs` file in your home directory in yaml format, e.g.
21
- ```yml
22
- nt: Nicola Tesla
23
- ae: Alfred Einstein
24
- ...
19
+ ## Available commands
20
+ ```sh
21
+ git pair init # create a sample .git_pairs file in your home directory
22
+ git pair add <initials> <Full Name> # add a new pair
23
+ git pair delete <initial> # delete a pair from .git_pairs
24
+ git pair list # list all available pairs
25
+ git pair help # display a help page
25
26
  ```
26
27
 
27
28
  ## Supported Rubies
28
29
  - 1.9.3
30
+ - 1.9.2
29
31
  - 1.8.7
30
32
 
31
- ## Future Development
32
- - git pair add <initial> <full_name> # adds an author to .git_pairs
33
- - git pair delete <initial> # deletes a pair from .git_pairs
34
- - git pair list # lists all available pairs
35
-
36
33
  ## Issues and Contributions
37
34
  Feel free to submit [issues](https://github.com/fsproru/simple-git-pair/issues), pull requests or [feedback](mailto: a.tamoykin@gmail.com)
data/bin/git-pair CHANGED
@@ -3,19 +3,18 @@ require 'rubygems'
3
3
  require 'commander/import'
4
4
  require 'simple-git-pair'
5
5
 
6
- #TODO: figure out a better way to output usage first
7
6
  program :name, "\n Usage:\n #{SimpleGitPair::BINARY_NAME} <initials>"
8
7
  program :version, SimpleGitPair::VERSION
9
8
  program :description, SimpleGitPair::SUMMARY
10
9
  program :int_message, "Good bye"
11
- program :help, 'Example', 'git pair nt ae Changes your git user.name to "Nicola Tesla & Alfred Einstein"'
10
+ program :help, 'Example', 'git pair nt ae Changes your git user.name to "Nikola Tesla & Alfred Einstein"'
12
11
  program :help_formatter, :compact
13
12
 
14
13
  default_command :change
15
14
  command :change do |c|
16
15
  c.description = "Change your git user.name"
17
16
  c.syntax = "#{SimpleGitPair::BINARY_NAME} change <initials>"
18
- c.example 'Nicola Tesla & Alfred Einstein', "#{SimpleGitPair::BINARY_NAME} change nt ae"
17
+ c.example 'Nikola Tesla & Alfred Einstein', "#{SimpleGitPair::BINARY_NAME} change nt ae"
19
18
  c.action do |args, options|
20
19
  if args.empty?
21
20
  commands['help'].run
@@ -34,6 +33,15 @@ command :init do |c|
34
33
  end
35
34
  end
36
35
 
36
+ command :list do |c|
37
+ c.description = "List available pairs"
38
+ c.syntax = SimpleGitPair::Command::List::USAGE
39
+ c.example "Lists all available pairs", "#{SimpleGitPair::BINARY_NAME} list"
40
+ c.action do |args, options|
41
+ SimpleGitPair::Command::List.new.run!
42
+ end
43
+ end
44
+
37
45
  command :add do |c|
38
46
  c.description = "Add new pair to a list"
39
47
  c.syntax = SimpleGitPair::Command::Add::USAGE
@@ -42,3 +50,12 @@ command :add do |c|
42
50
  SimpleGitPair::Command::Add.new(args).run!
43
51
  end
44
52
  end
53
+
54
+ command :delete do |c|
55
+ c.description = "Delete existing pair"
56
+ c.syntax = SimpleGitPair::Command::Delete::USAGE
57
+ c.example "Deletes og from pairs list", "#{SimpleGitPair::BINARY_NAME} delete og"
58
+ c.action do |args, options|
59
+ SimpleGitPair::Command::Delete.new(args).run!
60
+ end
61
+ end
@@ -3,3 +3,5 @@ require 'simple-git-pair/command/base'
3
3
  require 'simple-git-pair/command/init'
4
4
  require 'simple-git-pair/command/change'
5
5
  require 'simple-git-pair/command/add'
6
+ require 'simple-git-pair/command/delete'
7
+ require 'simple-git-pair/command/list'
@@ -17,15 +17,11 @@ module SimpleGitPair
17
17
  end
18
18
 
19
19
  pairs = Helper.read_pairs
20
- existent_user = pairs[initials]
20
+ existing_user = pairs[initials]
21
21
  message = ""
22
22
 
23
- if existent_user
24
- unless agree("#{initials} has alredy taken by #{existent_user}. Override it with #{fullname}? (yes/no)")
25
- puts "#{fullname} was not added"
26
- exit 1
27
- end
28
-
23
+ if existing_user
24
+ exit 1 unless user_needs_update? existing_user, initials, fullname
29
25
  message = "Updated #{initials} to be #{fullname}"
30
26
  else
31
27
  message = "Added #{fullname}"
@@ -51,6 +47,18 @@ module SimpleGitPair
51
47
  errors << "Please provide a Full Name" if fullname == ""
52
48
  [ initials, fullname, errors.empty?, errors ]
53
49
  end
50
+
51
+ def user_needs_update? existing_user, initials, fullname
52
+ if existing_user == fullname
53
+ puts "#{fullname} already exists"
54
+ false
55
+ elsif not agree("#{initials} has already taken by #{existing_user}. Override it with #{fullname}? (yes/no)")
56
+ puts "#{fullname} was not added"
57
+ false
58
+ else
59
+ true
60
+ end
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -0,0 +1,46 @@
1
+ require 'simple-git-pair/command/base'
2
+ require 'rainbow'
3
+
4
+ module SimpleGitPair
5
+ module Command
6
+ class Delete < Base
7
+ USAGE = "#{BINARY_NAME} delete <initials>"
8
+
9
+ def run!
10
+ exit 1 unless ensure_pairs_file_exists
11
+
12
+ initials, valid_opts, errors = validate_opts
13
+ unless valid_opts
14
+ puts errors.join "\n"
15
+ puts "Usage: #{USAGE}"
16
+ exit 1
17
+ end
18
+
19
+ pairs = Helper.read_pairs
20
+ existing_user = pairs[initials]
21
+
22
+ if existing_user
23
+ pairs.delete initials
24
+ Helper.save_pairs pairs
25
+ puts "Deleted #{initials}: #{existing_user}".color(:green)
26
+ else
27
+ puts "There is no #{initials}"
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ ##
34
+ # Validate and return options
35
+ #
36
+ # Returns: array
37
+ # [initials, status, errors]
38
+ def validate_opts
39
+ initials = opts.shift
40
+ errors = []
41
+ errors << "Initials should contain no spaces" if /\s/.match initials
42
+ [ initials, errors.empty?, errors ]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,20 @@
1
+ require 'simple-git-pair/command/base'
2
+
3
+ module SimpleGitPair
4
+ module Command
5
+ class List < Base
6
+ USAGE = "#{BINARY_NAME} list"
7
+
8
+ def run!
9
+ exit 1 unless ensure_pairs_file_exists
10
+
11
+ pairs = Helper.read_pairs
12
+ if pairs.empty?
13
+ puts "No pairs available. Use 'git pair add' to add more pairs."
14
+ else
15
+ pairs.each {|initials, fullname| puts "#{initials}: #{fullname}"}
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module SimpleGitPair
2
2
  SUMMARY = "Simple way to add your pair to a git commit message"
3
3
  BINARY_NAME = "git pair"
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -4,28 +4,30 @@ require 'simple-git-pair/command/add'
4
4
  describe SimpleGitPair::Command::Add do
5
5
  let(:opts) { [] }
6
6
  let(:command) { described_class.new opts }
7
+ before { command.stub :puts }
7
8
 
8
9
  describe "#run!" do
9
10
  subject { command.run! }
10
- before { command.stub :puts }
11
11
 
12
12
  it_should_behave_like "command that ensures that pairs file exists"
13
13
 
14
14
  context "there is a pairs file" do
15
+ before { command.stub(:ensure_pairs_file_exists).and_return true }
16
+
15
17
  context "and there is already a pair with the same initials" do
16
18
  let(:opts) { ["ng", "New", "Guy"] }
17
19
  before { SimpleGitPair::Helper.stub(:read_pairs).and_return({"ng" => "Already Exists"}) }
18
20
 
19
- context "and user agrees to override" do
20
- before { command.stub(:agree).and_return true }
21
+ context "and user needs an update" do
22
+ before { command.stub(:user_needs_update?).and_return true }
21
23
  it "overrides the pair" do
22
24
  SimpleGitPair::Helper.should_receive(:save_pairs).with({"ng" => "New Guy"})
23
25
  subject
24
26
  end
25
27
  end
26
28
 
27
- context "and user dissagrees to override" do
28
- before { command.stub(:agree).and_return false }
29
+ context "and user does NOT need an update" do
30
+ before { command.stub(:user_needs_update?).and_return false }
29
31
  it "doesn't override and exits" do
30
32
  SimpleGitPair::Helper.should_not_receive :save_pairs
31
33
  expect {subject}.to raise_error SystemExit
@@ -77,4 +79,29 @@ describe SimpleGitPair::Command::Add do
77
79
  end
78
80
  end
79
81
  end
82
+
83
+ describe "#user_needs_update?" do
84
+ let(:existing_user) { "Old Guy" }
85
+ let(:initials) { "og" }
86
+ subject { command.send :user_needs_update?, existing_user, initials, fullname }
87
+
88
+ context "user already exists with same initials and fullname" do
89
+ let(:fullname) { "Old Guy" }
90
+ it {should be_false}
91
+ end
92
+
93
+ context "user already exists with same initials only" do
94
+ let(:fullname) { "New Guy" }
95
+
96
+ context "user disagrees to override it" do
97
+ before { command.stub(:agree).and_return false }
98
+ it {should be_false}
99
+ end
100
+
101
+ context "user agrees to override it" do
102
+ before { command.stub(:agree).and_return true }
103
+ it {should be_true}
104
+ end
105
+ end
106
+ end
80
107
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'simple-git-pair/command/delete'
3
+
4
+ describe SimpleGitPair::Command::Delete do
5
+ let(:opts) { [] }
6
+ let(:command) { described_class.new opts }
7
+
8
+ describe "#run!" do
9
+ subject { command.run! }
10
+ before { command.stub :puts }
11
+
12
+ it_should_behave_like "command that ensures that pairs file exists"
13
+
14
+ context "there is a pairs file" do
15
+ before { command.stub(:ensure_pairs_file_exists).and_return true }
16
+
17
+ context "and specified pair exists" do
18
+ let(:opts) { ["dm"] }
19
+ before { SimpleGitPair::Helper.stub(:read_pairs).and_return({"dm" => "Delete me", "km" => "Keep Me"}) }
20
+
21
+ it "deletes it" do
22
+ SimpleGitPair::Helper.should_receive(:save_pairs).with({"km" => "Keep Me"})
23
+ subject
24
+ end
25
+ end
26
+
27
+ context "and specified pair does NOT exist" do
28
+ let(:opts) { ["dm"] }
29
+ before { SimpleGitPair::Helper.stub(:read_pairs).and_return({"km" => "Keep Me"}) }
30
+
31
+ it "does NOT delete it" do
32
+ SimpleGitPair::Helper.should_not_receive :save_pairs
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#validate_opts" do
39
+ subject { command.send :validate_opts }
40
+
41
+ context "initials have spaces" do
42
+ let(:opts) { ["n g"] }
43
+ it "returns error status and msg" do
44
+ initials, valid_opts, errors = subject
45
+ valid_opts.should be_false
46
+ errors.should_not be_empty
47
+ end
48
+ end
49
+
50
+ context "initals are fine" do
51
+ let(:opts) { ["og"] }
52
+
53
+ it "returns intials and no error" do
54
+ initials, valid_opts, errors = subject
55
+ initials.should == "og"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'simple-git-pair/command/list'
3
+
4
+ describe SimpleGitPair::Command::List do
5
+ let(:command) { described_class.new }
6
+
7
+ describe "#run!" do
8
+ subject { command.run! }
9
+
10
+ it_should_behave_like "command that ensures that pairs file exists"
11
+
12
+ context "there is a pairs file" do
13
+ before { command.stub(:ensure_pairs_file_exists).and_return true }
14
+
15
+ context "there are available pairs" do
16
+ before { SimpleGitPair::Helper.stub(:read_pairs).and_return({"od" => "One Dude", "ad" => "Another Dude"}) }
17
+ it "displays them" do
18
+ command.should_receive(:puts).with("od: One Dude")
19
+ command.should_receive(:puts).with("ad: Another Dude")
20
+ subject
21
+ end
22
+ end
23
+
24
+ context "there is NO available pairs" do
25
+ before { SimpleGitPair::Helper.stub(:read_pairs).and_return({}) }
26
+ it "complains" do
27
+ command.should_receive(:puts).with("No pairs available. Use 'git pair add' to add more pairs.")
28
+ subject
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -11,7 +11,7 @@ describe SimpleGitPair::Helper do
11
11
  subject {described_class.names_for initials}
12
12
 
13
13
  context "there is NO user in pairs file" do
14
- let(:initials) { ["non_existent_pair"] }
14
+ let(:initials) { ["non_existing_pair"] }
15
15
  it { expect { subject }.to raise_error }
16
16
  end
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-git-pair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander
16
- requirement: &70239044165920 !ruby/object:Gem::Requirement
16
+ requirement: &70223973955700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70239044165920
24
+ version_requirements: *70223973955700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rainbow
27
- requirement: &70239044181500 !ruby/object:Gem::Requirement
27
+ requirement: &70223973955060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70239044181500
35
+ version_requirements: *70223973955060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70239044180880 !ruby/object:Gem::Requirement
38
+ requirement: &70223973954620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70239044180880
46
+ version_requirements: *70223973954620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: aruba
49
- requirement: &70239044180280 !ruby/object:Gem::Requirement
49
+ requirement: &70223973954040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70239044180280
57
+ version_requirements: *70223973954040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: cucumber
60
- requirement: &70239044179400 !ruby/object:Gem::Requirement
60
+ requirement: &70223973953420 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70239044179400
68
+ version_requirements: *70223973953420
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &70239044178820 !ruby/object:Gem::Requirement
71
+ requirement: &70223973952520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70239044178820
79
+ version_requirements: *70223973952520
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: debugger
82
- requirement: &70239044178320 !ruby/object:Gem::Requirement
82
+ requirement: &70223973950980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70239044178320
90
+ version_requirements: *70223973950980
91
91
  description: Simple way to add your pair to a git commit message
92
92
  email:
93
93
  - a.tamoykin@gmail.com
@@ -99,7 +99,9 @@ files:
99
99
  - lib/simple-git-pair/command/add.rb
100
100
  - lib/simple-git-pair/command/base.rb
101
101
  - lib/simple-git-pair/command/change.rb
102
+ - lib/simple-git-pair/command/delete.rb
102
103
  - lib/simple-git-pair/command/init.rb
104
+ - lib/simple-git-pair/command/list.rb
103
105
  - lib/simple-git-pair/helper.rb
104
106
  - lib/simple-git-pair/version.rb
105
107
  - lib/simple-git-pair.rb
@@ -109,7 +111,9 @@ files:
109
111
  - spec/lib/simple-git-pair/command/add_spec.rb
110
112
  - spec/lib/simple-git-pair/command/base_spec.rb
111
113
  - spec/lib/simple-git-pair/command/change_spec.rb
114
+ - spec/lib/simple-git-pair/command/delete_spec.rb
112
115
  - spec/lib/simple-git-pair/command/init_spec.rb
116
+ - spec/lib/simple-git-pair/command/list_spec.rb
113
117
  - spec/lib/simple-git-pair/helper_spec.rb
114
118
  - spec/spec_helper.rb
115
119
  - spec/support/shared_examples/command_examples.rb
@@ -143,7 +147,9 @@ test_files:
143
147
  - spec/lib/simple-git-pair/command/add_spec.rb
144
148
  - spec/lib/simple-git-pair/command/base_spec.rb
145
149
  - spec/lib/simple-git-pair/command/change_spec.rb
150
+ - spec/lib/simple-git-pair/command/delete_spec.rb
146
151
  - spec/lib/simple-git-pair/command/init_spec.rb
152
+ - spec/lib/simple-git-pair/command/list_spec.rb
147
153
  - spec/lib/simple-git-pair/helper_spec.rb
148
154
  - spec/spec_helper.rb
149
155
  - spec/support/shared_examples/command_examples.rb