scm_workspace 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3297eb7e346c9ad8e2bf8603cbc40f18ff27da67
4
+ data.tar.gz: d403449591587f7d1b4e3d5b2697db5120104559
5
+ SHA512:
6
+ metadata.gz: e7783fc796f20487075f650a1c86ad0e578bdd41e4d80dc5e1c209e815caca20f6960cad999363cdc5cd79b95ae02cbb6bf10ad802c6c4162110cd1d5b97129e
7
+ data.tar.gz: a80bacb2fd7814502b52aad903c28e8f0f95ba02fd8d086f2c348698f03741a6231740543760c491dc6318a1fd432718cb9667d70d9d9719828b86192739a56a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --profile
3
+ --format Fuubar
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scm_workspace.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 akima
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ScmWorkspace
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'scm_workspace'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install scm_workspace
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ class ScmWorkspace
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,306 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'fileutils'
4
+ require 'yaml'
5
+
6
+ require 'tengine/support/core_ext/hash/deep_dup'
7
+ require 'tengine/support/null_logger'
8
+
9
+ require "scm_workspace/version"
10
+
11
+ class ScmWorkspace
12
+
13
+ attr_reader :root
14
+ attr_writer :logger
15
+ def initialize(config, options = {})
16
+ @root = config[:workspace]
17
+ @logger = options[:logger]
18
+ end
19
+
20
+ def logger
21
+ @logger ||= Tengine::Support::NullLogger.new
22
+ end
23
+
24
+ def puts_info(msg)
25
+ logger.info(msg)
26
+ $stdout.puts(msg)
27
+ end
28
+
29
+ def configure(url)
30
+ raise "#{repo_dir} is not empty. You must clear it" if configured?
31
+ raise "#{root} does not exist" unless Dir.exist?(root)
32
+ url, opt = url.split(/\s+/, 2)
33
+ scm_type = self.class.guess_scm_type(url)
34
+ options = opt ? parse_options(opt, scm_type) : {}
35
+ options['url'] = url
36
+ save_options(options)
37
+ case scm_type
38
+ when :git then
39
+ logger.info("*" * 100)
40
+ logger.info("SCM configure")
41
+ puts_info "git clone #{url} #{repo_dir}"
42
+ require 'git'
43
+ @git = Git.clone(url, repo_dir)
44
+ when :svn then
45
+ Dir.chdir(@root) do
46
+ cmd = "git svn clone #{url} #{repo_dir} #{opt} > /dev/null 2>&1"
47
+ logger.info("*" * 100)
48
+ logger.info("SCM configure")
49
+ puts_info "cd #{@root} && " + cmd
50
+ system(cmd)
51
+ end
52
+ @git = nil
53
+ else
54
+ raise "Unknown SCM type: #{url}"
55
+ end
56
+ end
57
+
58
+ def clear
59
+ FileUtils.remove_entry_secure(repo_dir) if Dir.exist?(repo_dir)
60
+ FileUtils.rm(options_path) if File.exist?(options_path)
61
+ end
62
+
63
+ def checkout(branch_name)
64
+ logger.info("-" * 100)
65
+ puts_info "git checkout #{branch_name}"
66
+ git.checkout(branch_name)
67
+ case scm_type
68
+ when :git then
69
+ puts_info "git reset --hard origin/#{branch_name}"
70
+ git.reset_hard("origin/#{branch_name}")
71
+ end
72
+ end
73
+
74
+ def reset_hard(tag)
75
+ case scm_type
76
+ when :git then
77
+ logger.info("-" * 100)
78
+ puts_info("git reset --hard #{tag}")
79
+ git.reset_hard(tag)
80
+ when :svn then raise "Illegal operation for svn"
81
+ end
82
+ end
83
+ alias_method :move, :reset_hard
84
+
85
+ def fetch
86
+ case scm_type
87
+ when :git then
88
+ logger.info("-" * 100)
89
+ puts_info("git fetch origin")
90
+ git.fetch("origin")
91
+ when :svn then in_repo_dir{ system("git svn fetch") }
92
+ end
93
+ end
94
+
95
+ def status
96
+ case scm_type
97
+ when :git then
98
+ logger.info("-" * 100)
99
+ puts_info("git status")
100
+ status_text = in_repo_dir{ `git status` }
101
+ value = status_text.scan(/Your branch is behind 'origin\/#{current_branch_name}' by (\d+\s+commits)/)
102
+ if value && !value.empty?
103
+ "There is/are #{value.flatten.join}"
104
+ else
105
+ "everything is up-to-dated."
106
+ end
107
+ when :svn then
108
+ current_sha = git.log.first.sha
109
+ status_text = in_repo_dir{
110
+ cmd = "git log --branches --oneline #{current_sha}.."
111
+ puts_info cmd
112
+ `#{cmd}`
113
+ }
114
+ lines = status_text.split(/\n/)
115
+ if lines.empty?
116
+ "everything is up-to-dated."
117
+ else
118
+ latest_sha = lines.first
119
+ "There is/are #{lines.length} commits." + in_repo_dir{
120
+ " current revision: " << `git svn find-rev #{current_sha}`.strip <<
121
+ " latest revision: " << `git svn find-rev #{latest_sha}`.strip
122
+ }
123
+ end
124
+ end
125
+ end
126
+
127
+ def current_commit_key
128
+ return nil unless configured?
129
+ result = git.log.first.sha
130
+ case scm_type
131
+ when :svn then
132
+ rev = nil
133
+ cnt = 0
134
+ while rev.nil?
135
+ rev = in_repo_dir{ `git svn find-rev #{result}`.strip }
136
+ cnt += 1
137
+ raise "failed to get svn revision for #{result}" if cnt > 10
138
+ end
139
+ result << ':' << rev
140
+ end
141
+ result
142
+ end
143
+
144
+ def branch_names
145
+ return nil unless configured?
146
+ case scm_type
147
+ when :git then
148
+ result = git.branches.remote.map(&:full).map{|path| path.sub(/\Aremotes\/origin\//, '')}
149
+ result.delete_if{|name| name =~ /\AHEAD ->/}
150
+ result
151
+ when :svn then
152
+ git.branches.remote.map(&:full).map{|path| path.sub(/\Aremotes\//, '')}
153
+ end
154
+ end
155
+
156
+ def tag_names
157
+ return nil unless configured?
158
+ git.tags.map(&:name).uniq
159
+ end
160
+
161
+ def url
162
+ return nil unless configured?
163
+ case scm_type
164
+ when :git then git.remote("origin").url
165
+ when :svn then svn_info[:repository_root]
166
+ end
167
+ end
168
+
169
+ def current_branch_name
170
+ return nil unless configured?
171
+ case scm_type
172
+ when :git then
173
+ logger.info("-" * 100)
174
+ r = git.log.first.name
175
+ logger.info("current_branch_name: #{r.inspect}")
176
+ r
177
+ when :svn then
178
+ info = svn_info
179
+ r = info[:url].sub(info[:repository_root], '')
180
+ r.sub!(/\A\//, '')
181
+ if branch_prefix = load_options['branches']
182
+ r.sub!(branch_prefix + "/", '')
183
+ end
184
+ r
185
+ end
186
+ end
187
+
188
+ def current_tag_names
189
+ return nil unless configured?
190
+ log = git.log.first
191
+ git.tags.select{|b| b.log.first.sha == log.sha}.map(&:name)
192
+ end
193
+
194
+
195
+ def repo_dir
196
+ File.join(@root, "workspace")
197
+ end
198
+
199
+ def options_path
200
+ File.join(@root, "options.yml")
201
+ end
202
+
203
+ def configured?
204
+ Dir.exist?(repo_dir)
205
+ end
206
+
207
+ def cleared?
208
+ !configured?
209
+ end
210
+
211
+ def git
212
+ require 'git'
213
+ @git ||= Git.open(repo_dir, log: logger)
214
+ end
215
+
216
+ CONFIGURE_OPTIONS = {
217
+ svn: {
218
+ "A" => "authors_file",
219
+ "b" => "branches",
220
+ "m!" => "minimize_rul",
221
+ "q+" => "quiet",
222
+ "r" => "revision",
223
+ "s" => "stdlayout",
224
+ "t" => "tags",
225
+ "T" => "trunk",
226
+ },
227
+
228
+ git: {
229
+ 'n' => 'no_checkout',
230
+ 'l' => 'local',
231
+ 's' => 'shared',
232
+ 'o' => 'origin',
233
+ 'b' => 'branch',
234
+ 'u' => 'upload_pack',
235
+ 'c' => 'config',
236
+ }
237
+ }
238
+
239
+ def parse_options(opt, scm_type)
240
+ # "-T trunk --branches branches --tags tags -hoge --on" という文字列を
241
+ # [["-T", "trunk"], ["--branches", "branches"], ["--tags", "tags"], ["-hoge", nil], ["--on", nil]]
242
+ # という風に分割します
243
+ key_values = opt.scan(/(-[^\s]+)(?:\=|\s+)?([^-][^\s]+)?/)
244
+ result = key_values.each_with_object({}){|(k,v), d| d[k.sub(/\A-{1,2}/, '').gsub(/-/, '_')] = v }
245
+ CONFIGURE_OPTIONS[scm_type].each do |short_key, long_key|
246
+ if v = result.delete(short_key)
247
+ result[long_key] = v
248
+ end
249
+ end
250
+ result
251
+ end
252
+
253
+ def save_options(hash)
254
+ open(options_path, "w") do |f|
255
+ YAML.dump(hash, f)
256
+ end
257
+ end
258
+
259
+ def load_options
260
+ return {} unless File.readable?(options_path)
261
+ YAML.load_file(options_path)
262
+ end
263
+ alias_method :options, :load_options
264
+
265
+ def git_repo?
266
+ return nil unless configured?
267
+ !git.remotes.empty? rescue false
268
+ end
269
+
270
+ def svn_repo?
271
+ return nil unless configured?
272
+ Dir.exist?(File.join(repo_dir, '.git', 'svn'))
273
+ end
274
+
275
+ def scm_type
276
+ return nil unless configured?
277
+ return :git if git_repo?
278
+ return :svn if svn_repo?
279
+ nil
280
+ end
281
+
282
+ def svn_info
283
+ in_repo_dir do
284
+ txt = `git svn info`
285
+ return txt.scan(/^(.+?): (.*)$/).each_with_object({}){|(k,v), d| d[k.downcase.gsub(/\s/, '_').to_sym] = v }
286
+ end
287
+ end
288
+
289
+ def in_repo_dir
290
+ Dir.chdir(repo_dir) do
291
+ return yield
292
+ end
293
+ end
294
+
295
+
296
+ class << self
297
+ def guess_scm_type(url)
298
+ case url
299
+ when /\Agit:\/\//, /\Agit\@/, /\.git\Z/ then :git
300
+ when /svn/ then :svn
301
+ else nil
302
+ end
303
+ end
304
+ end
305
+
306
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scm_workspace/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scm_workspace"
8
+ spec.version = ScmWorkspace::VERSION
9
+ spec.authors = ["akima"]
10
+ spec.email = ["akima@groovenauts.jp"]
11
+ spec.description = %q{support loading scm repogitory into local workspace}
12
+ spec.summary = %q{support loading scm repogitory into local workspace}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "git"
22
+ spec.add_runtime_dependency "tengine_support"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 2.11.0"
27
+
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "fuubar"
30
+ end
@@ -0,0 +1,250 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ require 'tmpdir'
5
+ require 'fileutils'
6
+
7
+ # ApiServerモードでもScmWorkspaceクラスを使用するので、参照だけはできることを確認する。
8
+ describe ScmWorkspace do
9
+
10
+ before(:all){ @tmp_workspace = Dir.mktmpdir }
11
+ after(:all){ FileUtils.remove_entry_secure(@tmp_workspace) }
12
+ let(:tmp_workspace){ @tmp_workspace }
13
+ let(:scm_workspace){ ScmWorkspace.new(workspace: tmp_workspace) }
14
+
15
+ context "not depend on git" do
16
+ subject{ scm_workspace }
17
+ its(:repo_dir){ should_not == nil }
18
+ its(:options_path){ should_not == nil }
19
+ it{ subject.configured? }
20
+ it{ subject.cleared? }
21
+ end
22
+
23
+ context "git", git: true do
24
+ let(:url){ "git://github.com/akm/git_sandbox.git" }
25
+
26
+ context "before configuring" do
27
+ before do
28
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
29
+ end
30
+ subject{ scm_workspace }
31
+
32
+ its(:configured?){ should == false}
33
+ its(:scm_type){ should == nil}
34
+ its(:url){ should == nil}
35
+
36
+ its(:scm_type){ should == nil}
37
+ its(:git_repo?){ should == nil }
38
+ its(:svn_repo?){ should == nil }
39
+
40
+ its(:branch_names){ should == nil }
41
+ its(:tag_names){ should == nil }
42
+
43
+ its(:current_branch_name){ should == nil }
44
+ its(:current_tag_names){ should == nil }
45
+
46
+ its(:current_commit_key){ should == nil }
47
+ end
48
+
49
+ context "after configuring" do
50
+ before(:all) do
51
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
52
+ scm_workspace.configure(url)
53
+ end
54
+ subject{ scm_workspace }
55
+
56
+ its(:options){ should == {"url" => url} }
57
+ its(:configured?){ should == true}
58
+ its(:cleared?){ should == false }
59
+ its(:url){ should == url }
60
+
61
+ its(:scm_type){ should == :git}
62
+ its(:git_repo?){ should == true }
63
+ its(:svn_repo?){ should == false }
64
+
65
+ its(:branch_names){ should =~ %w[master develop 0.1 feature/function_d feature/function_e] }
66
+ its(:tag_names){ should =~ %w[v0.0.1 v0.0.2 v0.1.0] }
67
+
68
+ its(:current_branch_name){ should == "develop" }
69
+ its(:current_tag_names){ should =~ %w[v0.0.2] }
70
+
71
+ its(:current_commit_key){ should == "a0eaf8cca31080ca26edbae0daddaa9931edd6d6" }
72
+
73
+ it :fetch do
74
+ scm_workspace.fetch
75
+ end
76
+
77
+ context "duplicated configuration" do
78
+ it do
79
+ expect{
80
+ scm_workspace.configure(url)
81
+ }.to raise_error(/not empty/i)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe :checkout do
87
+ context "another branch" do
88
+ before(:all) do
89
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
90
+ scm_workspace.configure(url)
91
+ scm_workspace.checkout("0.1")
92
+ end
93
+ subject{ scm_workspace }
94
+ its(:current_branch_name){ should == "0.1" }
95
+ its(:current_tag_names){ should =~ %w[v0.1.0] }
96
+ end
97
+
98
+ context "branch is updated" do
99
+ before(:all) do
100
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
101
+ scm_workspace.configure(url)
102
+ Dir.chdir(scm_workspace.repo_dir) do
103
+ # バージョンを巻き戻す
104
+ system("git reset --hard a68a53610407e6ba30939326af743d3b734bb53d")
105
+ end
106
+ end
107
+ it "checkout again" do
108
+ scm_workspace.status.should =~ /7 commits/
109
+ scm_workspace.checkout("develop")
110
+ scm_workspace.status.should =~ /up-to-dated/
111
+ end
112
+ end
113
+ end
114
+
115
+ describe :move do # reset --hard
116
+ %w[v0.0.1 v0.0.2 v0.1.0].each do |tag|
117
+ context "#{tag} in develop" do
118
+ before(:all) do
119
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
120
+ scm_workspace.configure(url)
121
+ scm_workspace.checkout("develop")
122
+ scm_workspace.move(tag)
123
+ end
124
+ subject{ scm_workspace }
125
+ its(:current_branch_name){ should == "develop" }
126
+ its(:current_tag_names){ should =~ [tag] }
127
+ end
128
+ end
129
+ context "reset to fix wrong reset" do
130
+ before(:all) do
131
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
132
+ scm_workspace.configure(url)
133
+ scm_workspace.checkout("develop")
134
+ scm_workspace.move("v0.1.0")
135
+ end
136
+ subject{ scm_workspace }
137
+ it do
138
+ subject.current_branch_name.should == "develop"
139
+ subject.current_tag_names.should =~ ["v0.1.0"]
140
+ subject.checkout("develop")
141
+ subject.current_branch_name.should == "develop"
142
+ subject.current_tag_names.should =~ ["v0.0.2"]
143
+ end
144
+ end
145
+ end
146
+
147
+ describe :clear do
148
+ before(:all) do
149
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
150
+ scm_workspace.configure(url)
151
+ end
152
+
153
+ it do
154
+ scm_workspace.cleared?.should == false
155
+ scm_workspace.clear
156
+ scm_workspace.cleared?.should == true
157
+ Dir.exist?(scm_workspace.repo_dir).should == false
158
+ end
159
+ end
160
+
161
+ end
162
+
163
+ context "svn", svn: true do
164
+ let(:base_url){ "http://rubeus.googlecode.com/svn" }
165
+ let(:cloning_url){ "#{base_url} -T trunk --branches branches --tags tags" }
166
+
167
+ context "after configuring" do
168
+ before(:all) do
169
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
170
+ scm_workspace.configure(cloning_url)
171
+ end
172
+ subject{ scm_workspace }
173
+
174
+ its(:configured?){ should == true}
175
+ its(:cleared?){ should == false }
176
+ its(:url){ should == base_url }
177
+ its(:options){ should == {"url" => base_url, "trunk" => "trunk", "branches" => "branches", "tags" => "tags"} }
178
+
179
+ its(:scm_type){ should == :svn}
180
+ its(:git_repo?){ should == false }
181
+ its(:svn_repo?){ should == true }
182
+
183
+ its(:branch_names){ should =~ %w[jdbc_migration rakeable rmaven tags/0.0.8 tags/REL-0.0.2 tags/REL-0.0.3 trunk] }
184
+ its(:tag_names){ should == [] }
185
+
186
+ its(:current_branch_name){ should == "trunk" }
187
+ its(:current_tag_names){ should == [] }
188
+
189
+ # git svn だと SHAはcloneするたびに変わるので末尾のSVNのリビジョン番号をチェックします
190
+ its(:current_commit_key){ should =~ /\A[0-9a-f]{40}:247\Z/ }
191
+
192
+ it :fetch do
193
+ scm_workspace.fetch
194
+ end
195
+ end
196
+
197
+ context "duplicated configuration" do
198
+ before(:all) do
199
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
200
+ scm_workspace.configure(cloning_url)
201
+ end
202
+ subject{ scm_workspace }
203
+
204
+ it do
205
+ expect{
206
+ scm_workspace.configure(cloning_url)
207
+ }.to raise_error(/not empty/i)
208
+ end
209
+ end
210
+
211
+ describe :checkout do
212
+ %w[rmaven tags/0.0.8].each do |branch_name|
213
+
214
+ context branch_name do
215
+ before(:all) do
216
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
217
+ scm_workspace.configure(cloning_url)
218
+ scm_workspace.checkout(branch_name)
219
+ end
220
+ subject{ scm_workspace }
221
+ its(:current_branch_name){ should == branch_name }
222
+ its(:current_tag_names){ should == [] }
223
+ end
224
+
225
+ end
226
+
227
+ context "branch is updated" do
228
+ before(:all) do
229
+ FileUtils.remove_entry_secure(scm_workspace.repo_dir) if Dir.exist?(scm_workspace.repo_dir)
230
+ scm_workspace.configure(cloning_url)
231
+ scm_workspace.checkout("trunk")
232
+ Dir.chdir(scm_workspace.repo_dir) do
233
+ # バージョンを巻き戻す
234
+ system("git reset --hard HEAD~3")
235
+ end
236
+ end
237
+
238
+ it "checkout again" do
239
+ scm_workspace.current_commit_key.should =~ /\A[0-9a-f]{40}:244\Z/
240
+ scm_workspace.status.should =~ /3 commits.*current revision: 244.*latest revision: 247/
241
+ scm_workspace.checkout("trunk")
242
+ scm_workspace.current_commit_key.should =~ /\A[0-9a-f]{40}:247\Z/
243
+ scm_workspace.status.should =~ /up-to-dated/
244
+ end
245
+
246
+ end
247
+ end
248
+ end
249
+
250
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'scm_workspace'
3
+
4
+ RSpec.configure do |config|
5
+ # config.filter_run_excluding svn: true
6
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scm_workspace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - akima
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-26 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: tengine_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.11.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.11.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fuubar
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'
111
+ description: support loading scm repogitory into local workspace
112
+ email:
113
+ - akima@groovenauts.jp
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - lib/scm_workspace.rb
126
+ - lib/scm_workspace/version.rb
127
+ - scm_workspace.gemspec
128
+ - spec/scm_workspace_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: ''
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.0.3
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: support loading scm repogitory into local workspace
154
+ test_files:
155
+ - spec/scm_workspace_spec.rb
156
+ - spec/spec_helper.rb
157
+ has_rdoc: