raykit 0.0.501 → 0.0.503

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +25 -20
  4. data/bin/raykit +6 -6
  5. data/lib/raykit/auto_setup.rb +69 -69
  6. data/lib/raykit/command.rb +373 -373
  7. data/lib/raykit/conan/buildinfo.rb +69 -69
  8. data/lib/raykit/conanpackage.rb +49 -49
  9. data/lib/raykit/configuration.rb +53 -50
  10. data/lib/raykit/console.rb +314 -308
  11. data/lib/raykit/default_content.rb +227 -227
  12. data/lib/raykit/dir.rb +49 -49
  13. data/lib/raykit/dotnet.rb +174 -174
  14. data/lib/raykit/environment.rb +114 -114
  15. data/lib/raykit/filesystem.rb +34 -34
  16. data/lib/raykit/git/commit.rb +16 -16
  17. data/lib/raykit/git/directory.rb +216 -216
  18. data/lib/raykit/git/files.rb +46 -46
  19. data/lib/raykit/git/repositories.rb +89 -89
  20. data/lib/raykit/git/repository.rb +376 -376
  21. data/lib/raykit/installer.rb +17 -17
  22. data/lib/raykit/log.rb +80 -80
  23. data/lib/raykit/logevent.rb +49 -49
  24. data/lib/raykit/logging.rb +57 -57
  25. data/lib/raykit/markdown.rb +21 -21
  26. data/lib/raykit/msbuild.rb +54 -54
  27. data/lib/raykit/nugetpackage.rb +54 -54
  28. data/lib/raykit/nunit.rb +13 -13
  29. data/lib/raykit/project.rb +343 -343
  30. data/lib/raykit/rake.rb +39 -39
  31. data/lib/raykit/runner.rb +42 -42
  32. data/lib/raykit/secrets.rb +38 -38
  33. data/lib/raykit/sourceImport.rb +76 -76
  34. data/lib/raykit/sourceImports.rb +43 -43
  35. data/lib/raykit/string.rb +18 -18
  36. data/lib/raykit/symbols.rb +16 -16
  37. data/lib/raykit/tasks.rb +99 -99
  38. data/lib/raykit/text.rb +32 -32
  39. data/lib/raykit/timer.rb +31 -31
  40. data/lib/raykit/version.rb +103 -103
  41. data/lib/raykit/vstest.rb +24 -24
  42. data/lib/raykit/wt.rb +28 -28
  43. data/lib/raykit/zip.rb +73 -73
  44. data/lib/raykit.rb +125 -125
  45. metadata +1 -1
