dapp 0.29.2 → 0.30.0

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 (63) hide show
  1. checksums.yaml +5 -5
  2. data/bin/dapp +1 -23
  3. data/config/en/net_status.yml +5 -4
  4. data/lib/dapp.rb +1 -1
  5. data/lib/dapp/dapp/sentry.rb +11 -8
  6. data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +33 -21
  7. data/lib/dapp/dimg/dimg/git_artifact.rb +2 -5
  8. data/lib/dapp/dimg/git_artifact.rb +41 -23
  9. data/lib/dapp/dimg/git_repo/base.rb +19 -39
  10. data/lib/dapp/dimg/git_repo/local.rb +15 -14
  11. data/lib/dapp/dimg/git_repo/remote.rb +32 -19
  12. data/lib/dapp/kube/cli/command/kube/deploy.rb +4 -0
  13. data/lib/dapp/kube/cli/command/kube/dismiss.rb +4 -0
  14. data/lib/dapp/kube/cli/command/kube/lint.rb +4 -0
  15. data/lib/dapp/kube/cli/command/kube/render.rb +4 -0
  16. data/lib/dapp/kube/cli/command/kube/value_get.rb +4 -0
  17. data/lib/dapp/kube/dapp/command/common.rb +21 -18
  18. data/lib/dapp/kube/dapp/command/minikube_setup.rb +6 -2
  19. data/lib/dapp/kube/helm/release.rb +1 -1
  20. data/lib/dapp/kube/helm/values.rb +3 -3
  21. data/lib/dapp/kube/kubernetes/client.rb +21 -90
  22. data/lib/dapp/kube/kubernetes/config.rb +129 -0
  23. data/lib/dapp/version.rb +1 -1
  24. metadata +6 -44
  25. data/lib/dapp/deployment/app.rb +0 -120
  26. data/lib/dapp/deployment/cli/cli.rb +0 -1
  27. data/lib/dapp/deployment/cli/command/base.rb +0 -14
  28. data/lib/dapp/deployment/cli/command/deployment.rb +0 -18
  29. data/lib/dapp/deployment/cli/command/deployment/apply.rb +0 -26
  30. data/lib/dapp/deployment/cli/command/deployment/mrproper.rb +0 -13
  31. data/lib/dapp/deployment/config/config.rb +0 -46
  32. data/lib/dapp/deployment/config/directive/app.rb +0 -28
  33. data/lib/dapp/deployment/config/directive/app/instance_methods.rb +0 -51
  34. data/lib/dapp/deployment/config/directive/base.rb +0 -13
  35. data/lib/dapp/deployment/config/directive/deployment.rb +0 -11
  36. data/lib/dapp/deployment/config/directive/expose.rb +0 -68
  37. data/lib/dapp/deployment/config/directive/group.rb +0 -27
  38. data/lib/dapp/deployment/config/directive/job.rb +0 -28
  39. data/lib/dapp/deployment/config/directive/mod/group.rb +0 -22
  40. data/lib/dapp/deployment/config/directive/mod/jobs.rb +0 -26
  41. data/lib/dapp/deployment/config/directive/namespace.rb +0 -26
  42. data/lib/dapp/deployment/config/directive/namespace/instance_methods.rb +0 -37
  43. data/lib/dapp/deployment/core_ext/hash.rb +0 -19
  44. data/lib/dapp/deployment/dapp/command/apply.rb +0 -71
  45. data/lib/dapp/deployment/dapp/command/common.rb +0 -17
  46. data/lib/dapp/deployment/dapp/command/mrproper.rb +0 -12
  47. data/lib/dapp/deployment/dapp/dapp.rb +0 -15
  48. data/lib/dapp/deployment/dapp/dappfile.rb +0 -23
  49. data/lib/dapp/deployment/deployment.rb +0 -46
  50. data/lib/dapp/deployment/error/app.rb +0 -7
  51. data/lib/dapp/deployment/error/default.rb +0 -7
  52. data/lib/dapp/deployment/error/deployment.rb +0 -7
  53. data/lib/dapp/deployment/error/kubernetes.rb +0 -7
  54. data/lib/dapp/deployment/kube_app.rb +0 -146
  55. data/lib/dapp/deployment/kube_base.rb +0 -97
  56. data/lib/dapp/deployment/kube_deployment.rb +0 -51
  57. data/lib/dapp/deployment/kubernetes.rb +0 -174
  58. data/lib/dapp/deployment/kubernetes/error.rb +0 -20
  59. data/lib/dapp/deployment/mod/jobs.rb +0 -37
  60. data/lib/dapp/deployment/mod/namespace.rb +0 -58
  61. data/lib/dapp/deployment/mod/system_environments.rb +0 -30
  62. data/lib/dapp/deployment/secret.rb +0 -93
  63. data/lib/dapp/kube/error/kubernetes.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: aca77a164ea6ba0c0cfaebd85974916fee6ece90215572ec4b69a4f525d4b343
