confgit 0.0.3

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,466 @@
1
+ # coding: UTF-8
2
+
3
+ require File.expand_path('../spec_helper', __FILE__)
4
+ require 'confgit'
5
+
6
+
7
+ describe Confgit do
8
+ # 引数の最後が Hash ならオプションとして取出す
9
+ def arg_last_options(args)
10
+ if args.last && args.last.kind_of?(Hash)
11
+ args.pop
12
+ else
13
+ {}
14
+ end
15
+ end
16
+
17
+ # Confgit.run を呼出す
18
+ def confgit(*argv)
19
+ begin
20
+ options = {:interactive => false}
21
+ options.merge!(arg_last_options(argv))
22
+
23
+ Confgit.run(argv, options)
24
+ rescue SystemExit => err
25
+ @abort = err.inspect
26
+ end
27
+ end
28
+
29
+ # カレントディレクトリとルートを変更する
30
+ def chroot(*args)
31
+ options = arg_last_options(args)
32
+
33
+ root = options[:root]
34
+ root ||= ENV['HOME']
35
+
36
+ Dir.chdir(root) { |path|
37
+ confgit 'root', path
38
+
39
+ args.each { |file|
40
+ dir = File.dirname(file)
41
+ FileUtils.mkpath(dir) unless dir == '.'
42
+
43
+ open(file, 'w') { |f|
44
+ f.puts options[:data] if options[:data]
45
+ }
46
+ }
47
+
48
+ yield(path, *args)
49
+ }
50
+ end
51
+
52
+ # ファイルの変更を行うために現在の内容を記録する
53
+ def modfile(*args)
54
+ options = arg_last_options(args)
55
+
56
+ prevs = args.collect { |item| open(item).read }
57
+ yield(*prevs)
58
+
59
+ prevs
60
+ end
61
+
62
+ before do
63
+ require 'tmpdir'
64
+
65
+ @hostname = `hostname`.chop
66
+ @home = ENV['HOME']
67
+ ENV['HOME'] = @tmpdir = Dir.mktmpdir
68
+ end
69
+
70
+ describe "repo" do
71
+ it "repo" do
72
+ proc { confgit 'repo' }.must_output "* #{@hostname}\n"
73
+ end
74
+
75
+ it "repo REPO" do
76
+ name = '_foo_'
77
+ proc {
78
+ confgit 'repo', name
79
+ confgit 'repo'
80
+ }.must_output <<-EOD.gsub(/^\t+/,'')
81
+ * #{name}
82
+ #{@hostname}
83
+ EOD
84
+ end
85
+
86
+ it "repo -d REPO (not current)" do
87
+ name1 = '_foo_'
88
+ name2 = '_bar_'
89
+ proc {
90
+ confgit 'repo', name1
91
+ confgit 'repo', name2
92
+ confgit 'repo', '-d', name1
93
+ confgit 'repo'
94
+ }.must_output <<-EOD.gsub(/^\t+/,'')
95
+ * #{name2}
96
+ #{@hostname}
97
+ EOD
98
+ end
99
+
100
+ it "repo -d REPO (current)" do
101
+ name = '_foo_'
102
+ proc {
103
+ confgit 'repo', name
104
+ confgit 'repo', '-d', name
105
+ @abort == "'#{name}' is current repository!\n"
106
+ confgit 'repo'
107
+ }.must_output <<-EOD.gsub(/^\t+/,'')
108
+ * #{name}
109
+ #{@hostname}
110
+ EOD
111
+ end
112
+
113
+ it "repo -D REPO" do
114
+ name = '_foo_'
115
+ proc {
116
+ confgit 'repo', name
117
+ confgit 'repo', '-D', name
118
+ confgit 'repo'
119
+ }.must_output "* #{@hostname}\n"
120
+ end
121
+ end
122
+
123
+ describe "root" do
124
+ it "root" do
125
+ proc { confgit 'root' }.must_output "/\n"
126
+ end
127
+
128
+ it "root PATH" do
129
+ path = ENV['HOME']
130
+
131
+ confgit 'root', path
132
+ proc { confgit 'root' }.must_output "#{path}\n"
133
+ end
134
+
135
+ it "root -d" do
136
+ path = ENV['HOME']
137
+
138
+ confgit 'root', path
139
+ confgit 'root', '-d'
140
+ proc { confgit 'root' }.must_output "/\n"
141
+ end
142
+ end
143
+
144
+ describe "add" do
145
+ it "add FILE" do
146
+ chroot('README') { |root, file|
147
+ confgit 'add', file
148
+ proc { confgit 'status' }.must_output <<-EOD.gsub(/^\t+/,'')
149
+ # On branch master
150
+ #
151
+ # Initial commit
152
+ #
153
+ # Changes to be committed:
154
+ # (use "git rm --cached <file>..." to unstage)
155
+ #
156
+ # new file: #{file}
157
+ #
158
+ EOD
159
+ }
160
+ end
161
+
162
+ it "add DIR" do
163
+ dir = 'misc'
164
+
165
+ chroot(File.join(dir, 'README')) { |root, file|
166
+ confgit 'add', dir
167
+ proc { confgit 'status' }.must_output <<-EOD.gsub(/^\t+/,'')
168
+ # On branch master
169
+ #
170
+ # Initial commit
171
+ #
172
+ # Changes to be committed:
173
+ # (use "git rm --cached <file>..." to unstage)
174
+ #
175
+ # new file: #{file}
176
+ #
177
+ EOD
178
+ }
179
+ end
180
+ end
181
+
182
+ describe "rm" do
183
+ it "rm FILE" do
184
+ chroot('README') { |root, file|
185
+ confgit 'add', file
186
+
187
+ capture_io { confgit 'commit', '-m', "add #{file}" }
188
+ proc { confgit 'rm', file }.must_output "rm '#{file}'\n"
189
+ proc { confgit 'status' }.must_output <<-EOD.gsub(/^\t+/,'')
190
+ # On branch master
191
+ # Changes to be committed:
192
+ # (use "git reset HEAD <file>..." to unstage)
193
+ #
194
+ # deleted: #{file}
195
+ #
196
+ EOD
197
+ }
198
+ end
199
+
200
+ it "rm -f FILE" do
201
+ chroot('README') { |root, file|
202
+ confgit 'add', file
203
+
204
+ proc { confgit 'rm', '-f', file }.must_output "rm '#{file}'\n"
205
+ proc { confgit 'status' }.must_output <<-EOD.gsub(/^\t+/,'')
206
+ # On branch master
207
+ #
208
+ # Initial commit
209
+ #
210
+ nothing to commit (create/copy files and use "git add" to track)
211
+ EOD
212
+ }
213
+ end
214
+
215
+ it "rm -r DIR" do
216
+ dir = 'misc'
217
+
218
+ chroot(File.join(dir, 'README')) { |root, file|
219
+ confgit 'add', dir
220
+
221
+ capture_io { confgit 'commit', '-m', "add #{dir}" }
222
+ proc { confgit 'rm', '-r', dir }.must_output "rm '#{file}'\n"
223
+ proc { confgit 'status' }.must_output <<-EOD.gsub(/^\t+/,'')
224
+ # On branch master
225
+ # Changes to be committed:
226
+ # (use "git reset HEAD <file>..." to unstage)
227
+ #
228
+ # deleted: #{file}
229
+ #
230
+ EOD
231
+ }
232
+ end
233
+
234
+ it "rm -rf DIR" do
235
+ dir = 'misc'
236
+
237
+ chroot(File.join(dir, 'README')) { |root, file|
238
+ confgit 'add', dir
239
+
240
+ proc { confgit 'rm', '-rf', dir }.must_output "rm '#{file}'\n"
241
+ proc { confgit 'status' }.must_output <<-EOD.gsub(/^\t+/,'')
242
+ # On branch master
243
+ #
244
+ # Initial commit
245
+ #
246
+ nothing to commit (create/copy files and use "git add" to track)
247
+ EOD
248
+ }
249
+ end
250
+ end
251
+
252
+ describe "backup" do
253
+ before do
254
+ @mod_file = 'VERSION'
255
+ @data = '0.0.1'
256
+
257
+ chroot(@mod_file, 'README', 'LICENSE.txt') { |root, *files|
258
+ confgit 'add', *files
259
+ capture_io { confgit 'commit', '-m', "add #{files}" }
260
+ open(@mod_file, 'w') { |f| f.puts @data }
261
+ }
262
+ end
263
+
264
+ it "backup -n" do
265
+ chroot { |root, *files|
266
+ proc { confgit 'backup', '-n' }.must_output <<-EOD.gsub(/^\t+/,'')
267
+ \e[34m--> #{@mod_file}\e[m
268
+ # On branch master
269
+ nothing to commit (working directory clean)
270
+ EOD
271
+ }
272
+ end
273
+
274
+ it "backup -y" do
275
+ chroot { |root, *files|
276
+ proc { confgit 'backup', '-y' }.must_output <<-EOD.gsub(/^\t+/,'')
277
+ \e[34m--> VERSION\e[m
278
+ # On branch master
279
+ # Changes not staged for commit:
280
+ # (use "git add <file>..." to update what will be committed)
281
+ # (use "git checkout -- <file>..." to discard changes in working directory)
282
+ #
283
+ # modified: #{@mod_file}
284
+ #
285
+ no changes added to commit (use "git add" and/or "git commit -a")
286
+ EOD
287
+ }
288
+ end
289
+
290
+ it "backup -fn" do
291
+ chroot { |root, *files|
292
+ File.delete @mod_file
293
+
294
+ proc { confgit 'backup', '-fn' }.must_output <<-EOD.gsub(/^\t+/,'')
295
+ \e[34m--> LICENSE.txt\e[m
296
+ \e[34m--> README\e[m
297
+ \e[31m[?] #{@mod_file}\e[m
298
+ # On branch master
299
+ nothing to commit (working directory clean)
300
+ EOD
301
+ }
302
+ end
303
+ end
304
+
305
+ describe "restore" do
306
+ before do
307
+ @mod_file = 'VERSION'
308
+ @data = '0.0.1'
309
+
310
+ chroot(@mod_file, 'README', 'LICENSE.txt') { |root, *files|
311
+ confgit 'add', *files
312
+ capture_io { confgit 'commit', '-m', "add #{files}" }
313
+ }
314
+ end
315
+
316
+ it "restore -n" do
317
+ chroot { |root, *files|
318
+ open(@mod_file, 'w') { |f| f.puts @data }
319
+
320
+ modfile(@mod_file) { |prev|
321
+ proc { confgit 'restore', '-n' }.must_output <<-EOD.gsub(/^\t+/,'')
322
+ \e[34m<-- #{@mod_file}\e[m
323
+ EOD
324
+ open(@mod_file).read.must_equal prev
325
+ }
326
+ }
327
+ end
328
+
329
+ it "restore -y" do
330
+ chroot { |root, *files|
331
+ modfile(@mod_file) { |prev|
332
+ open(@mod_file, 'w') { |f| f.puts @data }
333
+
334
+ proc { confgit 'restore', '-y' }.must_output <<-EOD.gsub(/^\t+/,'')
335
+ \e[34m<-- #{@mod_file}\e[m
336
+ EOD
337
+ open(@mod_file).read.must_equal prev
338
+ }
339
+ }
340
+ end
341
+
342
+ it "restore -fn" do
343
+ chroot { |root, *files|
344
+ File.delete @mod_file
345
+
346
+ proc { confgit 'restore', '-fn' }.must_output <<-EOD.gsub(/^\t+/,'')
347
+ \e[34m<-- LICENSE.txt\e[m
348
+ \e[34m<-- README\e[m
349
+ \e[35m<-- #{@mod_file}\e[m
350
+ EOD
351
+ }
352
+ end
353
+ end
354
+
355
+ describe "git" do
356
+ it "commit" do
357
+ chroot('README') { |root, file|
358
+ confgit 'add', file
359
+ out, err, status = capture_io { confgit 'commit', '-m', "add #{file}" }
360
+ err.must_be_empty
361
+ status.must_be_nil
362
+ out.must_match <<-EOD.gsub(/^\t+/,'')
363
+
364
+ 0 files changed
365
+ create mode 100644 #{file}
366
+ EOD
367
+ }
368
+ end
369
+ end
370
+
371
+ describe "list" do
372
+ before do
373
+ chroot('VERSION', 'README', 'LICENSE.txt') { |root, *files|
374
+ confgit 'add', *files
375
+ capture_io { confgit 'commit', '-m', "add #{files}" }
376
+ }
377
+ end
378
+
379
+ it "list" do
380
+ chroot { |root, *files|
381
+ out, err, status = capture_io { confgit 'list' }
382
+ out.must_match Regexp.new <<-EOD.gsub(/^\t+/,'')
383
+ -rw-r--r-- .+ .+ #{root}/LICENSE\.txt
384
+ -rw-r--r-- .+ .+ #{root}/README
385
+ -rw-r--r-- .+ .+ #{root}/VERSION
386
+ EOD
387
+ }
388
+ end
389
+
390
+ it "list -8" do
391
+ chroot { |root, *files|
392
+ out, err, status = capture_io { confgit 'list', '-8' }
393
+ out.must_match Regexp.new <<-EOD.gsub(/^\t+/,'')
394
+ 100644 .+ .+ #{root}/LICENSE\.txt
395
+ 100644 .+ .+ #{root}/README
396
+ 100644 .+ .+ #{root}/VERSION
397
+ EOD
398
+ }
399
+ end
400
+ end
401
+
402
+ describe "tree" do
403
+ before do
404
+ @dir = 'misc'
405
+ chroot('.version', 'VERSION', 'README', File.join(@dir, 'LICENSE.txt')) { |root, *files|
406
+ confgit 'add', *files
407
+ }
408
+ end
409
+
410
+ it "tree" do
411
+ chroot { |root, *files|
412
+ proc { confgit 'tree' }.must_output <<-EOD.gsub(/^\t+/,'')
413
+ .
414
+ ├── README
415
+ ├── VERSION
416
+ └── #{@dir}
417
+ └── LICENSE.txt
418
+
419
+ 1 directory, 3 files
420
+ EOD
421
+ }
422
+ end
423
+
424
+ it "tree -a" do
425
+ chroot { |root, *files|
426
+ proc { confgit 'tree', '-a' }.must_output <<-EOD.gsub(/^\t+/,'')
427
+ .
428
+ ├── .version
429
+ ├── README
430
+ ├── VERSION
431
+ └── #{@dir}
432
+ └── LICENSE.txt
433
+
434
+ 1 directory, 4 files
435
+ EOD
436
+ }
437
+ end
438
+
439
+ it "tree DIR" do
440
+ chroot { |root, *files|
441
+ proc { confgit 'tree', @dir }.must_output <<-EOD.gsub(/^\t+/,'')
442
+ #{@dir}
443
+ └── LICENSE.txt
444
+
445
+ 0 directories, 1 file
446
+ EOD
447
+ }
448
+ end
449
+ end
450
+
451
+ describe "utilities" do
452
+ it "tig"
453
+
454
+ it "path" do
455
+ home = File.realpath(ENV['HOME'])
456
+ path = File.join(home, '.etc/confgit/repos', `hostname`.chomp)
457
+
458
+ proc { confgit 'path' }.must_output "#{path}\n"
459
+ end
460
+ end
461
+
462
+ after do
463
+ FileUtils.remove_entry_secure @tmpdir
464
+ ENV['HOME'] = @home
465
+ end
466
+ end
@@ -0,0 +1,9 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+
4
+ begin
5
+ require 'turn'
6
+
7
+ Turn.config.format = :progress
8
+ rescue LoadError
9
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: confgit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - gnue
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: i18n
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: turn
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Config files management tool with git
79
+ email:
80
+ - gnue@so-kukan.com
81
+ executables:
82
+ - confgit
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/confgit
92
+ - confgit.gemspec
93
+ - etc/bash_completion.d/confgit
94
+ - etc/tools/update_version.rb
95
+ - lib/confgit.rb
96
+ - lib/confgit/cli.rb
97
+ - lib/confgit/locales/en.yml
98
+ - lib/confgit/locales/ja.yml
99
+ - lib/confgit/repo.rb
100
+ - lib/confgit/version.rb
101
+ - lib/confgit/with_color.rb
102
+ - spec/confgit_spec.rb
103
+ - spec/spec_helper.rb
104
+ - VERSION
105
+ homepage: https://github.com/gnue/confgit
106
+ licenses: []
107
+ post_install_message: ! "\n ==================\n This software requires 'git'.\n
108
+ \ Also optional softwares 'tree' and 'tig'.\n\n If you are using the bash-completion\n\n
109
+ \ $ cp `gem env gemdir`/gems/confgit-0.0.3/etc/bash_completion.d/confgit $BASH_COMPLETION_DIR\n\n
110
+ \ ==================\n "
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: 1.9.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.23
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Config files management tool with git
132
+ test_files:
133
+ - spec/confgit_spec.rb
134
+ - spec/spec_helper.rb
135
+ has_rdoc: