git-duet 0.1.3 → 0.2.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,11 @@
1
+ # vim:fileencoding=utf-8
2
+
3
+ module Git
4
+ module Duet
5
+ class Config
6
+ def self.namespace
7
+ ENV['GIT_DUET_CONFIG_NAMESPACE'] || 'duet.env'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,4 @@
1
+ # vim:fileencoding=utf-8
1
2
  require 'git/duet'
2
3
  require 'git/duet/author_mapper'
3
4
  require 'git/duet/command_methods'
@@ -13,17 +14,22 @@ class Git::Duet::DuetCommand
13
14
  end
14
15
 
15
16
  def execute!
16
- set_alpha_as_git_config_user
17
- report_env_vars
18
- write_env_vars
17
+ if alpha && omega
18
+ set_alpha_as_git_config_user
19
+ report_env_vars
20
+ write_env_vars
21
+ else
22
+ show_current_config
23
+ end
19
24
  end
20
25
 
21
26
  private
27
+
22
28
  attr_accessor :alpha, :omega, :author_mapper
23
29
 
24
30
  def set_alpha_as_git_config_user
25
- exec_check("git config #{@global ? '--global ' : ''}user.name '#{alpha_info[:name]}'")
26
- exec_check("git config #{@global ? '--global ' : ''}user.email '#{alpha_info[:email]}'")
31
+ exec_check("#{git_config} user.name '#{alpha_info[:name]}'")
32
+ exec_check("#{git_config} user.email '#{alpha_info[:email]}'")
27
33
  end
28
34
 
29
35
  def var_map
@@ -1,3 +1,4 @@
1
+ # vim:fileencoding=utf-8
1
2
  require 'git/duet'
2
3
  require 'fileutils'
3
4
  require 'git/duet/command_methods'
@@ -5,7 +6,7 @@ require 'git/duet/command_methods'
5
6
  class Git::Duet::InstallHookCommand
6
7
  include Git::Duet::CommandMethods
7
8
 
8
- HOOK = <<-EOF.gsub(/^ /, '')
9
+ HOOK = <<-EOF.gsub(/^ {2}/, '')
9
10
  #!/bin/bash
10
11
  exec git duet-pre-commit "$@"
11
12
  EOF
@@ -17,17 +18,20 @@ class Git::Duet::InstallHookCommand
17
18
  def execute!
18
19
  Dir.chdir(`git rev-parse --show-toplevel`.chomp) do
19
20
  dest = File.join(Dir.pwd, '.git', 'hooks', 'pre-commit')
20
- if File.exist?(dest)
21
- error("git-duet-install-hook: A pre-commit hook already exists at #{dest}!")
22
- error("git-duet-install-hook: Move it out of the way first, mkay?")
23
- return 1
24
- end
25
- File.open(dest, 'w') do |f|
26
- f.puts HOOK
27
- end
21
+ return error_hook_exists(dest) if File.exist?(dest)
22
+ File.open(dest, 'w') { |f| f.puts HOOK }
28
23
  FileUtils.chmod(0755, dest)
29
24
  info("git-duet-install-hook: Installed hook to #{dest}")
30
25
  end
31
- return 0
26
+ 0
27
+ end
28
+
29
+ private
30
+
31
+ def error_hook_exists(dest)
32
+ error('git-duet-install-hook: ' <<
33
+ "A pre-commit hook already exists at #{dest}!")
34
+ error('git-duet-install-hook: Move it out of the way first, mkay?')
35
+ 1
32
36
  end
33
37
  end
@@ -1,3 +1,4 @@
1
+ # vim:fileencoding=utf-8
1
2
  require 'git/duet'
2
3
  require 'git/duet/command_methods'
3
4
  require 'git/duet/script_die_error'
@@ -11,22 +12,21 @@ class Git::Duet::PreCommitCommand
11
12
 
12
13
  def execute!
13
14
  in_repo_root do
14
- if !env_cache_exists? || env_cache_stale?
15
- explode!
16
- end
15
+ explode! if !env_cache_exists? || env_cache_stale?
17
16
  end
18
17
  end
19
18
 
20
19
  private