4
- data.tar.gz: 4b25cc1076c2130714b2210c22ac11ad59697af51bd60e91c0142e9d595bddbd
2
+ SHA1:
3
+ metadata.gz: 259d9afe89f767678121d96c8ef2b64c1521207c
4
+ data.tar.gz: 667396adfa0c4f566621b4ed577636e1e82df25a
5
5
  SHA512:
6
- metadata.gz: 36d882416ba486c071fe29f7891a5f96e8bd95e68d2e55b2d5bc2a8adf7e8bc470128a5d89853f9bb65b2b040abee2c5a779edeb3f7841130793ded23887d220
7
- data.tar.gz: 65037b3db41398af71370f9ae8c2eb6769f96b3d3896f45bb479b5226550331e12b80aaac493c2627f02be2d42eabfcbb266a8926f626a86945276671ef6439b
6
+ metadata.gz: 434fe4c12cdc155d0ce888cce71948ac9fdf29daafcc8327d64d7649b78df948205ea76a2ee777488e1d12f32273178f5e7f03a64671cb5727b3bb207dd91cef
7
+ data.tar.gz: 97a9dc7ae4e16c42cb1e9002e8eff1dc90d572a013288638b2fc61a124862d37b5089f4f0d7afec841fdfa0413aba323033922b5ba54e8f002bda9cdcd030ed7
data/bin/dapp CHANGED
@@ -10,29 +10,7 @@ Thread.abort_on_exception = true
10
10
  begin
11
11
  begin
12
12
  begin
13
- begin
14
- Dapp::CLI.new.run
15
- ensure
16
- if Time.now.to_date < Date.parse("2019-11-01")
17
- STDERR.puts
18
- STDERR.puts ::Paint["###################################################################", :red, :bold]
19
- STDERR.puts ::Paint["### DEPRECATION WARNING! ###", :red, :bold]
20
- STDERR.puts ::Paint["### Dapp will be deprecated for use starting with 01.11.2019! ###", :red, :bold]
21
- STDERR.puts ::Paint["### Please port your project to werf: ###", :red, :bold]
22
- STDERR.puts ::Paint["### https://werf.io ###", :red, :bold]
23
- STDERR.puts ::Paint["###################################################################", :red, :bold]
24
- STDERR.puts
25
- else
26
- STDERR.puts
27
- STDERR.puts ::Paint["######################################################################", :red, :bold]
28
- STDERR.puts ::Paint["### DEPRECATION WARNING! ###", :red, :bold]
29
- STDERR.puts ::Paint["### Dapp is deprecated for use and will not receive any support! ###", :red, :bold]
30
- STDERR.puts ::Paint["### Please port your project to werf: ###", :red, :bold]
31
- STDERR.puts ::Paint["### https://werf.io ###", :red, :bold]
32
- STDERR.puts ::Paint["######################################################################", :red, :bold]
33
- STDERR.puts
34
- end
35
- end
13
+ Dapp::CLI.new.run
36
14
  rescue Dapp::Error::Base => e
37
15
  unless (message = Dapp::Helper::NetStatus.before_error_message(e)).empty?
38
16
  $stderr.puts(message)
@@ -136,10 +136,11 @@ en:
136
136
  namespace_not_found: "App `%{name}`: namespace `%{namespace}` not found!"
137
137
  namespace_not_defined: "App `%{name}`: namespace not defined!"
138
138
  kubernetes:
