scm_workspace 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scm_workspace/core_ext/fileutils.rb +44 -0
- data/lib/scm_workspace/version.rb +1 -1
- data/lib/scm_workspace.rb +16 -13
- data/scm_workspace.gemspec +1 -0
- data/spec/scm_workspace/core_ext/fileutils_spec.rb +71 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a6ca321bae08aaafea7d717e1807f8d22f79945
|
4
|
+
data.tar.gz: c49506dc81028ed0052301b4b69e8549e972655c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aad7efa2ec7fb4db8298c3d65de9be0413a0a6bbf04ade013c5b4ec9a7e7c47074dccc28bca0eb59ff63014cf9ed8dfd04122cebe535623a8f72079cc0dbfcb
|
7
|
+
data.tar.gz: 2bc81ed0c8769892b8e8c0e4ea915891ea630b3747c39dca282bd0d50f56806c5932035fb20589472d030b32e2643c7c5c4d76cc08319176b8ba48b8ab3fcbd2
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module FileUtils
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def with_logger(logger, level = :info)
|
8
|
+
output = LoggerAdapter.new(logger, level)
|
9
|
+
|
10
|
+
Module.new do
|
11
|
+
include FileUtils
|
12
|
+
@fileutils_output = output
|
13
|
+
@fileutils_label = ''
|
14
|
+
|
15
|
+
::FileUtils.collect_method(:verbose).each do |name|
|
16
|
+
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
17
|
+
def #{name}(*args)
|
18
|
+
super(*fu_update_option(args, :verbose => true))
|
19
|
+
end
|
20
|
+
private :#{name}
|
21
|
+
EOS
|
22
|
+
end
|
23
|
+
|
24
|
+
extend self
|
25
|
+
class << self
|
26
|
+
::FileUtils::METHODS.each do |m|
|
27
|
+
public m
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class LoggerAdapter
|
36
|
+
def initialize(logger, level)
|
37
|
+
@logger, @level = logger, level
|
38
|
+
end
|
39
|
+
def puts(msg)
|
40
|
+
@logger.send(@level, msg)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/scm_workspace.rb
CHANGED
@@ -7,6 +7,7 @@ require 'tengine/support/core_ext/hash/deep_dup'
|
|
7
7
|
require 'tengine/support/null_logger'
|
8
8
|
|
9
9
|
require "scm_workspace/version"
|
10
|
+
require "scm_workspace/core_ext/fileutils"
|
10
11
|
|
11
12
|
class ScmWorkspace
|
12
13
|
|
@@ -28,9 +29,8 @@ class ScmWorkspace
|
|
28
29
|
@logger ||= Tengine::Support::NullLogger.new
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
-
|
33
|
-
$stdout.puts(msg) if verbose
|
32
|
+
def fileutils
|
33
|
+
@fileutils ||= FileUtils.with_logger(logger)
|
34
34
|
end
|
35
35
|
|
36
36
|
def system!(cmd)
|
@@ -44,8 +44,11 @@ class ScmWorkspace
|
|
44
44
|
end
|
45
45
|
|
46
46
|
if $?.exitstatus == 0
|
47
|
-
|
48
|
-
|
47
|
+
msg = "\e[33mSUCCESS: %s\e[0m" % cmd
|
48
|
+
r = buf.join
|
49
|
+
msg << "\n" << r.strip if verbose
|
50
|
+
logger.info(msg)
|
51
|
+
return r
|
49
52
|
else
|
50
53
|
msg = "\e[31mFAILURE: %s\n%s\e[0m" % [cmd, buf.join.strip]
|
51
54
|
logger.error(msg)
|
@@ -54,7 +57,9 @@ class ScmWorkspace
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def system_at_root!(cmd)
|
57
|
-
|
60
|
+
fileutils.chdir(root) do
|
61
|
+
return system!(cmd)
|
62
|
+
end
|
58
63
|
end
|
59
64
|
|
60
65
|
def configure(url)
|
@@ -71,12 +76,11 @@ class ScmWorkspace
|
|
71
76
|
logger.info("SCM configure")
|
72
77
|
system!("git clone #{url} #{repo_dir} #{opt}")
|
73
78
|
when :svn then
|
74
|
-
|
79
|
+
fileutils.chdir(@root) do
|
75
80
|
cmd = "git svn clone #{url} #{repo_dir} #{opt}"
|
76
81
|
cmd << " > /dev/null 2>&1" unless verbose
|
77
82
|
logger.info("*" * 100)
|
78
83
|
logger.info("SCM configure")
|
79
|
-
puts_info "cd #{@root} && " + cmd
|
80
84
|
system(cmd)
|
81
85
|
end
|
82
86
|
else
|
@@ -86,10 +90,10 @@ class ScmWorkspace
|
|
86
90
|
|
87
91
|
def clear
|
88
92
|
return unless Dir.exist?(repo_dir)
|
89
|
-
|
93
|
+
fileutils.chdir(repo_dir) do
|
90
94
|
(Dir.glob("*") + Dir.glob(".*")).each do |d|
|
91
95
|
next if d =~ /\A\.+\Z/
|
92
|
-
|
96
|
+
fileutils.remove_entry_secure(d)
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end
|
@@ -123,7 +127,6 @@ class ScmWorkspace
|
|
123
127
|
logger.info("-" * 100)
|
124
128
|
case scm_type
|
125
129
|
when :git then
|
126
|
-
# puts_info("git status")
|
127
130
|
status_text = system_at_root!("git status") # in_repo_dir{ `git status` }
|
128
131
|
value = status_text.scan(/Your branch is behind 'origin\/#{current_branch_name}' by (\d+\s+commits)/)
|
129
132
|
if value && !value.empty?
|
@@ -217,7 +220,7 @@ class ScmWorkspace
|
|
217
220
|
|
218
221
|
def git_current_branch_name(dir = repo_dir)
|
219
222
|
return nil unless Dir.exist?(dir)
|
220
|
-
|
223
|
+
fileutils.chdir(dir) do
|
221
224
|
# http://qiita.com/sugyan/items/83e060e895fa8ef2038c
|
222
225
|
result = `git symbolic-ref --short HEAD`.strip
|
223
226
|
return result unless result.nil? || result.empty?
|
@@ -313,7 +316,7 @@ class ScmWorkspace
|
|
313
316
|
end
|
314
317
|
|
315
318
|
def in_root
|
316
|
-
|
319
|
+
fileutils.chdir(repo_dir) do
|
317
320
|
return yield
|
318
321
|
end
|
319
322
|
end
|
data/scm_workspace.gemspec
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'scm_workspace/core_ext/fileutils'
|
4
|
+
require "stringio"
|
5
|
+
require "tmpdir"
|
6
|
+
|
7
|
+
describe FileUtils do
|
8
|
+
|
9
|
+
let(:io){ StringIO.new }
|
10
|
+
let(:logger){ Logger.new(io) }
|
11
|
+
let(:fu){ FileUtils.with_logger(logger) }
|
12
|
+
|
13
|
+
describe :chdir do
|
14
|
+
it "default" do
|
15
|
+
dir = File.expand_path("../..", __FILE__)
|
16
|
+
fu.chdir(dir) do
|
17
|
+
fu.pwd.should == dir
|
18
|
+
end
|
19
|
+
io.rewind
|
20
|
+
lines = io.read.lines
|
21
|
+
lines.length.should == 2
|
22
|
+
lines[0].should =~ /\AI, \[.+\]\s+INFO -- : cd #{Regexp.escape(dir)}/
|
23
|
+
lines[1].should =~ /\AI, \[.+\]\s+INFO -- : cd -/
|
24
|
+
end
|
25
|
+
|
26
|
+
it "debug" do
|
27
|
+
debug_fu = FileUtils.with_logger(logger, :debug)
|
28
|
+
dir = File.expand_path("../..", __FILE__)
|
29
|
+
debug_fu.chdir(dir) do
|
30
|
+
debug_fu.pwd.should == dir
|
31
|
+
end
|
32
|
+
io.rewind
|
33
|
+
lines = io.read.lines
|
34
|
+
lines.length.should == 2
|
35
|
+
lines[0].should =~ /\AD, \[.+\]\s+DEBUG -- : cd #{Regexp.escape(dir)}/
|
36
|
+
lines[1].should =~ /\AD, \[.+\]\s+DEBUG -- : cd -/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe :mkdir_p do
|
41
|
+
it "default" do
|
42
|
+
path = nil
|
43
|
+
Dir.mktmpdir do |dir|
|
44
|
+
path = File.join(dir, "foo/bar")
|
45
|
+
fu.mkdir_p(path)
|
46
|
+
Dir.exist?(path).should be_true
|
47
|
+
end
|
48
|
+
io.rewind
|
49
|
+
lines = io.read.lines
|
50
|
+
lines.length.should == 1
|
51
|
+
lines[0].should =~ /\AI, \[.+\]\s+INFO -- : mkdir -p #{Regexp.escape(path)}/
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe :touch do
|
56
|
+
it "default" do
|
57
|
+
path = nil
|
58
|
+
Dir.mktmpdir do |dir|
|
59
|
+
path = File.join(dir, "restart.txt")
|
60
|
+
fu.touch(path)
|
61
|
+
File.exist?(path).should be_true
|
62
|
+
IO.read(path).should == ""
|
63
|
+
end
|
64
|
+
io.rewind
|
65
|
+
lines = io.read.lines
|
66
|
+
lines.length.should == 1
|
67
|
+
lines[0].should =~ /\AI, \[.+\]\s+INFO -- : touch #{Regexp.escape(path)}/
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scm_workspace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tengine_support
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-debugger
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: fuubar
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,8 +137,10 @@ files:
|
|
123
137
|
- README.md
|
124
138
|
- Rakefile
|
125
139
|
- lib/scm_workspace.rb
|
140
|
+
- lib/scm_workspace/core_ext/fileutils.rb
|
126
141
|
- lib/scm_workspace/version.rb
|
127
142
|
- scm_workspace.gemspec
|
143
|
+
- spec/scm_workspace/core_ext/fileutils_spec.rb
|
128
144
|
- spec/scm_workspace_spec.rb
|
129
145
|
- spec/spec_helper.rb
|
130
146
|
homepage: ''
|
@@ -152,6 +168,7 @@ signing_key:
|
|
152
168
|
specification_version: 4
|
153
169
|
summary: support loading scm repogitory into local workspace
|
154
170
|
test_files:
|
171
|
+
- spec/scm_workspace/core_ext/fileutils_spec.rb
|
155
172
|
- spec/scm_workspace_spec.rb
|
156
173
|
- spec/spec_helper.rb
|
157
174
|
has_rdoc:
|