20
+
21
21
  def explode!
22
- error("Your git duet settings are stale, human!")
23
- error("Update them with `git duet` or `git solo`.")
22
+ error('Your git duet settings are stale, human!')
23
+ error('Update them with `git duet` or `git solo`.')
24
24
  raise Git::Duet::ScriptDieError.new(1)
25
25
  end
26
26
 
27
27
  def env_cache_exists?
28
28
  with_output_quieted do
29
- exec_check('git config duet.env.mtime')
29
+ exec_check("git config #{Git::Duet::Config.namespace}.mtime")
30
30
  end
31
31
  true
32
32
  rescue
@@ -34,10 +34,13 @@ class Git::Duet::PreCommitCommand
34
34
  end
35
35
 
36
36
  def env_cache_stale?
37
- Integer(exec_check('git config duet.env.mtime')) < stale_cutoff
37
+ Integer(exec_check("git config #{Git::Duet::Config.namespace}.mtime")) <
38
+ stale_cutoff
38
39
  end
39
40
 
40
41
  def stale_cutoff
41
- Integer(Time.now - Integer(ENV.fetch('GIT_DUET_SECONDS_AGO_STALE', '1200')))
42
+ Integer(
43
+ Time.now - Integer(ENV.fetch('GIT_DUET_SECONDS_AGO_STALE', '1200'))
44
+ )
42
45
  end
43
46
  end
@@ -1,3 +1,5 @@
1
+ # vim:fileencoding=utf-8
2
+
1
3
  module Git
2
4
  module Duet
3
5
  class ScriptDieError < StandardError
@@ -1,3 +1,4 @@
1
+ # vim:fileencoding=utf-8
1
2
  require 'git/duet'
2
3
  require 'git/duet/author_mapper'
3
4
  require 'git/duet/command_methods'
@@ -13,23 +14,36 @@ class Git::Duet::SoloCommand
13
14
  end
14
15
 
15
16
  def execute!
16
- set_soloist_as_git_config_user
17
17
  unset_committer_vars
18
- report_env_vars
19
- write_env_vars
18
+ if soloist
19
+ set_soloist_as_git_config_user
20
+ report_env_vars
21
+ write_env_vars
22
+ else
23
+ show_current_config
24
+ end
20
25
  end
21
26
 
22
27
  private
28
+
23
29
  attr_accessor :soloist, :author_mapper
24
30
 
25
31
  def set_soloist_as_git_config_user
26
- exec_check("git config #{@global ? '--global ' : ''}user.name '#{soloist_info[:name]}'")
27
- exec_check("git config #{@global ? '--global ' : ''}user.email '#{soloist_info[:email]}'")
32
+ exec_check("#{git_config} user.name '#{soloist_info[:name]}'")
33
+ exec_check("#{git_config} user.email '#{soloist_info[:email]}'")
28
34
  end
29
35
 
30
36
  def unset_committer_vars
31
- exec_check("git config #{@global ? '--global ' : ''}--unset-all duet.env.git-committer-name", [0, 5])
32
- exec_check("git config #{@global ? '--global ' : ''}--unset-all duet.env.git-committer-email", [0, 5])
37
+ exec_check(
38
+ "#{git_config} --unset-all #{Git::Duet::Config.namespace}." <<
39
+ 'git-committer-name',
40
+ [0, 5]
41
+ )
42
+ exec_check(
43
+ "#{git_config} --unset-all #{Git::Duet::Config.namespace}." <<
44
+ 'git-committer-email',
45
+ [0, 5]
46
+ )
33
47
  end
34
48
 
35
49
  def var_map
@@ -1,7 +1,9 @@
1
+ # vim:fileencoding=utf-8
2
+
1
3
  unless defined?(Git::Duet::VERSION)
2
4
  module Git
3
5
  module Duet
4
- VERSION = '0.1.3'
6
+ VERSION = '0.2.0'
5
7
  end
6
8
  end
7
9
  end
@@ -1,6 +1,7 @@
1
+ # vim:fileencoding=utf-8
1
2
  require 'tmpdir'
2
3
 
3
- describe 'git-duet end to end', :integration => true do
4
+ describe 'git-duet end to end', integration: true do
4
5
  EMAIL_LOOKUP_SCRIPT = <<-EOF.gsub(/^ /, '')
5
6
  #!/usr/bin/env ruby
6
7
  addr = {
@@ -21,11 +22,12 @@ describe 'git-duet end to end', :integration => true do
21
22
 
22
23
  def make_an_edit
23
24
  Dir.chdir(@repo_dir)
24
- File.open('file.txt', 'w') { |f| f.puts "foo-#{rand(100000)}" }
25
+ File.open('file.txt', 'w') { |f| f.puts "foo-#{rand(100_000)}" }
25
26
  `git add file.txt`
26
27
  end
27
28
 
28
29
  before :all do
30
+ ENV['GIT_DUET_CONFIG_NAMESPACE'] = 'foo.bar'
29
31
  @startdir = Dir.pwd
30
32
  @tmpdir = Dir.mktmpdir('git-duet-specs')
31
33
  @git_authors = File.join(@tmpdir, '.git-authors')
@@ -46,7 +48,8 @@ describe 'git-duet end to end', :integration => true do
46
48
  )
47
49
  end
48
50
  ENV['GIT_DUET_AUTHORS_FILE'] = @git_authors
49
- ENV['PATH'] = "#{File.expand_path('../../../bin', __FILE__)}:#{ENV['PATH']}"
51
+ top_bin = File.expand_path('../../../bin', __FILE__)
52
+ ENV['PATH'] = "#{top_bin}:#{ENV['PATH']}"
50
53
  File.open(@email_lookup_path, 'w') { |f| f.puts EMAIL_LOOKUP_SCRIPT }
51
54
  FileUtils.chmod(0755, @email_lookup_path)
52
55
  @repo_dir = File.join(@tmpdir, 'foo')
@@ -57,7 +60,9 @@ describe 'git-duet end to end', :integration => true do
57
60
  after :all do
58
61
  Dir.chdir(@startdir)
59
62
  if ENV['RSPEC_NO_CLEANUP']
60
- File.open('integration-end-to-end-test-dir.txt', 'w') { |f| f.puts @tmpdir }
63
+ File.open('integration-end-to-end-test-dir.txt', 'w') do |f|
64
+ f.puts @tmpdir
65
+ end
61
66
  else
62
67
  FileUtils.rm_rf(@tmpdir)
63
68
  end
@@ -67,11 +72,11 @@ describe 'git-duet end to end', :integration => true do
67
72
  before(:each) { install_hook }
68
73
  after(:each) { uninstall_hook }
69
74
 
70
- it 'should write the hook to the `pre-commit` hook file' do
75
+ it 'writes the hook to the `pre-commit` hook file' do
71
76
  File.exist?('.git/hooks/pre-commit').should be_true
72
77
  end
73
78
 
74
- it 'should make the `pre-commit` hook file executable' do
79
+ it 'makes the `pre-commit` hook file executable' do
75
80
  File.executable?('.git/hooks/pre-commit').should be_true
76
81
  end
77
82
  end
@@ -82,24 +87,25 @@ describe 'git-duet end to end', :integration => true do
82
87
  `git solo jd -q`
83
88
  end
84
89
 
85
- it 'should set the git user name' do
90
+ it 'sets the git user name' do
86
91
  `git config user.name`.chomp.should == 'Jane Doe'
87
92
  end
88
93
 
89
- it 'should set the git user email' do
94
+ it 'sets the git user email' do
90
95
  `git config user.email`.chomp.should == 'jane@hamsters.biz.local'
91
96
  end
92
97
 
93
- it 'should cache the git user name as author name' do
94
- `git config duet.env.git-author-name`.chomp.should == 'Jane Doe'
98
+ it 'caches the git user name as author name' do
99
+ `git config #{Git::Duet::Config.namespace}.git-author-name`.chomp
100
+ .should == 'Jane Doe'
95
101
  end
96
102
 
97
- it 'should cache the git user email as author email' do
98
- `git config duet.env.git-author-email`.chomp.should == 'jane@hamsters.biz.local'
103
+ it 'caches the git user email as author email' do
104
+ `git config #{Git::Duet::Config.namespace}.git-author-email`.chomp
105
+ .should == 'jane@hamsters.biz.local'
99
106
  end
100
107
  end
101
108
 
102
-
103
109
  context 'when an external email lookup is provided' do
104
110
  before :each do
105
111
  @old_email_lookup = ENV.delete('GIT_DUET_EMAIL_LOOKUP_COMMAND')
@@ -116,8 +122,9 @@ describe 'git-duet end to end', :integration => true do
116
122
  `git solo jd -q`
117
123
  end
118
124
 
119
- it 'should set the author email address given by the external email lookup' do
120
- `git config duet.env.git-author-email`.chomp.should == 'jane_doe@lookie.me.local'
125
+ it 'sets the author email given by the external email lookup' do
126
+ `git config #{Git::Duet::Config.namespace}.git-author-email`.chomp
127
+ .should == 'jane_doe@lookie.me.local'
121
128
  end
122
129
  end
123
130
 
@@ -127,12 +134,14 @@ describe 'git-duet end to end', :integration => true do
127
134
  `git duet jd fb -q`
128
135
  end
129
136
 
130
- it 'should set the author email address given by the external email lookup' do
131
- `git config duet.env.git-author-email`.chomp.should == 'jane_doe@lookie.me.local'
137
+ it 'sets the author email given by the external email lookup' do
138
+ `git config #{Git::Duet::Config.namespace}.git-author-email`.chomp
139
+ .should == 'jane_doe@lookie.me.local'
132
140
  end
133
141
 
134
- it 'should set the committer email address given by the external email lookup' do
135
- `git config duet.env.git-committer-email`.chomp.should == 'fb9000@dalek.info.local'
142
+ it 'sets the committer email given by the external email lookup' do
143
+ `git config #{Git::Duet::Config.namespace}.git-committer-email`.chomp
144
+ .should == 'fb9000@dalek.info.local'
136
145
  end
137
146
  end
138
147
  end
@@ -143,7 +152,8 @@ describe 'git-duet end to end', :integration => true do
143
152
  @name_suffix = rand(9999)
144
153
  authors_cfg['email_template'] =
145
154
  %Q^<%= '' << author.split.first.downcase << ^ <<
146
- %Q^author.split.last[0].chr.downcase << '#{@name_suffix}@mompopshop.local' %>^
155
+ %Q^author.split.last[0].chr.downcase << ^ <<
156
+ %Q^'#{@name_suffix}@mompopshop.local' %>^
147
157
  File.open(@git_authors, 'w') do |f|
148
158
  f.puts YAML.dump(authors_cfg)
149
159
  end
@@ -164,14 +174,16 @@ describe 'git-duet end to end', :integration => true do
164
174
  make_an_edit
165
175
  end
166
176
 
167
- it 'should use the email template to construct the author email' do
177
+ it 'uses the email template to construct the author email' do
168
178
  `git duet-commit -q -m 'Testing custom email template for author'`
169
- `git log -1 --format='%an <%ae>'`.chomp.should == "Zubaz Pants <zubazp#{@name_suffix}@mompopshop.local>"
179
+ `git log -1 --format='%an <%ae>'`.chomp
180
+ .should == "Zubaz Pants <zubazp#{@name_suffix}@mompopshop.local>"
170
181
  end
171
182
 
172
- it 'should use the email template to construct the committer email' do
183
+ it 'uses the email template to construct the committer email' do
173
184
  `git duet-commit -q -m 'Testing custom email template for committer'`
174
- `git log -1 --format='%cn <%ce>'`.chomp.should == "Zubaz Pants <zubazp#{@name_suffix}@mompopshop.local>"
185
+ `git log -1 --format='%cn <%ce>'`.chomp
186
+ .should == "Zubaz Pants <zubazp#{@name_suffix}@mompopshop.local>"
175
187
  end
176
188
  end
177
189
 
@@ -182,14 +194,16 @@ describe 'git-duet end to end', :integration => true do
182
194
  make_an_edit
183
195
  end