139
- config_not_found: "Kube config `%{config_path}` not found!"
140
- user_config_not_found: "User's `%{user}` config is not found in config %{config_path}"
141
- cluster_config_not_found: "Cluster's `%{cluster}` config is not found in config %{config_path}"
142
- config_context_not_found: "Context `%{context_name}` is not found in config %{config_path}"
139
+ config_not_found: "Kube config not found in: KUBECONFIG, kubectl (through `kubectl config view`), `~/.kube/config`"
140
+ config_file_not_found: "Kube config file `%{config_path}` not found!"
141
+ user_config_not_found: "User's `%{user}` config is not found in config `%{config_path}`"
142
+ cluster_config_not_found: "Cluster's `%{cluster}` config is not found in config `%{config_path}`"
143
+ context_config_not_found: "Context `%{context_name}` is not found in config `%{config_path}`"
143
144
  server_connection_refused: "Kube server `%{url}` connection refused: %{error}"
144
145
  server_error: "Kube respond with server error code %{response_http_status}, request parameters: `%{request_parameters}`, response: `%{response_raw_body}`"
145
146
  container_stuck: "Pod's `%{pod_name}` container `%{container_name}` stuck in %{state} state: %{state_reason}: %{state_message}"
@@ -83,10 +83,10 @@ require 'dapp/dapp/command/slug'
83
83
  require 'dapp/dapp'
84
84
  require 'dapp/kube'
85
85
  require 'dapp/kube/error/default'
86
- require 'dapp/kube/error/kubernetes'
87
86
  require 'dapp/kube/secret'
88
87
  require 'dapp/kube/kubernetes'
89
88
  require 'dapp/kube/kubernetes/error'
89
+ require 'dapp/kube/kubernetes/config'
90
90
  require 'dapp/kube/kubernetes/client'
91
91
  require 'dapp/kube/kubernetes/client/error'
92
92
  require 'dapp/kube/kubernetes/client/resource/base'
@@ -56,13 +56,16 @@ module Dapp
56
56
  },
57
57
  }.tap {|extra|
58
58
  if git_own_repo_exist?
59
- extra["git"] = {
60
- "remote_origin_url" => git_own_repo.remote_origin_url, # may contain https token
61
- "name" => self.git_url_to_name(git_own_repo.remote_origin_url),
62
- "path" => git_own_repo.path,
63
- "workdir_path" => git_own_repo.workdir_path,
64
- "latest_commit" => git_own_repo.latest_commit,
65
- }
59
+ extra["git"] = {}.tap do |extra_git|
60
+ if git_own_repo.tracked_remote_repository?
61
+ extra_git["remote_origin_url"] = git_own_repo.remote_origin_url, # may contain https token
62
+ extra_git["name"] = self.git_url_to_name(git_own_repo.remote_origin_url)
63
+ end
64
+
65
+ extra_git["path"] = git_own_repo.path
66
+ extra_git["workdir_path"] = git_own_repo.workdir_path
67
+ extra_git["latest_commit"] = git_own_repo.latest_commit unless git_own_repo.empty?
68
+ end
66
69
  end
67
70
 
68
71
  extra["ci-env"] = {"CI" => ENV["CI"]}
@@ -80,7 +83,7 @@ module Dapp
80
83
  "dapp-build-cache-version" => ::Dapp::BUILD_CACHE_VERSION,
81
84
  "dapp-command" => self.options[:dapp_command],
82
85
  }.tap {|tags|
83
- if git_own_repo_exist?
86
+ if git_own_repo_exist? && git_own_repo.tracked_remote_repository?
84
87
  tags["git-host"] = self.get_host_from_git_url(git_own_repo.remote_origin_url)
85
88
 
86
89
  git_name = self.git_url_to_name(git_own_repo.remote_origin_url)
@@ -9,6 +9,12 @@ module Dapp
9
9
  def cleanup_repo
10
10
  lock_repo(repo = option_repo) do
11
11
  log_step_with_indent(repo) do
12
+ log_step_with_indent("Searching for images being used in kubernetes clusters in one of the kube-config contexts") do
13
+ deployed_docker_images.each do |deployed_img|
14
+ log(deployed_img)
15
+ end
16
+ end
17
+
12
18
  registry = dimg_registry(repo)
13
19
 
14
20
  if git_own_repo_exist?
@@ -29,18 +35,21 @@ module Dapp
29
35
  {}.tap do |detailed_dimgs_images_by_scheme|
30
36
  tagging_schemes.each { |scheme| detailed_dimgs_images_by_scheme[scheme] = [] }
31
37
  repo_detailed_dimgs_images(registry).each do |image|
32
- next unless repo_dimg_image_should_be_ignored?(image)
38
+ image_repository = [option_repo, image[:dimg]].compact.join('/')
39
+ image_name = [image_repository, image[:tag]].join(':')
40
+
41
+ should_be_ignored = deployed_docker_images.include?(image_name)
42
+
43
+ if should_be_ignored
44
+ log "Keep in repo image that is being used in kubernetes: #{image_name}"
45
+ next
46
+ end
47
+
33
48
  (detailed_dimgs_images_by_scheme[image[:labels]['dapp-tag-scheme']] ||= []) << image
34
49
  end
35
50
  end
36
51
  end
37
52
 
38
- def repo_dimg_image_should_be_ignored?(image)
39
- image_repository = [option_repo, image[:dimg]].compact.join('/')
40
- image_name = [image_repository, image[:tag]].join(':')
41
- !deployed_docker_images.include?(image_name)
42
- end
43
-
44
53
  def cleanup_repo_by_nonexistent_git_primitive(registry, detailed_dimgs_images_by_scheme)
45
54
  %w(git_tag git_branch git_commit).each do |scheme|
46
55
  cleanup_repo_by_nonexistent_git_base(detailed_dimgs_images_by_scheme, scheme) do |detailed_dimg_image|
@@ -117,18 +126,23 @@ module Dapp
117
126
  end
118
127
 
119
128
  def deployed_docker_images
129
+ @deployed_docker_images ||= search_deployed_docker_images
130
+ end
131
+
132
+ def search_deployed_docker_images
120
133
  return [] if without_kube?
121
134
 
122
- # open kube client, get all pods and select containers' images
123
- ::Dapp::Kube::Kubernetes::Client.tap do |kube|
124
- config_file = kube.kube_config_path
125
- unless File.exist?(config_file)
126
- return []
127
- end
128
- end
135
+ config = ::Dapp::Kube::Kubernetes::Config.new_auto_if_available
136
+ return [] if config.nil?
129
137
 
130
- client = ::Dapp::Kube::Kubernetes::Client.new
138
+ config.context_names.
139
+ map {|context_name|
140
+ client = ::Dapp::Kube::Kubernetes::Client.new(config, context_name, "default")
141
+ search_deployed_docker_images_from_kube(client)
142
+ }.flatten.sort.uniq
143
+ end
131
144
 
145
+ def search_deployed_docker_images_from_kube(client)
132
146
  namespaces = []
133
147
  # check connectivity for 2 seconds
134
148
  begin
@@ -138,7 +152,7 @@ module Dapp
138
152
  end
139
153
 
140
154
  # get images from containers from pods from all namespaces.
141
- @kube_images ||= namespaces['items'].map do |item|
155
+ namespaces['items'].map do |item|
142
156
  item['metadata']['name']
143
157
  end.map do |ns|
144
158
  [].tap do |arr|
@@ -152,9 +166,9 @@ module Dapp
152
166
  arr << replicationcontroller_images(client)
153
167
  end
154
168
  end
155
- end.flatten.uniq.select do |image|
156
- image.start_with?(option_repo)
157
- end
169
+ end.flatten.select do |img|
170
+ img.start_with? option_repo
171
+ end.sort.uniq
158
172
  end
159
173
 
160
174
  # pod items[] spec containers[] image
@@ -206,8 +220,6 @@ module Dapp
206
220
  end
207
221
  end
208
222
 
209
-
210
-
211
223
  def without_kube?
212
224
  !!options[:without_kube]
213
225
  end
@@ -19,10 +19,7 @@ module Dapp
19
19
  def remote_git_artifacts
20
20
  @remote_git_artifact_list ||= [].tap do |artifacts|
21
21
  Array(config._git_artifact._remote).each do |ga_config|
22
- repo = GitRepo::Remote.get_or_create(dapp, ga_config._name,
23
- url: ga_config._url,
24
- branch: ga_config._branch,
25
- ignore_git_fetch: ignore_git_fetch)
22
+ repo = GitRepo::Remote.get_or_create(dapp, ga_config._name, url: ga_config._url, ignore_git_fetch: ignore_git_fetch)
26
23
  artifacts.concat(generate_git_artifacts(repo, **ga_config._artifact_options)) unless repo.empty?
27
24
  end
28
25
  end
@@ -30,7 +27,7 @@ module Dapp
30
27
 
31
28
  def generate_git_artifacts(repo, **git_artifact_options)
32
29
  [].tap do |artifacts|
33
- artifacts << (artifact = ::Dapp::Dimg::GitArtifact.new(repo, self, **git_artifact_options))
30
+ artifacts << (artifact = ::Dapp::Dimg::GitArtifact.new(repo, self, ignore_signature_auto_calculation: ignore_signature_auto_calculation, **git_artifact_options))
34
31
  if ENV['DAPP_DISABLE_GIT_SUBMODULES']
35
32
  artifacts
36
33
  else
@@ -14,11 +14,13 @@ module Dapp
14
14
  # rubocop:disable Metrics/ParameterLists
15
15
  def initialize(repo, dimg, to:, name: nil, branch: nil, commit: nil,
16
16
  cwd: nil, include_paths: nil, exclude_paths: nil, owner: nil, group: nil, as: nil,
17
- stages_dependencies: {})
17
+ stages_dependencies: {}, ignore_signature_auto_calculation: false)
18
18
  @repo = repo
19
19
  @dimg = dimg
20
20
  @name = name
21
21
 
22
+ @ignore_signature_auto_calculation = ignore_signature_auto_calculation
23
+
22
24
  @branch = branch || repo.dapp.options[:git_artifact_branch] || repo.branch
23
25
  @commit = commit
24
26
 
@@ -70,10 +72,7 @@ module Dapp
70
72
  embedded_rel_path = embedded_params[:path]
71
73
  embedded_repo = begin
72
74
  if embedded_params[:type] == :remote
73
- GitRepo::Remote.get_or_create(repo.dapp, embedded_rel_path,
74
- url: embedded_params[:url],
75
- branch: embedded_params[:branch],
76
- ignore_git_fetch: dimg.ignore_git_fetch )
75
+ GitRepo::Remote.get_or_create(repo.dapp, embedded_rel_path, url: embedded_params[:url], ignore_git_fetch: dimg.ignore_git_fetch)
77
76
  elsif embedded_params[:type] == :local
78
77
  embedded_path = File.join(repo.workdir_path, embedded_params[:path])
79
78
  GitRepo::Local.new(repo.dapp, embedded_rel_path, embedded_path)
@@ -104,8 +103,11 @@ module Dapp
104
103
  .to_h
105
104
  end
106
105
  options[:branch] = embedded_params[:branch]
106
+ options[:commit] = embedded_params[:commit]
107
107
  options[:owner] = owner
108
108
  options[:group] = group
109
+
110
+ options[:ignore_signature_auto_calculation]= ignore_signature_auto_calculation
109
111
  end
110
112
  end
111
113
 
@@ -288,7 +290,11 @@ module Dapp
288
290
  end
289
291
 
290
292
  def latest_commit
291
- @latest_commit ||= (commit || repo.latest_commit(branch))
293
+ @latest_commit ||= begin
294
+ (commit || repo.latest_commit(branch)).tap do |c|
295
+ repo.dapp.log_info("Repository `#{repo.name}`: latest commit `#{c}` to `#{to}`") unless ignore_signature_auto_calculation
296
+ end
297
+ end
292
298
  end
293
299
 
294
300
  def paramshash
@@ -325,6 +331,7 @@ module Dapp
325
331
  attr_reader :owner
326
332
  attr_reader :group
327
333
  attr_reader :stages_dependencies
334
+ attr_reader :ignore_signature_auto_calculation
328
335
 
329
336
  def sudo
330
337
  repo.dapp.sudo_command(owner: owner, group: group)
@@ -409,33 +416,40 @@ module Dapp
409
416
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
410
417
  def change_patch_new_file_path(stage, patch)
411
418
  patch.to_s.lines.tap do |lines|
419
+ prepare_native_path = proc do |path_with_cwd|
420
+ case archive_type(stage)
421
+ when :directory
422
+ path_with_cwd.sub(cwd, '')
423
+ when :file
424
+ File.basename(to)
425
+ else
426
+ raise
427
+ end
428
+ end
429
+
412
430
  modify_patch_line = proc do |line_number, path_char|
413
431
  action_part, path_part = lines[line_number].strip.split(' ', 2)
414
432
  if (path_with_cwd = path_part.partition("#{path_char}/").last).start_with?(cwd)
415
- native_path = case archive_type(stage)
416
- when :directory
417
- path_with_cwd.sub(cwd, '')
418
- when :file
419
- File.basename(to)
420
- else
421
- raise
422
- end
423
-
424
- if native_path
425
- expected_path = File.join(path_char, native_path)
426
- lines[line_number] = [action_part, expected_path].join(' ') + "\n"
433
+ prepare_native_path.call(path_with_cwd).tap do |native_path|
434
+ if native_path
435
+ expected_path = File.join(path_char, native_path)
436
+ lines[line_number] = [action_part, expected_path].join(' ') + "\n"
437
+ end
427
438
  end
428
-
429
- native_path
430
439
  end
431
440
  end
432
441
 
442
+ modify_patch_first_line = proc do
443
+ old_file_path = prepare_native_path.call(patch.delta.old_file[:path])
444
+ new_file_path = prepare_native_path.call(patch.delta.new_file[:path])
445
+ lines[0] = ['diff --git', File.join('a', old_file_path), File.join('b', new_file_path)].join(' ') + "\n"
446
+ end
447
+
433
448
  modify_patch = proc do |*modify_patch_line_args|
434
449
  native_paths = modify_patch_line_args.map { |args| modify_patch_line.call(*args) }
435
450
  unless (native_paths = native_paths.compact.uniq).empty?
436
451
  raise Error::Build, code: :unsupported_patch_format, data: { patch: patch.to_s } unless native_paths.one?
437
- native_path = native_paths.first
438
- lines[0] = ['diff --git', File.join('a', native_path), File.join('b', native_path)].join(' ') + "\n"
452
+ modify_patch_first_line.call
439
453
  end
440
454
  end
441
455
 
@@ -444,7 +458,11 @@ module Dapp
444
458
  when patch.delta.added? then modify_patch.call([4, 'b'])
445
459
  when patch.delta.modified?
446
460
  if patch_file_mode_changed?(patch)
447
- modify_patch.call([4, 'a'], [5, 'b'])
461
+ if patch.changes.zero?
462
+ modify_patch_first_line.call
463
+ else
464
+ modify_patch.call([4, 'a'], [5, 'b'])
465
+ end
448
466
  else
449
467
  modify_patch.call([2, 'a'], [3, 'b'])
450
468
  end
@@ -49,50 +49,26 @@ module Dapp
49
49
  end
50
50
 
51
51
  def submodules_params(commit, paths: [], exclude_paths: [])
52
- raise "Workdir not supported for #{self.class}" if commit.nil?
52
+ raise "Workdir not supported for `#{self.class}` repository" if commit.nil?
53
+ submodules(commit, paths: paths, exclude_paths: exclude_paths).map(&method(:submodule_params))
54
+ end
53
55
 
54
- entry = begin
55
- lookup_commit(commit).tree.path('.gitmodules')
56
- rescue Rugged::TreeError
57
- return []
56
+ def submodule_params(submodule)
57
+ {}.tap do |params|
58
+ params[:path] = submodule.path
59
+ params[:url] = submodule_url(submodule.url)
60
+ params[:type] = url_protocol(params[:url]) == :noname ? :local : :remote
61
+ params[:commit] = submodule.head_oid
58
62
  end
59
-
60
- submodules_params_base(lookup_object(entry[:oid]).content, paths: paths, exclude_paths: exclude_paths)
61
63
  end
62
64
 
63
- def submodules_params_base(gitsubmodule_content, paths: [], exclude_paths: [])
64
- submodules_file_parse!(gitsubmodule_content)
65
- .select { |_, params| !ignore_directory?(params['path'], paths: paths, exclude_paths: exclude_paths) }
66
- .map do |_, params|
67
- params = params.symbolize_keys
68
- params[:branch] = params[:branch].to_s if params.key?(:branch)
69
- params[:url] = submodule_url(params[:url])
70
- params[:type] = url_protocol(params[:url]) == :noname ? :local : :remote
71
- params
72
- end
65
+ def submodules(commit, paths: [], exclude_paths: [])
66
+ Rugged::SubmoduleCollection.new(submodules_git(commit))
67
+ .select { |s| !ignore_directory?(s.path, paths: paths, exclude_paths: exclude_paths) }
73
68
  end
