scm_workspace 0.1.0 → 0.2.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/version.rb +1 -1
- data/lib/scm_workspace.rb +64 -50
- data/scm_workspace.gemspec +1 -1
- data/spec/spec_helper.rb +5 -0
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c25ceeee6e8984c83a268cdd8f6ac77dbb4299b
|
4
|
+
data.tar.gz: b96f3e482cfec6b779419148c546420c59ad112e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dc62a996961bd8607440029ce273e1fd73d8a819f5e58ebd2c30ca9833867a0cbef55fa0e04ad3c1d4b687904f1e2ea18f805c75b90548bd9e2bafc7e4ea3ed
|
7
|
+
data.tar.gz: 86191e0cd85108c5826082ebf253d18d80e13059da7e843f50f2bf30b4abc3e7e4c58efce3add60d928dd56807503a7de25635f761cd739062c7c09fef673628
|
data/lib/scm_workspace.rb
CHANGED
@@ -10,6 +10,9 @@ require "scm_workspace/version"
|
|
10
10
|
|
11
11
|
class ScmWorkspace
|
12
12
|
|
13
|
+
class Error < StandardError
|
14
|
+
end
|
15
|
+
|
13
16
|
attr_reader :root
|
14
17
|
attr_writer :logger
|
15
18
|
attr_accessor :svn_branch_prefix
|
@@ -30,6 +33,30 @@ class ScmWorkspace
|
|
30
33
|
$stdout.puts(msg) if verbose
|
31
34
|
end
|
32
35
|
|
36
|
+
def system!(cmd)
|
37
|
+
logger.info("executing: #{cmd}")
|
38
|
+
buf = []
|
39
|
+
IO.popen("#{cmd} 2>&1") do |io|
|
40
|
+
while line = io.gets
|
41
|
+
# puts line
|
42
|
+
buf << line
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if $?.exitstatus == 0
|
47
|
+
logger.info("\e[33mSUCCESS: %s\e[0m" % cmd)
|
48
|
+
return buf.join
|
49
|
+
else
|
50
|
+
msg = "\e[31mFAILURE: %s\n%s\e[0m" % [cmd, buf.join.strip]
|
51
|
+
logger.error(msg)
|
52
|
+
raise Error, msg
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def system_at_root!(cmd)
|
57
|
+
Dir.chdir(root){ system!(cmd) }
|
58
|
+
end
|
59
|
+
|
33
60
|
def configure(url)
|
34
61
|
if configured?
|
35
62
|
msg = "#{repo_dir} is not empty. You must clear it"
|
@@ -42,9 +69,7 @@ class ScmWorkspace
|
|
42
69
|
when :git then
|
43
70
|
logger.info("*" * 100)
|
44
71
|
logger.info("SCM configure")
|
45
|
-
|
46
|
-
require 'git'
|
47
|
-
@git = Git.clone(url, repo_dir)
|
72
|
+
system!("git clone #{url} #{repo_dir} #{opt}")
|
48
73
|
when :svn then
|
49
74
|
Dir.chdir(@root) do
|
50
75
|
cmd = "git svn clone #{url} #{repo_dir} #{opt}"
|
@@ -54,7 +79,6 @@ class ScmWorkspace
|
|
54
79
|
puts_info "cd #{@root} && " + cmd
|
55
80
|
system(cmd)
|
56
81
|
end
|
57
|
-
@git = nil
|
58
82
|
else
|
59
83
|
raise "Unknown SCM type: #{url}"
|
60
84
|
end
|
@@ -72,42 +96,35 @@ class ScmWorkspace
|
|
72
96
|
|
73
97
|
def checkout(branch_name)
|
74
98
|
logger.info("-" * 100)
|
75
|
-
|
76
|
-
git.checkout(branch_name)
|
99
|
+
system_at_root!("git checkout #{branch_name}")
|
77
100
|
case scm_type
|
78
|
-
when :git then
|
79
|
-
puts_info "git reset --hard origin/#{branch_name}"
|
80
|
-
git.reset_hard("origin/#{branch_name}")
|
101
|
+
when :git then system_at_root!("git reset --hard origin/#{branch_name}")
|
81
102
|
end
|
82
103
|
end
|
83
104
|
|
84
105
|
def reset_hard(tag)
|
106
|
+
logger.info("-" * 100)
|
85
107
|
case scm_type
|
86
|
-
when :git then
|
87
|
-
logger.info("-" * 100)
|
88
|
-
puts_info("git reset --hard #{tag}")
|
89
|
-
git.reset_hard(tag)
|
108
|
+
when :git then system_at_root!("git reset --hard #{tag}")
|
90
109
|
when :svn then raise "Illegal operation for svn"
|
91
110
|
end
|
92
111
|
end
|
93
112
|
alias_method :move, :reset_hard
|
94
113
|
|
95
114
|
def fetch
|
115
|
+
logger.info("-" * 100)
|
96
116
|
case scm_type
|
97
|
-
when :git then
|
98
|
-
|
99
|
-
puts_info("git fetch origin")
|
100
|
-
git.fetch("origin")
|
101
|
-
when :svn then in_repo_dir{ system("git svn fetch") }
|
117
|
+
when :git then system_at_root!("git fetch origin")
|
118
|
+
when :svn then system_at_root!("git svn fetch")
|
102
119
|
end
|
103
120
|
end
|
104
121
|
|
105
122
|
def status
|
123
|
+
logger.info("-" * 100)
|
106
124
|
case scm_type
|
107
125
|
when :git then
|
108
|
-
|
109
|
-
|
110
|
-
status_text = in_repo_dir{ `git status` }
|
126
|
+
# puts_info("git status")
|
127
|
+
status_text = system_at_root!("git status") # in_repo_dir{ `git status` }
|
111
128
|
value = status_text.scan(/Your branch is behind 'origin\/#{current_branch_name}' by (\d+\s+commits)/)
|
112
129
|
if value && !value.empty?
|
113
130
|
"There is/are #{value.flatten.join}"
|
@@ -115,28 +132,26 @@ class ScmWorkspace
|
|
115
132
|
"everything is up-to-dated."
|
116
133
|
end
|
117
134
|
when :svn then
|
118
|
-
|
119
|
-
status_text = in_repo_dir{
|
120
|
-
cmd = "git log --branches --oneline #{current_sha}.."
|
121
|
-
puts_info cmd
|
122
|
-
`#{cmd}`
|
123
|
-
}
|
135
|
+
status_text = system_at_root!("git log --branches --oneline #{current_sha}..")
|
124
136
|
lines = status_text.split(/\n/)
|
125
137
|
if lines.empty?
|
126
138
|
"everything is up-to-dated."
|
127
139
|
else
|
128
140
|
latest_sha = lines.first
|
129
|
-
"There is/are #{lines.length} commits."
|
130
|
-
" current revision: " <<
|
131
|
-
" latest revision: "
|
132
|
-
}
|
141
|
+
"There is/are #{lines.length} commits." <<
|
142
|
+
" current revision: " << system_at_root!("git svn find-rev #{current_sha}").strip <<
|
143
|
+
" latest revision: " << system_at_root!("git svn find-rev #{latest_sha}").strip
|
133
144
|
end
|
134
145
|
end
|
135
146
|
end
|
136
147
|
|
148
|
+
def current_sha
|
149
|
+
system_at_root!("git log -1").scan(/^commit ([0-9a-f]+)$/).flatten.first
|
150
|
+
end
|
151
|
+
|
137
152
|
def current_commit_key
|
138
153
|
return nil unless configured?
|
139
|
-
result =
|
154
|
+
result = current_sha
|
140
155
|
case scm_type
|
141
156
|
when :svn then
|
142
157
|
rev = nil
|
@@ -155,23 +170,30 @@ class ScmWorkspace
|
|
155
170
|
return nil unless configured?
|
156
171
|
case scm_type
|
157
172
|
when :git then
|
158
|
-
result = git.
|
173
|
+
result = system_at_root!("git branch -r").lines.map{|path| path.sub(/\A\s*origin\//, '').strip }
|
159
174
|
result.delete_if{|name| name =~ /\AHEAD ->/}
|
160
175
|
result
|
161
176
|
when :svn then
|
162
|
-
git.
|
177
|
+
system_at_root!("git branch -r").lines.map{|path| path.strip }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def remotes
|
182
|
+
system_at_root!("git remote -v show").lines.each_with_object({}) do |line, d|
|
183
|
+
name, url, other = line.strip.split(/[\t\s]+/, 3)
|
184
|
+
d[name] = url
|
163
185
|
end
|
164
186
|
end
|
165
187
|
|
166
188
|
def tag_names
|
167
189
|
return nil unless configured?
|
168
|
-
git.
|
190
|
+
system_at_root!("git tag").lines.map{|path| path.strip.strip }
|
169
191
|
end
|
170
192
|
|
171
193
|
def url
|
172
194
|
return nil unless configured?
|
173
195
|
case scm_type
|
174
|
-
when :git then
|
196
|
+
when :git then remotes["origin"]
|
175
197
|
when :svn then svn_info[:repository_root]
|
176
198
|
end
|
177
199
|
end
|
@@ -216,8 +238,7 @@ class ScmWorkspace
|
|
216
238
|
|
217
239
|
def current_tag_names
|
218
240
|
return nil unless configured?
|
219
|
-
|
220
|
-
git.tags.select{|b| b.log.first.sha == log.sha}.map(&:name)
|
241
|
+
system_at_root!("git describe --tags #{current_sha}").lines.map(&:strip) rescue []
|
221
242
|
end
|
222
243
|
|
223
244
|
|
@@ -233,11 +254,6 @@ class ScmWorkspace
|
|
233
254
|
!configured?
|
234
255
|
end
|
235
256
|
|
236
|
-
def git
|
237
|
-
require 'git'
|
238
|
-
@git ||= Git.open(repo_dir, log: logger)
|
239
|
-
end
|
240
|
-
|
241
257
|
CONFIGURE_OPTIONS = {
|
242
258
|
svn: {
|
243
259
|
"A" => "authors_file",
|
@@ -263,7 +279,7 @@ class ScmWorkspace
|
|
263
279
|
|
264
280
|
def git_repo?
|
265
281
|
return nil unless configured?
|
266
|
-
!
|
282
|
+
!remotes.empty? rescue false
|
267
283
|
end
|
268
284
|
|
269
285
|
def svn_repo?
|
@@ -279,18 +295,16 @@ class ScmWorkspace
|
|
279
295
|
end
|
280
296
|
|
281
297
|
def svn_info
|
282
|
-
|
283
|
-
|
284
|
-
return txt.scan(/^(.+?): (.*)$/).each_with_object({}){|(k,v), d| d[k.downcase.gsub(/\s/, '_').to_sym] = v }
|
285
|
-
end
|
298
|
+
txt = system_at_root!("git svn info")
|
299
|
+
return txt.scan(/^(.+?): (.*)$/).each_with_object({}){|(k,v), d| d[k.downcase.gsub(/\s/, '_').to_sym] = v }
|
286
300
|
end
|
287
301
|
|
288
|
-
def
|
302
|
+
def in_root
|
289
303
|
Dir.chdir(repo_dir) do
|
290
304
|
return yield
|
291
305
|
end
|
292
306
|
end
|
293
|
-
|
307
|
+
alias_method :in_repo_dir, :in_root
|
294
308
|
|
295
309
|
class << self
|
296
310
|
def guess_scm_type(url)
|
data/scm_workspace.gemspec
CHANGED
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "git"
|
22
21
|
spec.add_runtime_dependency "tengine_support"
|
23
22
|
|
24
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
24
|
spec.add_development_dependency "rake"
|
26
25
|
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "simplecov"
|
27
27
|
|
28
28
|
spec.add_development_dependency "pry"
|
29
29
|
spec.add_development_dependency "fuubar"
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scm_workspace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: git
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: tengine_support
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +66,20 @@ dependencies:
|
|
80
66
|
- - '>='
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|