184
196
 
185
- it 'should use the email template to construct the author email' do
197
+ it 'uses the email template to construct the author email' do
186
198
  `git duet-commit -q -m 'Testing custom email template for author'`
187
- `git log -1 --format='%an <%ae>'`.chomp.should == "Zubaz Pants <zubazp#{@name_suffix}@mompopshop.local>"
199
+ `git log -1 --format='%an <%ae>'`.chomp
200
+ .should == "Zubaz Pants <zubazp#{@name_suffix}@mompopshop.local>"
188
201
  end
189
202
 
190
- it 'should use the email template to construct the committer email' do
203
+ it 'uses the email template to construct the committer email' do
191
204
  `git duet-commit -q -m 'Testing custom email template for committer'`
192
- `git log -1 --format='%cn <%ce>'`.chomp.should == "Frances Bar <francesb#{@name_suffix}@mompopshop.local>"
205
+ `git log -1 --format='%cn <%ce>'`.chomp
206
+ .should == "Frances Bar <francesb#{@name_suffix}@mompopshop.local>"
193
207
  end
194
208
  end
195
209
  end
@@ -200,20 +214,22 @@ describe 'git-duet end to end', :integration => true do
200
214
  `git duet jd fb -q`
201
215
  end
202
216
 
203
- it 'should set the git user name' do
217
+ it 'sets the git user name' do
204
218
  `git config user.name`.chomp.should == 'Jane Doe'
205
219
  end
206
220
 
207
- it 'should set the git user email' do
221
+ it 'sets the git user email' do
208
222
  `git config user.email`.chomp.should == 'jane@hamsters.biz.local'
209
223
  end
210
224
 
211
- it 'should cache the git committer name' do
212
- `git config duet.env.git-committer-name`.chomp.should == 'Frances Bar'
225
+ it 'caches the git committer name' do
226
+ `git config #{Git::Duet::Config.namespace}.git-committer-name`.chomp
227
+ .should == 'Frances Bar'
213
228
  end
214
229
 
215
- it 'should cache the git committer email' do
216
- `git config duet.env.git-committer-email`.chomp.should == 'f.bar@hamster.info.local'
230
+ it 'caches the git committer email' do
231
+ `git config #{Git::Duet::Config.namespace}.git-committer-email`.chomp
232
+ .should == 'f.bar@hamster.info.local'
217
233
  end
218
234
  end
219
235
 
@@ -225,33 +241,35 @@ describe 'git-duet end to end', :integration => true do
225
241
  make_an_edit
226
242
  end
227
243
 
228
- it 'should list the alpha of the duet as author in the log' do
244
+ it 'lists the alpha of the duet as author in the log' do
229
245
  `git duet-commit -q -m 'Testing set of alpha as author'`
230
- `git log -1 --format='%an <%ae>'`.chomp.should == 'Jane Doe <jane@hamsters.biz.local>'
246
+ `git log -1 --format='%an <%ae>'`.chomp
247
+ .should == 'Jane Doe <jane@hamsters.biz.local>'
231
248
  end
232
249
 
233
- it 'should list the omega of the duet as committer in the log' do
250
+ it 'lists the omega of the duet as committer in the log' do
234
251
  `git duet-commit -q -m 'Testing set of omega as committer'`
235
- `git log -1 --format='%cn <%ce>'`.chomp.should == 'Frances Bar <f.bar@hamster.info.local>'
252
+ `git log -1 --format='%cn <%ce>'`.chomp
253
+ .should == 'Frances Bar <f.bar@hamster.info.local>'
236
254
  end
237
255
 
238
256
  context 'when no author has been set' do
239
257
  before do
240
258
  Dir.chdir(@repo_dir)
241
259
  %w(git-author-email git-author-name).each do |config|
242
- `git config --unset duet.env.#{config}`
260
+ `git config --unset #{Git::Duet::Config.namespace}.#{config}`
243
261
  end
244
262
  make_an_edit
245
263
  end
246
264
 
247
- it 'should raise an error if committed without the -q option' do
265
+ it 'raises an error if committed without the -q option' do
248
266
  `git duet-commit -q -m 'Testing commit with no author'`
