scm_workspace 0.3.1 → 0.3.2

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: 22b5aed2ebb23effa0e4d640181d609aa67fbf26
4
- data.tar.gz: c49b9fa6ff2dab68bfd7bfcfcb4b77f9481ef497
3
+ metadata.gz: 629f7fb29d5ef531cceaef646f520543465b360c
4
+ data.tar.gz: 34de1677365fe70f213b18ab0297afd4ec510849
5
5
  SHA512:
6
- metadata.gz: 189d7d0d60e6fa0bd1f490ffee50f0047e1a2e853c42eb940e6817798760e42b946b9739dec09cd79abdb6b43ef81081481e095268ac8a2d77ada54608de9ea0
7
- data.tar.gz: 0846be292f4e3ab347608db6c70a480d5e0c8ab175bd6727ef3bb005149c1b20ebcf401f88833d5e12088b01a9bdf3918a16201586d2b430d77d17039a166fad
6
+ metadata.gz: 3d6eefbb6c85f92d72b78d6a339bf47441588271ecdbd122243217c62997d5de277b06609aa66c5cf24327c667f81c732709db116abd6247e342381e274db483
7
+ data.tar.gz: 0c5ae5a04d84b6d08d06dbf7b7548e9b35169fe3f1dda63ad9143a91fa72b10cea6b033ec6fff9126fb0d4516ce25290a2015b1c4259b2022a37c7526dccdb9c
@@ -1,3 +1,3 @@
1
1
  class ScmWorkspace
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/scm_workspace.rb CHANGED
@@ -61,7 +61,7 @@ class ScmWorkspace
61
61
  end
62
62
 
63
63
  def configure(url)
64
- if configured?
64
+ unless empty?
65
65
  msg = "#{repo_dir} is not empty. You must clear it"
66
66
  msg << "\nls -la #{repo_dir}" << `ls -la #{repo_dir}` if verbose
67
67
  raise msg
@@ -87,8 +87,8 @@ class ScmWorkspace
87
87
  end
88
88
 
89
89
  def clear
90
- return unless Dir.exist?(repo_dir)
91
- fileutils.chdir(repo_dir) do
90
+ return unless Dir.exist?(root)
91
+ fileutils.chdir(root) do
92
92
  (Dir.glob("*") + Dir.glob(".*")).each do |d|
93
93
  next if d =~ /\A\.+\Z/
94
94
  fileutils.remove_entry_secure(d)
@@ -96,6 +96,13 @@ class ScmWorkspace
96
96
  end
97
97
  end
98
98
 
99
+ def empty?
100
+ return true unless Dir.exist?(root)
101
+ fileutils.chdir(root) do
102
+ return (Dir.glob("*") + Dir.glob(".*")).reject{|d| d =~ /\A\.+\Z/}.empty?
103
+ end
104
+ end
105
+
99
106
  def checkout(branch_name)
100
107
  logger.info("-" * 100)
101
108
  system_at_root!("git checkout #{branch_name}")
@@ -147,11 +154,12 @@ class ScmWorkspace
147
154
  end
148
155
 
149
156
  def current_sha
157
+ return nil unless accessible?
150
158
  system_at_root!("git log -1").scan(/^commit ([0-9a-f]+)$/).flatten.first
151
159
  end
152
160
 
153
161
  def current_commit_key
154
- return nil unless configured?
162
+ return nil unless accessible?
155
163
  result = current_sha
156
164
  case scm_type
157
165
  when :svn then
@@ -177,7 +185,7 @@ class ScmWorkspace
177
185
  end
178
186
 
179
187
  def branch_names
180
- return nil unless configured?
188
+ return nil unless accessible?
181
189
  case scm_type
182
190
  when :git then
183
191
  result = system_at_root!("git branch -r").lines.map{|path| path.sub(/\A\s*origin\//, '').strip }
@@ -196,12 +204,12 @@ class ScmWorkspace
196
204
  end
197
205
 
198
206
  def tag_names
199
- return nil unless configured?
207
+ return nil unless accessible?
200
208
  system_at_root!("git tag").lines.map{|path| path.strip.strip }
201
209
  end
202
210
 
203
211
  def url
204
- return nil unless configured?
212
+ return nil unless accessible?
205
213
  case scm_type
206
214
  when :git then remotes["origin"]
207
215
  when :svn then svn_info[:repository_root]
@@ -209,7 +217,7 @@ class ScmWorkspace
209
217
  end
210
218
 
211
219
  def current_branch_name
212
- return nil unless configured?
220
+ return nil unless accessible?
213
221
  case scm_type
214
222
  when :git then git_current_branch_name
215
223
  when :svn then svn_current_branch_name
@@ -247,7 +255,7 @@ class ScmWorkspace
247
255
  end
248
256
 
249
257
  def current_tag_names
250
- return nil unless configured?
258
+ return nil unless accessible?
251
259
  system_at_root!("git describe --tags #{current_sha}").lines.map(&:strip) rescue []
252
260
  end
253
261
 
@@ -256,12 +264,24 @@ class ScmWorkspace
256
264
  @root
257
265
  end
258
266
 
267
+ # submoduleでない場合 true
268
+ # submoduleの場合 true
269
+ # gitの対象外の場合 false
270
+ def accessible?
271
+ File.exist?(File.join(repo_dir, ".git"))
272
+ end
273
+
274
+ # submoduleでない場合 true
275
+ # submoduleの場合 false
276
+ # gitの対象外の場合 false
259
277
  def configured?
260
278
  Dir.exist?(File.join(repo_dir, ".git"))
261
279
  end
262
280
 
281
+
263
282
  def cleared?
264
- !configured?
283
+ # !configured?
284
+ empty?
265
285
  end
266
286
 
267
287
  def contains?(obj)
@@ -292,17 +312,17 @@ class ScmWorkspace
292
312
  }
293
313
 
294
314
  def git_repo?
295
- return nil unless configured?
315
+ return nil unless accessible?
296
316
  !remotes.empty? rescue false
297
317
  end
298
318
 
299
319
  def svn_repo?
300
- return nil unless configured?
320
+ return nil unless accessible?
301
321
  Dir.exist?(File.join(repo_dir, '.git', 'svn'))
302
322
  end
303
323
 
304
324
  def scm_type
305
- return nil unless configured?
325
+ return nil unless accessible?
306
326
  return :git if git_repo?
307
327
  return :svn if svn_repo?
308
328
  nil
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.3.1
4
+ version: 0.3.2
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-24 00:00:00.000000000 Z
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tengine_support