git-duet 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50d7af1c799d72430af337f3ebce7f5594628022
4
- data.tar.gz: 8efc2502e7dbcf5048c208dc38dffef004b10ae8
3
+ metadata.gz: f5a7119cb29f7c28cbb125f4f33013cbb8cff6dc
4
+ data.tar.gz: 6b6a786fa89f95717f22295979b1921dde224f2c
5
5
  SHA512:
6
- metadata.gz: e36a169a110dbef6344c8f4c58dce163c4e83c432be772136a07095f84ba2ba80037da6bf2f8ba016c9211e92d23341ccae7209c502dc808aa3fd6063e0a1862
7
- data.tar.gz: c579fc838fe6616f768cf28a25e29a6d7e6c9a56ef050dc56f20d014305e4af3f289062718b0b7d8d3247337d5bf7bc73574cf8a70105d25b6ea372add205c85
6
+ metadata.gz: 2b48834810702670b620f63783b30a6ff53c0e6e4bdf33be742046f95b9bf221b9e179665533a31b784454f5129c24835b20628c8b808f1aa29b334be1969aed
7
+ data.tar.gz: dc1a039596092cffa2810c63c7aa1636c386f19aab13813bdf8c2183daadcea134012e38c95a8b5cde4a8d3b17b19c2285edbc760f0c52ca1553fccf392a9688
@@ -1,4 +1,5 @@
1
1
  ---
2
+ inherit_from: .rubocop_todo.yml
2
3
  AllCops:
3
4
  Include:
4
5
  - git-duet.gemspec
@@ -0,0 +1,15 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-05-23 12:02:33 -0700 using RuboCop version 0.31.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ Metrics/AbcSize:
10
+ Max: 17
11
+
12
+ # Offense count: 1
13
+ # Configuration parameters: CountComments.
14
+ Metrics/ModuleLength:
15
+ Max: 109
@@ -1,8 +1,10 @@
1
1
  ---
2
2
  language: ruby
3
+ sudo: false
3
4
  env:
4
5
  global:
5
6
  - COVERAGE=1
7
+ - PATH="$HOME/bin:$PATH"
6
8
  matrix:
7
9
  allow_failures:
8
10
  - rvm: jruby-19mode
@@ -12,8 +14,9 @@ rvm:
12
14
  - 2.1.3
13
15
  - jruby-19mode
14
16
  before_script:
15
- - "git clone https://github.com/sstephenson/bats.git"
16
- - "cd bats && sudo ./install.sh /usr/local"
17
+ - mkdir -p $HOME/bin
18
+ - git clone https://github.com/sstephenson/bats.git
19
+ - cd bats && ./install.sh $HOME
17
20
  script:
18
21
  - bundle exec rake
19
22
  - bundle exec bats test
data/README.md CHANGED
@@ -93,6 +93,21 @@ git solo -g jd
93
93
  git duet --global jd fb
94
94
  ```
95
95
 
96
+ If you do this habitually, you can set the `GIT_DUET_GLOBAL` environment
97
+ variable to `true` to always operate on the global git config:
98
+
99
+ ``` bash
100
+ export GIT_DUET_GLOBAL=true
101
+ git solo jd
102
+ ```
103
+
104
+ ``` bash
105
+ GIT_DUET_GLOBAL=true git duet jd fb
106
+ ```
107
+
108
+ You can also set it to `false` to always operate on the local config, even if
109
+ the global flag is used.
110
+
96
111
  ### Email Configuration
97
112
 
98
113
  By default, email addresses are constructed from the first initial and
@@ -134,7 +149,7 @@ key, and `username` which is the part following `;` in the author value.
134
149
  pairs:
135
150
  jd: Jane Doe
136
151
  fb: Frances Bar
137
- email_template: '<%= "#{author.gsub(/ /, "-").downcase}@hamster.local" =%>'
152
+ email_template: '<%= "#{author.gsub(/ /, "-").downcase}@hamster.local" %>'
138
153
  ```
139
154
 
140
155
  After invoking:
@@ -286,6 +301,11 @@ github](https://github.com/meatballhat/git-duet/issues/new).
286
301
 
287
302
  1. Fork it
288
303
  2. Create your feature branch (`git checkout -b my-new-feature`)
289
- 3. Commit your changes (`git dci -am 'Added some feature'`)
290
- 4. Push to the branch (`git push origin my-new-feature`)
291
- 5. Create new Pull Request
304
+ 3. Implement!
305
+ 4. Run the tests
306
+ 1. RSpec `bundle exec rake spec`
307
+ 2. Rubocop `bundle exec rake rubocop`
308
+ 3. [Bats](https://github.com/sstephenson/bats) `bundle exec rake install && bundle exec bats test` (if you have added new files, `git add` them before installing)
309
+ 5. Commit your changes (`git dci -am 'Added some feature'`)
310
+ 6. Push to the branch (`git push origin my-new-feature`)
311
+ 7. Create new Pull Request
@@ -22,10 +22,10 @@ Gem::Specification.new do |gem|
22
22
  gem.license = 'MIT'
23
23
 
24
24
  gem.files = `git ls-files -z`.split("\x00")
25
- gem.executables = gem.files.grep(/^bin\//)
26
- .map { |f| File.basename(f) }
27
- .reject { |n| n =~ /rubymine-git-wrapper/ }
28
- gem.test_files = gem.files.grep(/^spec\//)
25
+ gem.executables = gem.files.grep(%r{^bin/})
26
+ .map { |f| File.basename(f) }
27
+ .reject { |n| n =~ /rubymine-git-wrapper/ }
28
+ gem.test_files = gem.files.grep(%r{^spec/})
29
29
  gem.name = 'git-duet'
30
30
  gem.require_paths = %w(lib)
31
31
  gem.version = Git::Duet::VERSION
@@ -10,10 +10,10 @@ module Git
10
10
 
11
11
  def initialize(authors_file = nil, email_lookup = nil)
12
12
  @authors_file = authors_file ||
13
- ENV['GIT_DUET_AUTHORS_FILE'] ||
14
- File.join(ENV['HOME'], '.git-authors')
13
+ ENV['GIT_DUET_AUTHORS_FILE'] ||
14
+ File.join(ENV['HOME'], '.git-authors')
15
15
  @email_lookup = email_lookup ||
16
- ENV['GIT_DUET_EMAIL_LOOKUP_COMMAND']
16
+ ENV['GIT_DUET_EMAIL_LOOKUP_COMMAND']
17
17
  end
18
18
 
19
19
  def map(*initials_list)
@@ -1,6 +1,7 @@
1
1
  # vim:fileencoding=utf-8
2
2
  require 'optparse'
3
3
  require 'git/duet'
4
+ require 'git/duet/cli_options'
4
5
  require 'git/duet/script_die_error'
5
6
 
6
7
  module Git
@@ -8,9 +9,7 @@ module Git
8
9
  class Cli
9
10
  class << self
10
11
  def run(prog, argv)
11
- method_name = File.basename(prog)
12
- .sub(/^git-duet-/, '').sub(/^git-/, '').tr('-', '_')
13
- send(method_name, parse_options(method_name, argv.clone))
12
+ invoke(File.basename(prog), argv.clone, ENV)
14
13
  0
15
14
  rescue NoMethodError
16
15
  raise ScriptError, 'How did you get here???'
@@ -20,67 +19,26 @@ module Git
20
19
 
21
20
  private
22
21
 
23
- def parse_options(method_name, argv)
24
- case method_name
25
- when 'pre_commit', 'install_hook'
26
- parse_generic_options(argv)
27
- else
28
- send("parse_#{method_name}_options", argv)
22
+ def invoke(prog_name, args, environment)
23
+ method_name = prog_name
24
+ .sub(/^git-duet-/, '')
25
+ .sub(/^git-/, '')
26
+ .tr('-', '_')
27
+ options = CliOptions.parse_options(method_name, args)
28
+ if environment['GIT_DUET_GLOBAL']
29
+ options[:global] = parse_boolean(environment['GIT_DUET_GLOBAL'])
29
30
  end
31
+ send(method_name, options)
30
32
  end
31
33
 
32
- def with_common_opts(argv, banner)
33
- options = {}
34
- leftover_argv = OptionParser.new do |opts|
35
- opts.banner = banner.gsub(/__PROG__/, opts.program_name)
36
- opts.on('-q', 'Silence output') do |_|
37
- options[:quiet] = true
38
- end
39
- yield opts, options if block_given?
40
- end.parse!(argv)
41
- [leftover_argv, options]
42
- end
43
-
44
- def parse_solo_options(argv)
45
- parse_options_with_positional_args(
46
- argv, '<soloist-initials>') do |leftover_argv, options|
47
- options[:soloist] = leftover_argv.first
48
- end
49
- end
50
-
51
- def parse_duet_options(argv)
52
- parse_options_with_positional_args(
53
- argv,
54
- '<alpha-initials> <omega-initials>'
55
- ) do |leftover_argv, options|
56
- options[:alpha], options[:omega] = leftover_argv[0..1]
34
+ def parse_boolean(s)
35
+ case s
36
+ when 'true' then true
37
+ when 'false' then false
38
+ else fail ArgumentError, "must be 'true' or 'false': #{s}"
57
39
  end
58
40
  end
59
41
 
60
- def parse_options_with_positional_args(argv, usage)
61
- leftover_argv, options = with_common_opts(
62
- argv, 'Usage: __PROG__ [options] ' << usage
63
- ) do |opts, options_hash|
64
- opts.on('-g', '--global', 'Change global git config') do |_|
65
- options_hash[:global] = true
66
- end
67
- end
68
- yield leftover_argv, options
69
- options
70
- end
71
-
72
- def parse_generic_options(argv)
73
- with_common_opts(argv, 'Usage: __PROG__').last
74
- end
75
-
76
- def parse_commit_options(argv)
77
- opts_argv = []
78
- opts_argv << '-q' if argv.delete('-q')
79
- options = with_common_opts(opts_argv, 'Usage: __PROG__').last
80
- options[:passthrough_args] = argv
81
- options
82
- end
83
-
84
42
  def solo(options)
85
43
  require 'git/duet/solo_command'
86
44
  Git::Duet::SoloCommand.new(
@@ -0,0 +1,70 @@
1
+ module Git
2
+ module Duet
3
+ class CliOptions
4
+ class << self
5
+ def parse_options(method_name, argv)
6
+ case method_name
7
+ when 'pre_commit', 'install_hook'
8
+ parse_generic_options(argv)
9
+ else
10
+ send("parse_#{method_name}_options", argv)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def with_common_opts(argv, banner)
17
+ options = {}
18
+ leftover_argv = OptionParser.new do |opts|
19
+ opts.banner = banner.gsub(/__PROG__/, opts.program_name)
20
+ opts.on('-q', 'Silence output') do |_|
21
+ options[:quiet] = true
22
+ end
23
+ yield opts, options if block_given?
24
+ end.parse!(argv)
25
+ [leftover_argv, options]
26
+ end
27
+
28
+ def parse_solo_options(argv)
29
+ parse_options_with_positional_args(
30
+ argv, '<soloist-initials>') do |leftover_argv, options|
31
+ options[:soloist] = leftover_argv.first
32
+ end
33
+ end
34
+
35
+ def parse_duet_options(argv)
36
+ parse_options_with_positional_args(
37
+ argv,
38
+ '<alpha-initials> <omega-initials>'
39
+ ) do |leftover_argv, options|
40
+ options[:alpha], options[:omega] = leftover_argv[0..1]
41
+ end
42
+ end
43
+
44
+ def parse_options_with_positional_args(argv, usage)
45
+ leftover_argv, options = with_common_opts(
46
+ argv, 'Usage: __PROG__ [options] ' << usage
47
+ ) do |opts, options_hash|
48
+ opts.on('-g', '--global', 'Change global git config') do |_|
49
+ options_hash[:global] = true
50
+ end
51
+ end
52
+ yield leftover_argv, options
53
+ options
54
+ end
55
+
56
+ def parse_generic_options(argv)
57
+ with_common_opts(argv, 'Usage: __PROG__').last
58
+ end
59
+
60
+ def parse_commit_options(argv)
61
+ opts_argv = []
62
+ opts_argv << '-q' if argv.delete('-q')
63
+ options = with_common_opts(opts_argv, 'Usage: __PROG__').last
64
+ options[:passthrough_args] = argv
65
+ options
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -9,7 +9,8 @@ module Git
9
9
  include Git::Duet::CommandMethods
10
10
 
11
11
  def initialize(alpha, omega, quiet = false, global = false)
12
- @alpha, @omega = alpha, omega
12
+ @alpha = alpha
13
+ @omega = omega
13
14
  @quiet = !!quiet
14
15
  @global = !!global
15
16
  @author_mapper = Git::Duet::AuthorMapper.new
@@ -3,7 +3,7 @@
3
3
  unless defined?(Git::Duet::VERSION)
4
4
  module Git
5
5
  module Duet
6
- VERSION = '0.5.0'
6
+ VERSION = '0.5.1'
7
7
  end
8
8
  end
9
9
  end
@@ -26,7 +26,7 @@ describe Git::Duet::AuthorMapper do
26
26
 
27
27
  it 'uses an authors file given at initialization' do
28
28
  instance = described_class
29
- .new('/blarggie/blarggie/new/friend/.git-authors')
29
+ .new('/blarggie/blarggie/new/friend/.git-authors')
30
30
  expect(instance.authors_file)
31
31
  .to eq('/blarggie/blarggie/new/friend/.git-authors')
32
32
  end
@@ -44,4 +44,48 @@ describe Git::Duet::Cli do
44
44
  )
45
45
  cli.run('git-duet-pre-commit', %w(-q))
46
46
  end
47
+
48
+ it 'defaults to loud and local when running `solo`' do
49
+ allow(Git::Duet::SoloCommand)
50
+ .to receive(:new).with('jd', be_falsey, be_falsey)
51
+ .and_return(double('solo').as_null_object)
52
+ cli.run('git-solo', %w(jd))
53
+ end
54
+
55
+ it 'parses options for quietness and globality when running `solo`' do
56
+ allow(Git::Duet::SoloCommand)
57
+ .to receive(:new).with('jd', be_truthy, be_truthy)
58
+ .and_return(double('solo').as_null_object)
59
+ cli.run('git-solo', %w(jd -q -g))
60
+ end
61
+
62
+ it 'defaults to loud and local when running `duet`' do
63
+ allow(Git::Duet::DuetCommand)
64
+ .to receive(:new).with('jd', 'fb', be_falsey, be_falsey)
65
+ .and_return(double('duet').as_null_object)
66
+ cli.run('git-duet', %w(jd fb))
67
+ end
68
+
69
+ it 'parses options for quietness and globality when running `duet`' do
70
+ allow(Git::Duet::DuetCommand)
71
+ .to receive(:new).with('jd', 'fb', be_truthy, be_truthy)
72
+ .and_return(double('duet').as_null_object)
73
+ cli.run('git-duet', %w(jd fb -q -g))
74
+ end
75
+
76
+ it 'respects the environment about global issues when running `solo`' do
77
+ stub_const('ENV', 'GIT_DUET_GLOBAL' => 'true')
78
+ allow(Git::Duet::SoloCommand)
79
+ .to receive(:new).with('cp', anything, be_truthy)
80
+ .and_return(double('solo').as_null_object)
81
+ cli.run('git-solo', %w(cp))
82
+ end
83
+
84
+ it 'respects the environment about global issues when running `duet`' do
85
+ stub_const('ENV', 'GIT_DUET_GLOBAL' => 'true')
86
+ allow(Git::Duet::DuetCommand)
87
+ .to receive(:new).with('cp', 'g', anything, be_truthy)
88
+ .and_return(double('duet').as_null_object)
89
+ cli.run('git-duet', %w(cp g))
90
+ end
47
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-duet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Buch
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-10-07 00:00:00.000000000 Z
14
+ date: 2015-05-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -116,6 +116,7 @@ files:
116
116
  - ".jrubyrc"
117
117
  - ".rspec"
118
118
  - ".rubocop.yml"
119
+ - ".rubocop_todo.yml"
119
120
  - ".ruby-version"
120
121
  - ".simplecov"
121
122
  - ".travis.yml"
@@ -135,6 +136,7 @@ files:
135
136
  - lib/git/duet.rb
136
137
  - lib/git/duet/author_mapper.rb
137
138
  - lib/git/duet/cli.rb
139
+ - lib/git/duet/cli_options.rb
138
140
  - lib/git/duet/command_methods.rb
139
141
  - lib/git/duet/commit_command.rb
140
142
  - lib/git/duet/config.rb