@@ -1,376 +1,376 @@
1
- # frozen_string_literal: true
2
- require "uri"
3
-
4
- module Raykit
5
- module Git
6
- # Functionality to manage a remote git repository
7
- class Repository
8
- # The url of the remote repository
9
- attr_accessor :url, :latest_commit_id, :latest_commit_exit_status
10
- attr_accessor :clone_directory, :work_directory
11
-
12
- def initialize(url)
13
- if (url.nil? || url.empty?)
14
- raise "Raykit::Git::Repository::initialize(url), url is nil or empty!"
15
- end
16
- @url = url
17
- @clone_directory = Raykit::Git::Directory.new(get_dev_dir("clone"))
18
- @work_directory = Raykit::Git::Directory.new(get_dev_dir("work"))
19
- load
20
- end
21
-
22
- def filename
23
- Environment.get_dev_dir("data") + File::SEPARATOR + "repository" + File::SEPARATOR + Raykit::FileSystem::replace_invalid_chars(relative_path.gsub("/", ".").gsub("\\", ".")) + ".json"
24
- end
25
-
26
- def save
27
- # Create the config directory if it doesn't exist.
28
- dir = File.dirname(filename)
29
- FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
30
-
31
- File.write(filename, {
32
- latest_commit_id: @latest_commit_id,
33
- latest_commit_exit_status: @latest_commit_exit_status,
34
- }.to_json)
35
- end
36
-
37
- def load
38
- if (File.exist?(filename))
39
- data = JSON.parse(File.read(filename))
40
- @latest_commit_id = data["latest_commit_id"]
41
- @latest_commit_exit_status = data["latest_commit_exit_status"]
42
- end
43
- end
44
-
45
- def update
46
- @latest_commit_id = latest_commit(default_branch)
47
- if (@latest_commit_id.nil? || @latest_commit_id.empty?)
48
- cmd = get_make_command(@latest_commit_id, "rake default")
49
- if (!cmd.nil?)
50
- @latest_commit_exit_status = cmd.exitstatus
51
- end
52
- end
53
- save
54
- end
55
-
56
- def short_name()
57
- @url.split("/").last.gsub(".git", "")
58
- end
59
-
60
- def to_json(*_args)
61
- JSON.generate({ "url" => @url })
62
- end
63
-
64
- def self.parse(json)
65
- hash = JSON.parse(json)
66
- Repository.new(hash["url"])
67
- end
68
-
69
- # The relative path is a valid local path name derived from the url
70
- def relative_path
71
- Repository::get_relative_path(@url)
72
- #@url.gsub("https://", "").gsub(".git", "").gsub("http://", "")
73
- end
74
-
75
- def self.get_relative_path(url)
76
- uri = URI.parse(url)
77
-
78
- # Remove top-level domain (e.g., ".com")
79
- if (uri.host.nil?)
80
- puts "uri.host is nil for #{url}"
81
- end
82
- host = uri.host.split(".")[0]
83
- #host.pop # remove the last element which should be the top-level domain
84
- #host = host.join(".")
85
-
86
- # Remove scheme (e.g., "http" or "https")
87
- path = host + uri.path
88
-
89
- # Remove top-level domain (e.g., ".com")
90
- #path = path.split(".")
91
- #path.pop # remove the last element which should be the top-level domain
92
- #path = path.join(".")
93
-
94
- # Remove trailing ".git" if present
95
- path = path.chomp(".git")
96
-
97
- path
98
- end
99
-
100
- def get_dev_dir(dir)
101
- dev_dir = Environment.get_dev_dir(dir)
102
- Raykit::Environment::normalize_path("#{dev_dir}/#{relative_path}")
103
- end
104
-
105
- # Clone the repository to a specific directory
106
- def clone(directory, depth = 0)
107
- if depth.zero?
108
- PROJECT.run("git clone #{@url} #{directory}")
109
- else
110
- PROJECT.run("git clone #{@url} #{directory} --depth #{depth}")
111
- end
112
- end
113
-
114
- # default branch
115
- def default_branch
116
- update_local_clone_directory
117
- if Dir.exist?(local_clone_directory)
118
- Dir.chdir(local_clone_directory) do
119
- # refs/remotes/origin/master
120
- default_branch = `git symbolic-ref refs/remotes/origin/HEAD`.split("/").last.strip
121
- return default_branch
122
- end
123
- end
124
- "main"
125
- end
126
-
127
- # The branches for the git repository
128
- def branches
129
- results = []
130
- update_local_clone_directory
131
- if Dir.exist?(local_clone_directory)
132
- Dir.chdir(local_clone_directory) do
133
- `git branch`.split('\n').each do |line|
134
- branch = line.gsub("*", "").strip
135
- results.insert(-1, branch) if branch.length.positive?
136
- end
137
- end
138
- end
139
- results
140
- end
141
-
142
- # The latest commit id for a branch of the repostiory
143
- def latest_commit(branch)
144
- if checkout_local_clone_directory_branch(branch)
145
- update_local_clone_directory
146
- Dir.chdir(local_clone_directory) do
147
- text = `git log -n 1`
148
- scan = text.scan(/commit (\w+)\s/)
149
- return scan[0][0].to_s
150
- end
151
- end
152
- ""
153
- end
154
-
155
- def latest_commit_date(branch)
156
- if checkout_local_clone_directory_branch(branch)
157
- update_local_clone_directory
158
- Dir.chdir(local_clone_directory) do
159
- text = `git log -n 1`
160
- scan = text.scan(/Date:\s+(.*)/)
161
- return scan[0][0].to_s
162
- end # Dir.chdir
163
- end # if checkout_local_clone_directory_branch
164
- ""
165
- end
166
-
167
- # The latest tag for a branch of the repository
168
- def latest_tag(branch)
169
- return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
170
-
171
- ""
172
- end
173
-
174
- private def local_clone_directory
175
- clone_dir = Environment::normalize_path("#{Environment.get_dev_dir("clone")}/#{relative_path}")
176
- end
177
-
178
- public def update_local_clone_directory
179
- if Dir.exist?(local_clone_directory)
180
- Dir.chdir(local_clone_directory) do
181
- pull = Raykit::Command.new("git pull")
182
- pull.run
183
- pull
184
- # t = `git pull`
185
- end
186
- else
187
- PROJECT.run("git clone #{@url} #{local_clone_directory}")
188
- end
189
- end
190
-
191
- private def checkout_local_clone_directory_branch(branch)
192
- update_local_clone_directory
193
- if Dir.exist?(local_clone_directory)
194
- Dir.chdir(local_clone_directory) do
195
- check = `git branch`
196
- t = `git checkout #{branch}` unless check.include?("* #{branch}")
197
- check = `git branch`
198
- return check.include?("* #{branch}")
199
- end
200
- end
201
- false
202
- end
203
-
204
- def clobber
205
- ["work", "clone", "make"].each { |d|
206
- dir = get_dev_dir(d)
207
- if (Dir.exist?(dir))
208
- begin
209
- puts " deleting #{dir}"
210
- FileUtils.rm_rf(dir)
211
- FileUtils.rm(dir) if (Dir.exist?(dir))
212
- rescue
213
- puts " problem while deleting #{dir}"
214
- end
215
- end
216
- }
217
- end
218
-
219
- def pull
220
- #repo = Raykit::Git::Repository.new(url)
221
- #work_dir = repo.get_dev_dir("work")
222
- #repo.clone(work_dir) if !Dir.exist?(work_dir)
223
- Raykit::Git::Repository::work_pull(url)
224
- update_local_clone_directory
225
- end
226
-
227
- def work(command, force = false)
228
- #pull if (!Dir.exist?(get_dev_dir("work")))
229
- fcommand = Raykit::FileSystem::replace_invalid_chars(command)
230
- filename = "#{Raykit::Environment::log_dir}/work_#{fcommand}_#{relative_path.gsub("/", "-")}.json"
231
- if (Raykit::Git::Directory.new(get_dev_dir("work")).outstanding_commit? || force)
232
- puts " outstanding commit in #{get_dev_dir("work")}"
233
- work_cmd = Raykit::Git::Repository::work_url(url, command)
234
- work_cmd.save_as(filename)
235
- return work_cmd
236
- else
237
- if (File.exist?(filename))
238
- return Raykit::Command::parse(IO.read(filename))
239
- else
240
- work_cmd = Raykit::Git::Repository::work_url(url, command)
241
- work_cmd.save_as(filename)
242
- update
243
- end
244
- #
245
- end
246
- end
247
-
248
- def get_make_command(commit_id, command)
249
- make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
250
- fcommand = Raykit::FileSystem::replace_invalid_chars(command)
251
- filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
252
- return Raykit::Command::parse(IO.read(filename)) if (File.exist?(filename))
253
- nil
254
- end
255
-
256
- def make(command, force = false)
257
- commit_id = "#{latest_commit(default_branch)}"
258
- make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
259
- fcommand = Raykit::FileSystem::replace_invalid_chars(command)
260
- filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
261
- if (!force && File.exist?(filename))
262
- return Raykit::Command::parse(IO.read(filename))
263
- else
264
- make_cmd = Raykit::Git::Repository::make_url(url, commit_id, "rake default")
265
- make_cmd.save_as(filename)
266
- update
267
- return make_cmd
268
- end
269
- end
270
-
271
- def self.work_pull(url)
272
- repo = Raykit::Git::Repository.new(url)
273
- work_dir = repo.get_dev_dir("work")
274
- repo.clone(work_dir) if !Dir.exist?(work_dir)
275
- Dir.chdir(work_dir) do
276
- run("git pull")
277
- end
278
- end
279
-
280
- def self.work_integrate(url)
281
- repo = Raykit::Git::Repository.new(url)
282
- work_dir = repo.get_dev_dir("work")
283
- repo.clone(work_dir) if !Dir.exist?(work_dir)
284
- Dir.chdir(work_dir) do
285
- run("git pull")
286
- run("rake integrate")
287
- end
288
- end
289
-
290
- def self.work_url(url, cmd)
291
- repo = Raykit::Git::Repository.new(url)
292
- puts " work #{url} #{cmd}"
293
- work_dir = repo.get_dev_dir("work")
294
- repo.clone(work_dir) if !Dir.exist?(work_dir)
295
- Dir.chdir(work_dir) do
296
- run("git pull")
297
- cmd = Raykit::Command.new(cmd)
298
- cmd = cmd.run().summary()
299
- cmd
300
- end
301
- end
302
-
303
- def self.make_url(url, commit_id, command)
304
- repo = Raykit::Git::Repository.new(url)
305
- puts " make #{url} #{commit_id} #{command}"
306
- make_dir = Raykit::Environment::normalize_path(repo.get_dev_dir("make") + "/" + commit_id)
307
- FileUtils.mkdir_p(repo.get_dev_dir("make")) if !Dir.exist?(repo.get_dev_dir("make"))
308
- if (Dir.exist?(make_dir))
309
- FileUtils.rm_rf(make_dir)
310
- end
311
- run("git clone #{url} #{make_dir}")
312
- cmd = 0
313
- Dir.chdir(make_dir) do
314
- run("git reset --hard #{commit_id}")
315
- FileUtils.rm_rf(".git")
316
- cmd = Raykit::Command.new(command)
317
- cmd = cmd.run().summary()
318
- end
319
- FileUtils.rm_rf(make_dir) if (cmd.exitstatus == 0)
320
- cmd
321
- end
322
-
323
- def self.backup(url, backup_dir)
324
- if (Dir.exist?(backup_dir))
325
- Dir.chdir(backup_dir) do
326
- run("git pull")
327
- end
328
- else
329
- run("git clone #{url} \"#{backup_dir}\"")
330
- end
331
- end # def self.backup
332
-
333
- def to_s
334
- #short_name
335
- latest_commit_id = @latest_commit_id.nil? ? "" : @latest_commit_id # latest_commit(default_branch)
336
- latest_commit_exit_status = @latest_commit_exit_status.nil? ? nil : @latest_commit_exit_status # latest_commit(default_branch)
337
- symbol = Raykit::Symbols::warning
338
- symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status == 0)
339
- symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status != 0)
340
- #latest_make_cmd = get_make_command(latest_commit_id, "rake default")
341
- #commit = Rainbow(latest_commit(default_branch)[0..8]).cyan
342
- #if (latest_make_cmd.nil?)
343
- # symbol = Raykit::Symbols::warning
344
- #else
345
- # symbol = latest_make_cmd.exitstatus == 0 ? Raykit::Symbols::success : Raykit::Symbols::error
346
- #end
347
- commit = latest_commit_id[0..8]
348
- "#{symbol} #{commit} #{short_name}"
349
- end # def to_s
350
-
351
- def to_table
352
- #max_name_width = 10
353
- #max_value_width = 10
354
- #header = " =".ljust(max_name_width + max_value_width + 5, "=")
355
- header = "==Repository=="
356
- table = header
357
- table += "\n" + to_table_row("Name", short_name)
358
- table += "\n" + to_table_row("Url", @url)
359
- table += "\n" + to_table_row("Default Branch", default_branch)
360
- table += "\n" + to_table_row("Latest Commit", latest_commit(default_branch))
361
- table += "\n" + to_table_row("Latest Commit Date", latest_commit_date(default_branch))
362
- table += "\n" + to_table_row("Latest Commit Make", make("rake default").summary(false))
363
- table += "\n" + to_table_row("Clone Directory", local_clone_directory)
364
- table += "\n" + to_table_row("Work Directory", get_dev_dir("work"))
365
- table += "\n" + to_table_row("Latest Tag", latest_tag(default_branch))
366
- table
367
- end # def to_table
368
-
369
- def to_table_row(name, value)
370
- max_name_width = 20
371
- max_value_width = 30
372
- Rainbow(name.rjust(max_name_width, " ")).cyan + " | " + Rainbow(value).white.bold
373
- end
374
- end # class Repository
375
- end # module Git
376
- end # module Raykit
1
+ # frozen_string_literal: true
2
+ require "uri"
3
+
4
+ module Raykit
5
+ module Git
6
+ # Functionality to manage a remote git repository
7
+ class Repository
8
+ # The url of the remote repository
9
+ attr_accessor :url, :latest_commit_id, :latest_commit_exit_status
10
+ attr_accessor :clone_directory, :work_directory
11
+
12
+ def initialize(url)
13
+ if (url.nil? || url.empty?)
14
+ raise "Raykit::Git::Repository::initialize(url), url is nil or empty!"
15
+ end
16
+ @url = url
17
+ @clone_directory = Raykit::Git::Directory.new(get_dev_dir("clone"))
18
+ @work_directory = Raykit::Git::Directory.new(get_dev_dir("work"))
19
+ load
20
+ end
21
+
22
+ def filename
23
+ Environment.get_dev_dir("data") + File::SEPARATOR + "repository" + File::SEPARATOR + Raykit::FileSystem::replace_invalid_chars(relative_path.gsub("/", ".").gsub("\\", ".")) + ".json"
24
+ end
25
+
26
+ def save
27
+ # Create the config directory if it doesn't exist.
28
+ dir = File.dirname(filename)
29
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
30
+
31
+ File.write(filename, {
32
+ latest_commit_id: @latest_commit_id,
33
+ latest_commit_exit_status: @latest_commit_exit_status,
34
+ }.to_json)
35
+ end
36
+
37
+ def load
38
+ if (File.exist?(filename))
39
+ data = JSON.parse(File.read(filename))
40
+ @latest_commit_id = data["latest_commit_id"]
41
+ @latest_commit_exit_status = data["latest_commit_exit_status"]
42
+ end
43
+ end
44
+
45
+ def update
46
+ @latest_commit_id = latest_commit(default_branch)
47
+ if (@latest_commit_id.nil? || @latest_commit_id.empty?)
48
+ cmd = get_make_command(@latest_commit_id, "rake default")
49
+ if (!cmd.nil?)
50
+ @latest_commit_exit_status = cmd.exitstatus
51
+ end
52
+ end
53
+ save
54
+ end
55
+
56
+ def short_name()
57
+ @url.split("/").last.gsub(".git", "")
58
+ end
59
+
60
+ def to_json(*_args)
61
+ JSON.generate({ "url" => @url })
62
+ end
63
+
64
+ def self.parse(json)
65
+ hash = JSON.parse(json)
66
+ Repository.new(hash["url"])
67
+ end
68
+
69
+ # The relative path is a valid local path name derived from the url
70
+ def relative_path
71
+ Repository::get_relative_path(@url)
72
+ #@url.gsub("https://", "").gsub(".git", "").gsub("http://", "")
73
+ end
74
+
75
+ def self.get_relative_path(url)
76
+ uri = URI.parse(url)
77
+
78
+ # Remove top-level domain (e.g., ".com")
79
+ if (uri.host.nil?)
80
+ puts "uri.host is nil for #{url}"
81
+ end
82
+ host = uri.host.split(".")[0]
83
+ #host.pop # remove the last element which should be the top-level domain
84
+ #host = host.join(".")
85
+
86
+ # Remove scheme (e.g., "http" or "https")
87
+ path = host + uri.path
88
+
89
+ # Remove top-level domain (e.g., ".com")
90
+ #path = path.split(".")
91
+ #path.pop # remove the last element which should be the top-level domain
92
+ #path = path.join(".")
93
+
94
+ # Remove trailing ".git" if present
95
+ path = path.chomp(".git")
96
+
97
+ path
98
+ end
99
+
100
+ def get_dev_dir(dir)
101
+ dev_dir = Environment.get_dev_dir(dir)
102
+ Raykit::Environment::normalize_path("#{dev_dir}/#{relative_path}")
103
+ end
104
+
105
+ # Clone the repository to a specific directory
106
+ def clone(directory, depth = 0)
107
+ if depth.zero?
108
+ PROJECT.run("git clone #{@url} #{directory}")
109
+ else
110
+ PROJECT.run("git clone #{@url} #{directory} --depth #{depth}")
111
+ end
112
+ end
113
+
114
+ # default branch
115
+ def default_branch
116
+ update_local_clone_directory
117
+ if Dir.exist?(local_clone_directory)
118
+ Dir.chdir(local_clone_directory) do
119
+ # refs/remotes/origin/master
120
+ default_branch = `git symbolic-ref refs/remotes/origin/HEAD`.split("/").last.strip
121
+ return default_branch
122
+ end
123
+ end
124
+ "main"
125
+ end
126
+
127
+ # The branches for the git repository
128
+ def branches
129
+ results = []
130
+ update_local_clone_directory
131
+ if Dir.exist?(local_clone_directory)
132
+ Dir.chdir(local_clone_directory) do
133
+ `git branch`.split('\n').each do |line|
134
+ branch = line.gsub("*", "").strip
135
+ results.insert(-1, branch) if branch.length.positive?
136
+ end
137
+ end
138
+ end
139
+ results
140
+ end
141
+
142
+ # The latest commit id for a branch of the repostiory
143
+ def latest_commit(branch)
144
+ if checkout_local_clone_directory_branch(branch)
145
+ update_local_clone_directory
146
+ Dir.chdir(local_clone_directory) do
147
+ text = `git log -n 1`
148
+ scan = text.scan(/commit (\w+)\s/)
149
+ return scan[0][0].to_s
150
+ end
151
+ end
152
+ ""
153
+ end
154
+
155
+ def latest_commit_date(branch)
156
+ if checkout_local_clone_directory_branch(branch)
157
+ update_local_clone_directory
158
+ Dir.chdir(local_clone_directory) do
159
+ text = `git log -n 1`
160
+ scan = text.scan(/Date:\s+(.*)/)
161
+ return scan[0][0].to_s
162
+ end # Dir.chdir
163
+ end # if checkout_local_clone_directory_branch
164
+ ""
165
+ end
166
+
167
+ # The latest tag for a branch of the repository
168
+ def latest_tag(branch)
169
+ return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
170
+
171
+ ""
172
+ end
173
+
174
+ private def local_clone_directory
175
+ clone_dir = Environment::normalize_path("#{Environment.get_dev_dir("clone")}/#{relative_path}")
176
+ end
177
+
178
+ public def update_local_clone_directory
179
+ if Dir.exist?(local_clone_directory)
180
+ Dir.chdir(local_clone_directory) do
181
+ pull = Raykit::Command.new("git pull")
182
+ pull.run
183
+ pull
184
+ # t = `git pull`
185
+ end
186
+ else
187
+ PROJECT.run("git clone #{@url} #{local_clone_directory}")
188
+ end
189
+ end
190
+
191
+ private def checkout_local_clone_directory_branch(branch)
192
+ update_local_clone_directory
193
+ if Dir.exist?(local_clone_directory)
194
+ Dir.chdir(local_clone_directory) do
195
+ check = `git branch`
196
+ t = `git checkout #{branch}` unless check.include?("* #{branch}")
197
+ check = `git branch`
198
+ return check.include?("* #{branch}")
199
+ end
200
+ end
201
+ false
202
+ end
203
+
204
+ def clobber
205
+ ["work", "clone", "make"].each { |d|
206
+ dir = get_dev_dir(d)
207
+ if (Dir.exist?(dir))
208
+ begin
209
+ puts " deleting #{dir}"
210
+ FileUtils.rm_rf(dir)
211
+ FileUtils.rm(dir) if (Dir.exist?(dir))
212
+ rescue
213
+ puts " problem while deleting #{dir}"
214
+ end
215
+ end
216
+ }
217
+ end
218
+
219
+ def pull
220
+ #repo = Raykit::Git::Repository.new(url)
221
+ #work_dir = repo.get_dev_dir("work")
222
+ #repo.clone(work_dir) if !Dir.exist?(work_dir)
223
+ Raykit::Git::Repository::work_pull(url)
224
+ update_local_clone_directory
225
+ end
226
+
227
+ def work(command, force = false)
228
+ pull if (!Dir.exist?(get_dev_dir("work")))
229
+ fcommand = Raykit::FileSystem::replace_invalid_chars(command)
230
+ filename = "#{Raykit::Environment::log_dir}/work_#{fcommand}_#{relative_path.gsub("/", "-")}.json"
231
+ if (Raykit::Git::Directory.new(get_dev_dir("work")).outstanding_commit? || force)
232
+ puts " outstanding commit in #{get_dev_dir("work")}"
233
+ work_cmd = Raykit::Git::Repository::work_url(url, command)
234
+ work_cmd.save_as(filename)
235
+ return work_cmd
236
+ else
237
+ if (File.exist?(filename))
238
+ return Raykit::Command::parse(IO.read(filename))
239
+ else
240
+ work_cmd = Raykit::Git::Repository::work_url(url, command)
241
+ work_cmd.save_as(filename)
242
+ update
243
+ end
244
+ #
245
+ end
246
+ end
247
+
248
+ def get_make_command(commit_id, command)
249
+ make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
250
+ fcommand = Raykit::FileSystem::replace_invalid_chars(command)
251
+ filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
252
+ return Raykit::Command::parse(IO.read(filename)) if (File.exist?(filename))
253
+ nil
254
+ end
255
+
256
+ def make(command, force = false)
257
+ commit_id = "#{latest_commit(default_branch)}"
258
+ make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
259
+ fcommand = Raykit::FileSystem::replace_invalid_chars(command)
260
+ filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
261
+ if (!force && File.exist?(filename))
262
+ return Raykit::Command::parse(IO.read(filename))
263
+ else
264
+ make_cmd = Raykit::Git::Repository::make_url(url, commit_id, "rake default")
265
+ make_cmd.save_as(filename)
266
+ update
267
+ return make_cmd
268
+ end
269
+ end
270
+
271
+ def self.work_pull(url)
272
+ repo = Raykit::Git::Repository.new(url)
273
+ work_dir = repo.get_dev_dir("work")
274
+ repo.clone(work_dir) if !Dir.exist?(work_dir)
275
+ Dir.chdir(work_dir) do
276
+ run("git pull")
277
+ end
278
+ end
279
+
280
+ def self.work_integrate(url)
281
+ repo = Raykit::Git::Repository.new(url)
282
+ work_dir = repo.get_dev_dir("work")
283
+ repo.clone(work_dir) if !Dir.exist?(work_dir)
284
+ Dir.chdir(work_dir) do
285
+ run("git pull")
286
+ run("rake integrate")
287
+ end
288
+ end
289
+
290
+ def self.work_url(url, cmd)
291
+ repo = Raykit::Git::Repository.new(url)
292
+ puts " work #{url} #{cmd}"
293
+ work_dir = repo.get_dev_dir("work")
294
+ repo.clone(work_dir) if !Dir.exist?(work_dir)
295
+ Dir.chdir(work_dir) do
296
+ run("git pull")
297
+ cmd = Raykit::Command.new(cmd)
298
+ cmd = cmd.run().summary()
299
+ cmd
300
+ end
301
+ end
302
+
303
+ def self.make_url(url, commit_id, command)
304
+ repo = Raykit::Git::Repository.new(url)
305
+ puts " make #{url} #{commit_id} #{command}"
306
+ make_dir = Raykit::Environment::normalize_path(repo.get_dev_dir("make") + "/" + commit_id)
307
+ FileUtils.mkdir_p(repo.get_dev_dir("make")) if !Dir.exist?(repo.get_dev_dir("make"))
308
+ if (Dir.exist?(make_dir))
309
+ FileUtils.rm_rf(make_dir)
310
+ end
311
+ run("git clone #{url} #{make_dir}")
312
+ cmd = 0
313
+ Dir.chdir(make_dir) do
314
+ run("git reset --hard #{commit_id}")
315
+ FileUtils.rm_rf(".git")
316
+ cmd = Raykit::Command.new(command)
317
+ cmd = cmd.run().summary()
318
+ end
319
+ FileUtils.rm_rf(make_dir) if (cmd.exitstatus == 0)
320
+ cmd
321
+ end
322
+
323
+ def self.backup(url, backup_dir)
324
+ if (Dir.exist?(backup_dir))
325
+ Dir.chdir(backup_dir) do
326
+ run("git pull")
327
+ end
328
+ else
329
+ run("git clone #{url} \"#{backup_dir}\"")
330
+ end
331
+ end # def self.backup
332
+
333
+ def to_s
334
+ #short_name
335
+ latest_commit_id = @latest_commit_id.nil? ? "" : @latest_commit_id # latest_commit(default_branch)
336
+ latest_commit_exit_status = @latest_commit_exit_status.nil? ? nil : @latest_commit_exit_status # latest_commit(default_branch)
337
+ symbol = Raykit::Symbols::warning
338
+ symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status == 0)
339
+ symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status != 0)
340
+ #latest_make_cmd = get_make_command(latest_commit_id, "rake default")
341
+ #commit = Rainbow(latest_commit(default_branch)[0..8]).cyan
342
+ #if (latest_make_cmd.nil?)
343
+ # symbol = Raykit::Symbols::warning
344
+ #else
345
+ # symbol = latest_make_cmd.exitstatus == 0 ? Raykit::Symbols::success : Raykit::Symbols::error
346
+ #end
347
+ commit = latest_commit_id[0..8]
348
+ "#{symbol} #{commit} #{short_name}"
349
+ end # def to_s
350
+
351
+ def to_table
352
+ #max_name_width = 10
353
+ #max_value_width = 10
354
+ #header = " =".ljust(max_name_width + max_value_width + 5, "=")
355
+ header = "==Repository=="
356
+ table = header
357
+ table += "\n" + to_table_row("Name", short_name)
358
+ table += "\n" + to_table_row("Url", @url)
359
+ table += "\n" + to_table_row("Default Branch", default_branch)
360
+ table += "\n" + to_table_row("Latest Commit", latest_commit(default_branch))
361
+ table += "\n" + to_table_row("Latest Commit Date", latest_commit_date(default_branch))
362
+ table += "\n" + to_table_row("Latest Commit Make", make("rake default").summary(false))
363
+ table += "\n" + to_table_row("Clone Directory", local_clone_directory)
364
+ table += "\n" + to_table_row("Work Directory", get_dev_dir("work"))
365
+ table += "\n" + to_table_row("Latest Tag", latest_tag(default_branch))
366
+ table
367
+ end # def to_table
368
+
369
+ def to_table_row(name, value)
370
+ max_name_width = 20
371
+ max_value_width = 30
372
+ Rainbow(name.rjust(max_name_width, " ")).cyan + " | " + Rainbow(value).white.bold
373
+ end
374
+ end # class Repository
375
+ end # module Git
376
+ end # module Raykit