249
- $?.to_i.should_not == 0
267
+ $CHILD_STATUS.to_i.should_not == 0
250
268
  end
251
269
 
252
- it 'should fail to add a commit' do
253
- expect{ `git duet-commit -q -m 'testing commit with no author'` }.
254
- to_not change{ `git log -1 --format=%H`.chomp }
270
+ it 'fails to add a commit' do
271
+ expect { `git duet-commit -q -m 'testing commit with no author'` }
272
+ .to_not change { `git log -1 --format=%H`.chomp }
255
273
  end
256
274
  end
257
275
 
@@ -261,7 +279,7 @@ describe 'git-duet end to end', :integration => true do
261
279
  @latest_sha1 = `git log -1 --format=%H`.chomp
262
280
  make_an_edit
263
281
  install_hook
264
- `git config --unset-all duet.env.mtime`
282
+ `git config --unset-all #{Git::Duet::Config.namespace}.mtime`
265
283
  ENV['GIT_DUET_QUIET'] = '1'
266
284
  end
267
285
 
@@ -270,7 +288,7 @@ describe 'git-duet end to end', :integration => true do
270
288
  ENV.delete('GIT_DUET_QUIET')
271
289
  end
272
290
 
273
- it 'should fire the hook and reject the commit' do
291
+ it 'fires the hook and reject the commit' do
274
292
  `git duet-commit -q -m 'Testing hook firing'`
275
293
  `git log -1 --format=%H`.chomp.should == @latest_sha1
276
294
  end
@@ -284,18 +302,20 @@ describe 'git-duet end to end', :integration => true do
284
302
  make_an_edit
285
303
  end
286
304
 
287
- it 'should list the soloist as author in the log' do
305
+ it 'lists the soloist as author in the log' do
288
306
  `git duet-commit -m 'Testing set of soloist as author' 2>/dev/null`
289
- `git log -1 --format='%an <%ae>'`.chomp.should == 'Jane Doe <jane@hamsters.biz.local>'
307
+ `git log -1 --format='%an <%ae>'`.chomp
308
+ .should == 'Jane Doe <jane@hamsters.biz.local>'
290
309
  end
291
310
 
292
- it 'should list the soloist as committer in the log' do
311
+ it 'lists the soloist as committer in the log' do
293
312
  `git duet-commit -m 'Testing set of soloist as committer' 2>/dev/null`
294
- `git log -1 --format='%cn <%ce>'`.chomp.should == 'Jane Doe <jane@hamsters.biz.local>'
313
+ `git log -1 --format='%cn <%ce>'`.chomp
314
+ .should == 'Jane Doe <jane@hamsters.biz.local>'
295
315
  end
296
316
 
297
- it 'should not include "Signed-off-by" in the commit message' do
298
- `git duet-commit -m 'Testing ommitting signoff when only one author' 2>/dev/null`
317
+ it 'does not include "Signed-off-by" in the commit message' do
318
+ `git duet-commit -m 'Testing omitting signoff' 2>/dev/null`
299
319
  `grep 'Signed-off-by' .git/COMMIT_EDITMSG`.chomp.should == ''
300
320
  end
301
321
 
@@ -305,7 +325,7 @@ describe 'git-duet end to end', :integration => true do
305
325
  @latest_sha1 = `git log -1 --format=%H`.chomp
306
326
  make_an_edit
307
327
  install_hook
308
- `git config --unset-all duet.env.mtime`
328
+ `git config --unset-all #{Git::Duet::Config.namespace}.mtime`
309
329
  ENV['GIT_DUET_QUIET'] = '1'
310
330
  end
311
331
 
@@ -314,7 +334,7 @@ describe 'git-duet end to end', :integration => true do
314
334
  ENV.delete('GIT_DUET_QUIET')
315
335
  end
316
336
 
317
- it 'should fire the hook and reject the commit' do
337
+ it 'fires the hook and reject the commit' do
318
338
  `git duet-commit -q -m 'Testing hook firing'`
319
339
  `git log -1 --format=%H`.chomp.should == @latest_sha1
320
340
  end