dtk-common 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +5 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +16 -0
  5. data/LICENSE +674 -0
  6. data/README.md +36 -0
  7. data/dtk-common.gemspec +23 -0
  8. data/lib/common_patch.rb +16 -0
  9. data/lib/dsl/directory_parser/git.rb +39 -0
  10. data/lib/dsl/directory_parser/linux.rb +21 -0
  11. data/lib/dsl/directory_parser.rb +77 -0
  12. data/lib/dsl/file_parser/file_types/assembly/v2/assembly.rb +53 -0
  13. data/lib/dsl/file_parser/file_types/component_module_refs/v1/component_module_refs.rb +57 -0
  14. data/lib/dsl/file_parser.rb +228 -0
  15. data/lib/dsl.rb +23 -0
  16. data/lib/dtk-common/version.rb +3 -0
  17. data/lib/dtk_common.rb +36 -0
  18. data/lib/dynamic_loader.rb +28 -0
  19. data/lib/git_repo/adapters/rugged/blob.rb +14 -0
  20. data/lib/git_repo/adapters/rugged/commit.rb +14 -0
  21. data/lib/git_repo/adapters/rugged/common.rb +34 -0
  22. data/lib/git_repo/adapters/rugged/tree.rb +40 -0
  23. data/lib/git_repo/adapters/rugged.rb +45 -0
  24. data/lib/git_repo.rb +93 -0
  25. data/lib/gitolite/configuration.rb +35 -0
  26. data/lib/gitolite/errors.rb +5 -0
  27. data/lib/gitolite/grit/adapter.rb +101 -0
  28. data/lib/gitolite/grit/file_access.rb +51 -0
  29. data/lib/gitolite/init.rb +16 -0
  30. data/lib/gitolite/manager.rb +158 -0
  31. data/lib/gitolite/repo.rb +171 -0
  32. data/lib/gitolite/user_group.rb +98 -0
  33. data/lib/gitolite/utils.rb +59 -0
  34. data/lib/grit_adapter/file_access/diff.rb +82 -0
  35. data/lib/grit_adapter/file_access/status.rb +25 -0
  36. data/lib/grit_adapter/file_access.rb +296 -0
  37. data/lib/grit_adapter/object_access.rb +39 -0
  38. data/lib/grit_adapter.rb +212 -0
  39. data/lib/module_version.rb +12 -0
  40. data/lib/require_first.rb +18 -0
  41. data/rich_tests/README.md +1 -0
  42. data/rich_tests/dsl_test1.rb +14 -0
  43. data/rich_tests/dsl_test2.rb +10 -0
  44. data/rich_tests/dsl_test3.rb +17 -0
  45. data/rich_tests/dsl_test4.rb +25 -0
  46. data/rich_tests/fixtures/dsl_test1/sm-dtk-bootstrap/global_module_refs.json +2 -0
  47. data/rich_tests/fixtures/dsl_test1/sm-dtk-dtk/global_module_refs.json +7 -0
  48. data/rich_tests/fixtures/dsl_test1/sm-dtk-test_dtk/global_module_refs.json +8 -0
  49. data/rich_tests/fixtures/dsl_test1/sm-dtk-test_postgres/global_module_refs.json +7 -0
  50. data/rich_tests/fixtures/dsl_test1/sm-dtk-test_service/global_module_refs.json +5 -0
  51. data/rich_tests/fixtures/dsl_test1/sm-dtk-testv1/global_module_refs.json +14 -0
  52. data/rich_tests/fixtures/dsl_test1/sm-rich-app/global_module_refs.json +5 -0
  53. data/rich_tests/fixtures/dsl_test1/sm-rich-hdp/global_module_refs.json +3 -0
  54. data/rich_tests/fixtures/dsl_test1/sm-rich-test_dtk/global_module_refs.json +5 -0
  55. data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/message_bus/assembly.json +23 -0
  56. data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/repo_manager/assembly.json +26 -0
  57. data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/server-nginx/assembly.json +64 -0
  58. data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/server-on-one-node/assembly.json +47 -0
  59. data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/t4/assembly.json +20 -0
  60. data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/global_module_refs.json +7 -0
  61. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/HEAD +1 -0
  62. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/config +4 -0
  63. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/description +1 -0
  64. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/applypatch-msg.sample +15 -0
  65. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/commit-msg.sample +24 -0
  66. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/post-update.sample +8 -0
  67. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/pre-applypatch.sample +14 -0
  68. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/pre-commit.sample +50 -0
  69. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/pre-rebase.sample +169 -0
  70. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/prepare-commit-msg.sample +36 -0
  71. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/update.sample +128 -0
  72. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/info/exclude +6 -0
  73. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/0a/5b6255a87c9e56d91557398aee730a2b3de745 +0 -0
  74. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/15/e78d7675db51c3f9e2cf154a350d82b12abc72 +0 -0
  75. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/18/7c41cd47b9c295da0cee128c888c95cf2bba1c +0 -0
  76. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/2a/17fb5b22b8108790435eb215ffe9d06829b841 +0 -0
  77. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/2e/8c9f8472cb0e9e2421e8b5c86ad981b728cdcf +0 -0
  78. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/3b/4646ef81ef99c0c7aa62c0a97e774761c7de54 +0 -0
  79. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/5c/498a06b1ef830203e4e04c1043c9d846a18a98 +0 -0
  80. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/72/b3afc0c009e42faa235784f29f43e336bceebd +0 -0
  81. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/78/2987dc58fb1f3bea00452b8727957115b51d6f +0 -0
  82. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/9b/7c5e8096a3a871c76ad179bc29c33ac5390683 +0 -0
  83. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/a5/b61c6608349cd87f3d53a13abc2d2f51772082 +0 -0
  84. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/b4/1fb4f136d54fc9277ff16d58d9361a03a91b23 +0 -0
  85. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/be/81c8c44a92dde5139fdd302d75eec027032c8b +0 -0
  86. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/c3/88fbdcfe33840280aa119df6d01a782fdbdd60 +1 -0
  87. data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/refs/heads/master +1 -0
  88. data/rich_tests/fixtures/rugged_test1/repo1.git/HEAD +1 -0
  89. data/rich_tests/fixtures/rugged_test1/repo1.git/config +4 -0
  90. data/rich_tests/fixtures/rugged_test1/repo1.git/description +1 -0
  91. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/applypatch-msg.sample +15 -0
  92. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/commit-msg.sample +24 -0
  93. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/post-update.sample +8 -0
  94. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/pre-applypatch.sample +14 -0
  95. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/pre-commit.sample +50 -0
  96. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/pre-rebase.sample +169 -0
  97. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/prepare-commit-msg.sample +36 -0
  98. data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/update.sample +128 -0
  99. data/rich_tests/fixtures/rugged_test1/repo1.git/info/exclude +6 -0
  100. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/01/7d2a92efdefb513c266496c836112112c84b54 +0 -0
  101. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/0c/6675dac950c9f2038c899a0026c60bc71b1986 +0 -0
  102. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/12/7d8deca9a49974f887c594fc79804a2490c3c5 +0 -0
  103. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/21/c65148298b7366019013c31ddc9e6c62770277 +0 -0
  104. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/22/2c738a4abaebbd9ea3b6634fac902ae74479c4 +0 -0
  105. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/25/560ef0476ffda4abf20b660955aac645b6ee2f +0 -0
  106. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/4a/e421568785273757fe479236de426b80d1b658 +2 -0
  107. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/60/465cb06c0cde161eff264d4c2a0535fc1e8bb2 +0 -0
  108. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/63/7f0347d31dad180d6fc7f6720c187b05a8754c +0 -0
  109. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/6c/54ab6443f1a24669a99f2ce1b43863be2e9fda +0 -0
  110. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/82/c75b6fa64b746bd7f9cd7afe3c1e5bd53c430c +0 -0
  111. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/86/ec2616845245b9c9355f768a1727bcdfb643ac +0 -0
  112. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/93/ee8545d8f9681db9800cb11ec8aa72a8df8bd1 +0 -0
  113. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/bc/65ddb77fef699933dfe16b79c769f7a9cc0afd +0 -0
  114. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/d4/b1ee93110d823c5161f8cb954a6cf2e41345c1 +2 -0
  115. data/rich_tests/fixtures/rugged_test1/repo1.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 +0 -0
  116. data/rich_tests/fixtures/rugged_test1/repo1.git/refs/heads/branch1 +1 -0
  117. data/rich_tests/fixtures/rugged_test1/repo1.git/refs/heads/master +1 -0
  118. data/rich_tests/rugged_test1.rb +16 -0
  119. data/test.rb +13 -0
  120. metadata +205 -0