74
69
 
75
- def submodules_file_parse!(gitsubmodule_content)
76
- raise_error = proc do |error_message|
77
- raise Error::Rugged, code: :incorrect_gitmodules_file, data: { name: self.name,
78
- error: error_message,
79
- content: gitsubmodule_content.strip }
80
- end
81
-
82
- begin
83
- IniFile.new.parse(gitsubmodule_content).to_h.tap do |submodules_params|
84
- submodules_params.each do |name, params|
85
- %w(path url).each do |field|
86
- next unless params[field].nil? || params[field].empty?
87
- raise_error.call("field `#{field}` required (#{name})")
88
- end
89
-
90
- raise_error.call("path should be relative (#{name})") unless Pathname(params['path']).relative?
91
- end
92
- end
93
- rescue IniFile::Error => e
94
- raise_error.call(e.message)
95
- end
70
+ def submodules_git(_)
71
+ git
96
72
  end
97
73
 
98
74
  def submodule_url(gitsubmodule_url)
@@ -178,7 +154,7 @@ module Dapp
178
154
  .select { |b| b.start_with?('origin/') }
179
155
  .map { |b| b.reverse.chomp('origin/'.reverse).reverse }
180
156
  end
181
-
157
+
182
158
  def find_commit_id_by_message(regex)
183
159
  walker.each do |commit|
184
160
  msg = commit.message.encode('UTF-8', invalid: :replace, undef: :replace)
@@ -204,6 +180,10 @@ module Dapp
204
180
  git.empty?
205
181
  end
206
182
 
183
+ def tracked_remote_repository?
184
+ !git.remotes.to_a.empty?
185
+ end
186
+
207
187
  protected
208
188
 
209
189
  def git(**kwargs)
@@ -26,22 +26,20 @@ module Dapp
26
26
  end
27
27
  end
28
28
 
29
- # NOTICE: Параметры {from: nil, to: nil} можно указать только для Own repo.
30
- # NOTICE: Для Remote repo такой вызов не имеет смысла и это ошибка пользователя класса Remote.
31
-
32
29
  def submodules_params(commit, paths: [], exclude_paths: [])
33
- return super unless commit.nil?
34
- return [] unless File.file?((gitmodules_file_path = File.join(workdir_path, '.gitmodules')))
35
-
36
- submodules_params_base(File.read(gitmodules_file_path),
37
- paths: paths,
38
- exclude_paths: exclude_paths).each do |submodule_params|
39
- submodule_path = File.join(workdir_path, submodule_params[:path])
40
- if git_repo_exist?(submodule_path)
41
- dapp.log_info("Using local submodule `#{submodule_path}`!")
42
- submodule_params[:type] = :local
30
+ submodules(commit, paths: paths, exclude_paths: exclude_paths).map do |submodule|
31
+ next if commit.nil? && !submodule.in_config?
32
+ submodule_params(submodule).tap do |params|
33
+ if commit.nil?
34
+ submodule_path = File.join(workdir_path, params[:path])
35
+ params[:commit] = submodule.workdir_oid || submodule.head_oid
36
+ if git_repo_exist?(submodule_path)
37
+ dapp.log_info("Using local submodule `#{params[:path]}`!")
38
+ params[:type] = :local
39
+ end
40
+ end
43
41
  end
44
- end
42
+ end.compact
45
43
  end
46
44
 
47
45
  def ignore_patch?(patch, paths: [], exclude_paths: [])
@@ -58,6 +56,9 @@ module Dapp
58
56
  mode == 0o040000
59
57
  end
60
58
 
59
+ # NOTICE: Параметры {from: nil, to: nil} можно указать только для Own repo.
60
+ # NOTICE: Для Remote repo такой вызов не имеет смысла и это ошибка пользователя класса Remote.
61
+
61
62
  def diff(from, to, **kwargs)
62
63
  if from.nil? and to.nil?
63
64
  mid_commit = latest_commit