@@ -0,0 +1,296 @@
1
+ require 'colorize'
2
+
3
+ module DTK; module Common; class GritAdapter
4
+ class FileAccess < self
5
+ require File.expand_path('file_access/status', File.dirname(__FILE__))
6
+ require File.expand_path('file_access/diff', File.dirname(__FILE__))
7
+ include StatusMixin
8
+ include DiffMixin
9
+ def add_file(file_rel_path, content=nil)
10
+ content ||= String.new
11
+ file_path = qualified_path(file_rel_path)
12
+ chdir_and_checkout do
13
+ File.open(file_path,"w"){|f|f << content}
14
+ git_command__add(file_path)
15
+ end
16
+ end
17
+
18
+ def add_file_command(file_rel_path)
19
+ chdir_and_checkout do
20
+ file_path = qualified_path(file_rel_path)
21
+ git_command__add(file_path)
22
+ end
23
+ end
24
+
25
+ def git_command__add(file_path)
26
+ #put in -f to avoid error being thrown if try to add an ignored file
27
+ git_command(:add,file_path,"-f")
28
+ end
29
+ private :git_command__add
30
+
31
+ def remove_file(file_rel_path)
32
+ file_path = qualified_path(file_rel_path)
33
+ chdir_and_checkout do
34
+ if File.exists?(file_path)
35
+ git_command(:rm,file_path)
36
+ end
37
+ end
38
+ end
39
+
40
+ def pull(remote_branch,local_branch,remote=nil)
41
+ remote ||= default_remote()
42
+ chdir do
43
+ git_command(:pull,remote,"#{remote_branch}:#{local_branch}")
44
+ end
45
+ end
46
+
47
+ def fetch(remote=nil)
48
+ remote ||= default_remote()
49
+ chdir do
50
+ git_command(:fetch,remote)
51
+ end
52
+ end
53
+
54
+ #temp branch #TODO: make sure no name conflict
55
+ TempBranch = 'temp_branch'
56
+ def merge_theirs(remote_branch_ref)
57
+ #since there is no 'git merge -s theirs' we need to simulate it
58
+ chdir do
59
+ git_command(:checkout,"-b",TempBranch,remote_branch_ref)
60
+ git_command(:merge,@branch,"-s","ours")
61
+ git_command(:checkout,@branch)
62
+ git_command(:reset,"--hard",TempBranch)
63
+ git_command(:branch,"-D",TempBranch)
64
+ end
65
+ end
66
+
67
+ def merge(remote_branch_ref)
68
+ chdir_and_checkout do
69
+ git_command(:merge,remote_branch_ref)
70
+ end
71
+ end
72
+
73
+ def changed_files()
74
+ # NOTE: There is issue with grit and git. Where grit.status will report file changed (modified)
75
+ # and git status will not. Grit registers changing file time-stamp as change while git doesn't. This would
76
+ # not be a problem but `git push` will fail because of this. Following is fix for that.
77
+ output = git_command_status()
78
+ grit_files = @grit_repo.status.files.select { |k,v| (v.type =~ /(A|M)/ || v.untracked) }
79
+ changed_files = grit_files.select do |file|
80
+ file_name = file.instance_of?(String) ? file : file.first
81
+ filter_file_through_status_output(file_name,output)
82
+ end
83
+
84
+ # returns array of arrays (first element name of file)
85
+ changed_files.to_a
86
+ end
87
+
88
+ #TODO: see if we can do away with this
89
+ def filter_file_through_status_output(file_name,output)
90
+ #need to search for both filename and whether dircetory added
91
+ if output.include?(file_name)
92
+ true
93
+ else
94
+ file_parts = file_name.split('/')
95
+ file_parts.pop
96
+ while not file_parts.empty? do
97
+ return true if output.include?(file_parts.join('/')+'/')
98
+ file_parts.pop
99
+ end
100
+ false
101
+ end
102
+ end
103
+ private :filter_file_through_status_output
104
+
105
+ def deleted_files()
106
+ # returns array of arrays (first element name of file)
107
+ @grit_repo.status.deleted().to_a
108
+ end
109
+
110
+ def print_status()
111
+ changes = [@grit_repo.status.changed(), @grit_repo.status.untracked(), @grit_repo.status.deleted()]
112
+ puts "\nModified files:\n".colorize(:green) unless changes[0].empty?
113
+ changes[0].each { |item| puts "\t#{item.first}" }
114
+ puts "\nAdded files:\n".colorize(:yellow) unless changes[1].empty?
115
+ changes[1].each { |item| puts "\t#{item.first}" }
116
+ puts "\nDeleted files:\n".colorize(:red) unless changes[2].empty?
117
+ changes[2].each { |item| puts "\t#{item.first}" }
118
+ puts ""
119
+ end
120
+
121
+ ##
122
+ # Checks for changes add/delete/modified
123
+ #
124
+ def changed?
125
+ !(changed_files() + deleted_files).empty?
126
+ end
127
+
128
+ ##
129
+ # Method will add and remove all files, after commit with given msg
130
+ #
131
+ def add_remove_commit_all(commit_msg)
132
+ chdir do
133
+ # modified, untracked
134
+ changed_files().each do |c_file|
135
+ add_file_command(c_file.first)
136
+ end
137
+ # deleted
138
+ deleted_files().each do |d_file|
139
+ remove_file(d_file.first)
140
+ end
141
+ # commit
142
+ commit(commit_msg)
143
+ end
144
+ end
145
+
146
+ def commit(commit_msg,opts={})
147
+ cmd_args = [:commit,"-a","-m",commit_msg]
148
+ author = "#{opts[:author_username]||DefaultAuthor[:username]} <#{opts[:author_email]||DefaultAuthor[:email]}>"
149
+ cmd_args += ["--author",author]
150
+ chdir_and_checkout do
151
+ #note using following because silent failure @grit_repo.commit_all(commit_msg)
152
+ git_command(*cmd_args)
153
+ end
154
+ end
155
+ DefaultAuthor = {
156
+ :username => "dtk",
157
+ :email => "dtk@reactor8.com"
158
+ }
159
+
160
+ # returns :equal, :local_behind, :local_ahead, or :branchpoint
161
+ # type can be :remote_branch or :local_branch
162
+ def ret_merge_relationship(type,ref,opts={})
163
+ if (type == :remote_branch and opts[:fetch_if_needed])
164
+ #TODO: this fetches all branches on the remote; see if anyway to just fetch a specfic branch
165
+ #ref will be of form remote_name/branch
166
+ #TODO: also see if more efficient to use git ls-remote
167
+ fetch(ref.split("/").first)
168
+ end
169
+ other_grit_ref =
170
+ case type
171
+ when :remote_branch
172
+ @grit_repo.remotes.find{|r|r.name == ref}
173
+ when :local_branch
174
+ @grit_repo.heads.find{|r|r.name == ref}
175
+ else
176
+ raise Error.new("Illegal type parameter (#{type}) passed to ret_merge_relationship")
177
+ end
178
+
179
+ local_sha = head_commit_sha()
180
+ if opts[:ret_commit_shas]
181
+ opts[:ret_commit_shas][:local_sha] = local_sha
182
+ end
183
+
184
+ unless other_grit_ref
185
+ if type == :remote_branch
186
+ return :no_remote_ref
187
+ end
188
+ raise Error.new("Cannot find git ref (#{ref})")
189
+ end
190
+ other_sha = other_grit_ref.commit.id
191
+ if opts[:ret_commit_shas]
192
+ opts[:ret_commit_shas][:other_sha] = other_sha
193
+ end
194
+
195
+ if other_sha == local_sha
196
+ :equal
197
+ else
198
+ #shas can be different but they can have same content so do a git diff
199
+ unless any_diffs?(local_sha,other_sha)
200
+ return :equal
201
+ end
202
+ #TODO: see if missing or mis-categorizing any condition below
203
+ if git_command__rev_list_contains?(local_sha,other_sha) then :local_ahead
204
+ elsif git_command__rev_list_contains?(other_sha,local_sha) then :local_behind
205
+ else :branchpoint
206
+ end
207
+ end
208
+ end
209
+
210
+ def head_commit_sha()
211
+ head = @grit_repo.heads.find{|r|r.name == @branch}
212
+ head && head.commit.id
213
+ end
214
+ def find_remote_sha(ref)
215
+ remote = @grit_repo.remotes.find{|r|r.name == ref}
216
+ remote && remote.commit.id
217
+ end
218
+
219
+ def add_branch?(branch)
220
+ unless branches().include?(branch)
221
+ add_branch(branch)
222
+ end
223
+ end
224
+ def add_branch(branch)
225
+ chdir_and_checkout() do
226
+ git_command(:branch,branch)
227
+ end
228
+ end
229
+ def remove_branch?(branch)
230
+ if branches().include?(branch)
231
+ remove_branch(branch)
232
+ end
233
+ end
234
+ def remove_branch(branch)
235
+ checkout_branch = @branch
236
+ chdir_and_checkout(checkout_branch,:stay_on_checkout_branch => true) do
237
+ git_command(:branch,"-d",branch)
238
+ end.first
239
+ end
240
+
241
+ private
242
+
243
+ #
244
+ # There is issue with Grit 1.8.7 and 1.9.3 version have diffrent returns on changed/deleted files
245
+ #
246
+ # 1.8.7 => Returns array of arrays where file name is first elemenet
247
+ # 1.9.3 => Returns hash where keys are file names
248
+ #
249
+ # No need for it now, but when refactoring code use this instead of .to_a fix
250
+ def grit_compability_transform(grit_files)
251
+ grit_files.instance_of?(Hash) ? grit_files.keys : grit_files.collect { |element| element.first }
252
+ end
253
+
254
+ def default_remote()
255
+ "origin"
256
+ end
257
+
258
+ def qualified_path(file_rel_path)
259
+ "#{@repo_dir}/#{file_rel_path}"
260
+ end
261
+
262
+ def git_command__rev_list_contains?(container_sha,index_sha)
263
+ rev_list = git_command(:rev_list,container_sha)
264
+ !rev_list.split("\n").grep(index_sha).empty?()
265
+ end
266
+
267
+ #TODO: would like more efficient way of doing this as opposed to below which first produces object with full diff as opposed to summary
268
+ def any_diffs?(ref1,ref2)
269
+ not @grit_repo.diff(ref1,ref2).empty?
270
+ end
271
+
272
+ #TODO: may determine where --git-dir option makes an actual chdir unnecssary
273
+ def chdir_and_checkout(branch=nil,opts={},&block)
274
+ branch ||= @branch
275
+ chdir do
276
+ current_head = @grit_repo.head.name
277
+ git_command(:checkout,branch) unless current_head == branch
278
+ return unless block
279
+ ret = yield
280
+ unless opts[:stay_on_checkout_branch] or (current_head == branch)
281
+ git_command(:checkout,current_head)
282
+ end
283
+ ret
284
+ end
285
+ end
286
+
287
+ def chdir(&block)
288
+ unless File.directory?(@repo_dir)
289
+ raise Error.new("Trying to chdir to directory (#{@repo_dir}) that does not exist")
290
+ end
291
+ Dir.chdir(@repo_dir){yield}
292
+ end
293
+
294
+ end
295
+ end;end;end
296
+
@@ -0,0 +1,39 @@
1
+ module DTK::Common; class GritAdapter
2
+ class ObjectAccess < self
3
+ def initialize(repo_dir,branch=nil)
4
+ super
5
+ @grit_index = @grit_repo.index
6
+ end
7
+
8
+ def read_tree()
9
+ @grit_index.read_tree(@branch)
10
+ end
11
+
12
+ def add_or_replace_file(file_path,content)
13
+ @grit_index.add(file_path,content)
14
+ end
15
+
16
+ def delete_file(file_path)
17
+ @grit_index.delete(file_path)
18
+ end
19
+
20
+ def create_branch(new_branch)
21
+ if branches().include?(new_branch)
22
+ raise Error.new("Branch (#{new_branch}) already exists")
23
+ end
24
+ commit_msg = "adding new branch (#{new_branch})"
25
+ @grit_index.commit(commit_msg,@grit_repo.commits,nil,nil,new_branch)
26
+ end
27
+
28
+ def commit(commit_msg)
29
+ @grit_index.commit(commit_msg,@grit_repo.commits,nil,nil,@branch)
30
+ git_command("write-tree".to_sym)
31
+ end
32
+
33
+ def commit_context(commit_msg,&block)
34
+ read_tree()
35
+ yield
36
+ commit(commit_msg)
37
+ end
38
+ end
39
+ end;end
@@ -0,0 +1,212 @@
1
+ #TODO: should I move all methods that user grit.git to file_access?
2
+ require 'grit'
3
+ require 'fileutils'
4
+ require 'thread'
5
+
6
+ module DTK
7
+ module Common
8
+
9
+ require File.expand_path('require_first',File.dirname(__FILE__))
10
+ class GritAdapter
11
+ require File.expand_path('grit_adapter/file_access', File.dirname(__FILE__))
12
+ require File.expand_path('grit_adapter/object_access', File.dirname(__FILE__))
13
+ def initialize(repo_dir,branch=nil,opts={})
14
+ @repo_dir = repo_dir
15
+ @branch = branch
16
+ @grit_repo = nil
17
+ begin
18
+ @grit_repo = (opts[:init] ? init(repo_dir,branch,opts) : create_for_existing_repo(repo_dir,opts))
19
+ @branch ||= default_branch()
20
+ rescue ::Grit::NoSuchPathError
21
+ repo_name = repo_dir.split("/").last.gsub("\.git","")
22
+ #TODO: change to usage error
23
+ raise Error.new("repo (#{repo_name}) does not exist")
24
+ rescue => e
25
+ raise e
26
+ end
27
+ end
28
+
29
+ attr_reader :branch,:repo_dir
30
+
31
+ def self.clone(target_repo_dir,git_server_url,opts={})
32
+ if File.directory?(target_repo_dir)
33
+ if opts[:delete_if_exists]
34
+ FileUtils.rm_rf target_repo_dir
35
+ else
36
+ # raise Error.new("trying to create a repo directory (#{target_repo_dir}) that exists already")
37
+ raise DTK::Client::DtkError, "trying to create a repo directory (#{target_repo_dir}) that exists already"
38
+ end
39
+ end
40
+ clone_cmd_opts = {:raise => true, :timeout => 60}
41
+ clone_args = [git_server_url,target_repo_dir]
42
+ if branch = opts[:branch]
43
+ clone_args += ["-b",branch]
44
+ end
45
+ ::Grit::Git.new("").clone(clone_cmd_opts,*clone_args)
46
+ ret = new(*[target_repo_dir,opts[:branch]].compact)
47
+ #make sure remote branch exists; ::Grit::Git.new("").clone silently uses master if remote branch does not exist
48
+ if branch = opts[:branch]
49
+ branches = ret.branches()
50
+ unless branches.include?(opts[:branch])
51
+ FileUtils.rm_rf target_repo_dir
52
+ raise Error.new("Remote branch (#{opts[:branch]}) does not exist")
53
+ end
54
+ end
55
+ ret
56
+ end
57
+
58
+ def branches()
59
+ @grit_repo.branches.map{|h|h.name}
60
+ end
61
+
62
+ def remotes()
63
+ @grit_repo.remotes
64
+ end
65
+
66
+ def ls_r(depth=nil,opts={})
67
+ tree_contents = tree.contents
68
+ ls_r_aux(depth,tree_contents,opts)
69
+ end
70
+
71
+ def path_exists?(path)
72
+ not (tree/path).nil?
73
+ end
74
+
75
+ def file_content(path)
76
+ tree_or_blob = tree/path
77
+ tree_or_blob && tree_or_blob.kind_of?(::Grit::Blob) && tree_or_blob.data
78
+ end
79
+
80
+ def push(remote_branch_ref=nil)
81
+ remote_repo,remote_branch = parse_remote_branch_ref(remote_branch_ref)
82
+ Git_command__push_mutex.synchronize do
83
+ git_command(:push,remote_repo||"origin", "#{@branch}:refs/heads/#{remote_branch||@branch}")
84
+ end
85
+ end
86
+ Git_command__push_mutex = Mutex.new
87
+ #returns [remote_repo,remote_branch]
88
+ def parse_remote_branch_ref(remote_branch_ref)
89
+ if remote_branch_ref
90
+ split = remote_branch_ref.split("/")
91
+ case split.size
92
+ when 1 then [nil,split[0]]
93
+ when 2 then split
94
+ end
95
+ end
96
+ end
97
+ private :parse_remote_branch_ref
98
+
99
+ def add_remote?(remote_name,remote_url)
100
+ unless remote_exists?(remote_name)
101
+ add_remote(remote_name,remote_url)
102
+ end
103
+ end
104
+ def add_remote(remote_name,remote_url)
105
+ git_command(:remote,"add",remote_name,remote_url)
106
+ end
107
+ def add_or_update_remote(remote_name,remote_url)
108
+ if remote_exists?(remote_name)
109
+ git_command(:remote,"set-url",remote_name,remote_url)
110
+ else
111
+ add_remote(remote_name,remote_url)
112
+ end
113
+ end
114
+
115
+ private
116
+
117
+ def create_for_existing_repo(repo_dir,opts={})
118
+ unless File.exists?("#{repo_dir}/.git")
119
+ raise DTK::Client::DtkError, "#{repo_dir} does not contain .git folder."
120
+ end
121
+ ::Grit::Repo.new(repo_dir)
122
+ end
123
+
124
+ def init(repo_dir,branch=nil,opts={})
125
+ grit_repo = ::Grit::Repo.init(repo_dir)
126
+ if branch
127
+ Dir.chdir(repo_dir) do
128
+ git_command_during_init(grit_repo,"symbolic-ref".to_sym,"HEAD","refs/heads/#{branch}")
129
+ unless opts[:no_initial_commit]
130
+ git_command_during_init(grit_repo,:commit,"--allow-empty","-m","initialize")
131
+ end
132
+ end
133
+ end
134
+ grit_repo
135
+ end
136
+
137
+ def remote_exists?(remote_name)
138
+ ret_config_keys().include?("remote.#{remote_name}.url")
139
+ end
140
+
141
+ def ret_config_keys()
142
+ ::Grit::Config.new(@grit_repo).keys
143
+ end
144
+
145
+ def ret_config_key_value(key)
146
+ ::Grit::Config.new(@grit_repo).fetch(key)
147
+ end
148
+
149
+ def default_branch()
150
+ branches = branches()
151
+ if branches.include?('master')
152
+ return 'master'
153
+ elsif branches.size == 1
154
+ branches.first
155
+ else
156
+ raise Error.new("Cannot find a unique default branch")
157
+ end
158
+ end
159
+
160
+ def tree()
161
+ @grit_repo.tree(@branch)
162
+ end
163
+
164
+ def ls_r_aux(depth,tree_contents,opts={})
165
+ ret = Array.new
166
+ return ret if tree_contents.empty?
167
+ if depth == 1
168
+ ret = tree_contents.map do |tc|
169
+ if opts[:file_only]
170
+ tc.kind_of?(::Grit::Blob) && tc.name
171
+ elsif opts[:directory_only]
172
+ tc.kind_of?(::Grit::Tree) && tc.name
173
+ else
174
+ tc.name
175
+ end
176
+ end.compact
177
+ return ret
178
+ end
179
+
180
+ tree_contents.each do |tc|
181
+ if tc.kind_of?(::Grit::Blob)
182
+ unless opts[:directory_only]
183
+ ret << tc.name
184
+ end
185
+ else
186
+ dir_name = tc.name
187
+ ret += ls_r_aux(depth && depth-1,tc.contents).map{|r|"#{dir_name}/#{r}"}
188
+ end
189
+ end
190
+ ret
191
+ end
192
+
193
+ def git_command_status()
194
+ git_command_extra_opts(:status,:chdir => @grit_repo.working_dir)
195
+ end
196
+
197
+ def git_command_during_init(grit_repo,cmd,*args)
198
+ grit_repo.git.send(cmd, cmd_opts(),*args)
199
+ end
200
+ def git_command(cmd,*args)
201
+ @grit_repo.git.send(cmd, cmd_opts(),*args)
202
+ end
203
+ def git_command_extra_opts(cmd,*args)
204
+ extra_opts = args.pop
205
+ @grit_repo.git.send(cmd, cmd_opts().merge(extra_opts),*args)
206
+ end
207
+ def cmd_opts()
208
+ {:raise => true, :timeout => 60}
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,12 @@
1
+ module DtkCommon
2
+ class ModuleVersion
3
+
4
+ def self.string_has_version_format?(str)
5
+ !!(str =~ /\A\d{1,2}\.\d{1,2}\.\d{1,2}\Z/)
6
+ end
7
+
8
+ def self.string_master_or_emtpy?(str)
9
+ str.empty? || str.casecmp("master") || casecmp("default")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module DTK
2
+ module Common
3
+ def self.r8_require_common(path)
4
+ require File.expand_path(path, File.dirname(__FILE__))
5
+ end
6
+
7
+ def self.is_gem_installed?(gem_name)
8
+ begin
9
+ # if no exception gem is found
10
+ gem gem_name
11
+ return true
12
+ rescue Gem::LoadError
13
+ return false
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1 @@
1
+ Make into legitimate ruby unit tests
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ lib_root = '../lib'
4
+ require File.expand_path("#{lib_root}/dsl",File.dirname(__FILE__))
5
+ require 'pp'
6
+ Dir['fixtures/dsl_test1/*/*'].each do |component_module_refs_rel_path|
7
+ cmr_path = File.expand_path(component_module_refs_rel_path,File.dirname(__FILE__))
8
+ path_info = component_module_refs_rel_path.split("/")
9
+ service_mod = path_info[2]
10
+ puts "processing service module #{service_mod.gsub(/^sm-/,'')}:\n"
11
+ file_content = File.open(cmr_path).read()
12
+ pp DtkCommon::DSL::FileParser.parse_content(:component_module_refs,file_content)
13
+ puts "\n"
14
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ lib_root = '../lib'
4
+ require File.expand_path("#{lib_root}/dsl",File.dirname(__FILE__))
5
+ require 'pp'
6
+ Dir['fixtures/dsl_test2/*'].each do |service_mod_rel_path|
7
+ service_mod_path = File.expand_path(service_mod_rel_path,File.dirname(__FILE__))
8
+ dir_parser = DtkCommon::DSL::DirectoryParser::Linux.new(:service_module,service_mod_path)
9
+ pp dir_parser.parse_directory(:component_module_refs)
10
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ lib_root = '../lib'
4
+ require File.expand_path("#{lib_root}/dsl",File.dirname(__FILE__))
5
+ require 'pp'
6
+
7
+ service_repo_loc = '/home/git/repositories'
8
+
9
+ if Dir[service_repo_loc]
10
+ service_directories = Dir.entries(service_repo_loc).select {|entry| entry.to_s.include?('--sm--') }
11
+ service_directories.each do |service_repo|
12
+ dir_parser = DtkCommon::DSL::DirectoryParser::Git.new(:service_module, "#{service_repo_loc}/#{service_repo}")
13
+ pp dir_parser.parse_directory(:component_module_refs)
14
+ end
15
+ else
16
+ puts "Not able to find '#{service_repo_loc}' ment to be run on repo-manager"
17
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ lib_root = '../lib'
4
+ require File.expand_path("#{lib_root}/dsl",File.dirname(__FILE__))
5
+ require 'pp'
6
+ class DtkCommon::DSL::DirectoryParser::Git
7
+ public :all_files_from_root
8
+ end
9
+
10
+ Dir.chdir(File.dirname(__FILE__)) do
11
+ Dir['fixtures/dsl_test4/*'].each do |service_mod_rel_path|
12
+ service_mod_path = File.expand_path(service_mod_rel_path,File.dirname(__FILE__))
13
+ dir_parser = DtkCommon::DSL::DirectoryParser::Git.new(:service_module,service_mod_path)
14
+
15
+ puts "-------------------------------------------------"
16
+ puts "File: #{service_mod_rel_path.split('/').last}"
17
+ puts "File list"
18
+
19
+ pp dir_parser.all_files_from_root()
20
+ puts "----\n"
21
+ puts "Parse service_module component_module_refs"
22
+ pp dir_parser.parse_directory(:component_module_refs)
23
+ end
24
+ end
25
+
@@ -0,0 +1,7 @@
1
+ {
2
+ "component_modules": {
3
+ "gitolite" : "0.0.1",
4
+ "dtk_repo_manager": "0.0.1",
5
+ "thin": "0.0.1"
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "component_modules": {
3
+ "dtk_postgresql": "0.1.0",
4
+ "gitolite": "0.1.0",
5
+ "common_user": "0.1.0",
6
+ "dtk_server": "0.1.0"
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "component_modules": {
3
+ "concat": "0.2.0",
4
+ "dtk_postgresql": "2.2.0",
5
+ "postgresql": "2.2.0"
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "component_modules": {
3
+ "test_mod": "0.1.0"
4
+ }
5
+ }