eac_tools 0.34.0 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +32 -18
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +1 -1
  5. data/sub/{avm-tools → avm}/lib/avm/launcher/context/instance_collector.rb +0 -0
  6. data/sub/{avm-tools → avm}/lib/avm/launcher/context/instance_discovery.rb +0 -0
  7. data/sub/{avm-tools → avm}/lib/avm/launcher/context/instance_manager/cached_instance.rb +0 -0
  8. data/sub/{avm-tools → avm}/lib/avm/launcher/context/instance_manager/cached_instances.rb +0 -0
  9. data/sub/{avm-tools → avm}/lib/avm/launcher/context/instance_manager.rb +0 -0
  10. data/sub/{avm-tools → avm}/lib/avm/launcher/context/settings.rb +0 -0
  11. data/sub/{avm-tools → avm}/lib/avm/launcher/context.rb +0 -0
  12. data/sub/avm/lib/avm/launcher/errors.rb +11 -0
  13. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/base/cache.rb +0 -0
  14. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/base.rb +0 -0
  15. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/error.rb +0 -0
  16. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/runner_helper.rb +0 -0
  17. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/settings.rb +0 -0
  18. data/sub/avm/lib/avm/launcher/instances.rb +11 -0
  19. data/sub/{avm-tools → avm}/lib/avm/launcher/paths/logical.rb +0 -0
  20. data/sub/avm/lib/avm/launcher/paths.rb +11 -0
  21. data/sub/{avm-tools → avm}/lib/avm/launcher/project.rb +4 -5
  22. data/sub/{avm-tools → avm}/lib/avm/launcher/publish/base.rb +2 -5
  23. data/sub/avm/lib/avm/launcher/publish.rb +11 -0
  24. data/sub/avm/lib/avm/launcher.rb +9 -0
  25. data/sub/avm/lib/avm/registry.rb +0 -2
  26. data/sub/avm/lib/avm/version.rb +1 -1
  27. data/sub/avm-eac_php_base0/Gemfile +8 -0
  28. data/sub/avm-eac_php_base0/avm-eac_php_base0.gemspec +18 -0
  29. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/version.rb +7 -0
  30. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0.rb +9 -0
  31. data/sub/avm-eac_php_base0/spec/rubocop_spec.rb +3 -0
  32. data/sub/avm-eac_php_base0/spec/spec_helper.rb +4 -0
  33. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +1 -1
  34. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/apache_host.rb +2 -1
  35. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/deploy/git_info.rb +2 -1
  36. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/deploy.rb +0 -1
  37. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  38. data/sub/avm-git/Gemfile +8 -0
  39. data/sub/avm-git/avm-git.gemspec +22 -0
  40. data/sub/avm-git/lib/avm/git/auto_commit/commit_info.rb +23 -0
  41. data/sub/avm-git/lib/avm/git/auto_commit/rules/base.rb +39 -0
  42. data/sub/avm-git/lib/avm/git/auto_commit/rules/last.rb +19 -0
  43. data/sub/avm-git/lib/avm/git/auto_commit/rules/manual.rb +45 -0
  44. data/sub/avm-git/lib/avm/git/auto_commit/rules/new.rb +24 -0
  45. data/sub/avm-git/lib/avm/git/auto_commit/rules/nth.rb +31 -0
  46. data/sub/avm-git/lib/avm/git/auto_commit/rules/unique.rb +21 -0
  47. data/sub/avm-git/lib/avm/git/auto_commit/rules.rb +31 -0
  48. data/sub/avm-git/lib/avm/git/auto_commit_path/ruby.rb +20 -0
  49. data/sub/avm-git/lib/avm/git/auto_commit_path.rb +28 -0
  50. data/sub/avm-git/lib/avm/git/commit/class_methods.rb +31 -0
  51. data/sub/avm-git/lib/avm/git/commit/deploy.rb +38 -0
  52. data/sub/avm-git/lib/avm/git/commit/deploy_methods.rb +19 -0
  53. data/sub/avm-git/lib/avm/git/commit/diff_tree_line.rb +32 -0
  54. data/sub/avm-git/lib/avm/git/commit/file.rb +46 -0
  55. data/sub/avm-git/lib/avm/git/commit.rb +59 -0
  56. data/sub/avm-git/lib/avm/git/file_auto_fixup.rb +83 -0
  57. data/sub/avm-git/lib/avm/git/issue/complete/commits.rb +42 -0
  58. data/sub/avm-git/lib/avm/git/issue/complete/git_subrepos.rb +23 -0
  59. data/sub/avm-git/lib/avm/git/issue/complete/local_branch.rb +61 -0
  60. data/sub/avm-git/lib/avm/git/issue/complete/local_tag.rb +39 -0
  61. data/sub/avm-git/lib/avm/git/issue/complete/push.rb +60 -0
  62. data/sub/avm-git/lib/avm/git/issue/complete/remote.rb +33 -0
  63. data/sub/avm-git/lib/avm/git/issue/complete/test.rb +40 -0
  64. data/sub/avm-git/lib/avm/git/issue/complete/tracker.rb +28 -0
  65. data/sub/avm-git/lib/avm/git/issue/complete/validation.rb +39 -0
  66. data/sub/avm-git/lib/avm/git/issue/complete/validations.rb +53 -0
  67. data/sub/avm-git/lib/avm/git/issue/complete/working_tree.rb +19 -0
  68. data/sub/avm-git/lib/avm/git/issue/complete.rb +66 -0
  69. data/sub/avm-git/lib/avm/git/issue/deliver.rb +56 -0
  70. data/sub/{avm-tools/lib/avm/patches.rb → avm-git/lib/avm/git/issue.rb} +3 -1
  71. data/sub/avm-git/lib/avm/git/organize/reference_update.rb +34 -0
  72. data/sub/avm-git/lib/avm/git/organize/repository.rb +76 -0
  73. data/sub/avm-git/lib/avm/git/organize.rb +11 -0
  74. data/sub/avm-git/lib/avm/git/revision_test.rb +105 -0
  75. data/sub/avm-git/lib/avm/git/scms/git/change_tracker.rb +35 -0
  76. data/sub/avm-git/lib/avm/git/scms/git/commit.rb +55 -0
  77. data/sub/avm-git/lib/avm/git/scms/git.rb +73 -0
  78. data/sub/avm-git/lib/avm/git/scms/git_subrepo.rb +39 -0
  79. data/sub/avm-git/lib/avm/git/scms/provider.rb +19 -0
  80. data/sub/avm-git/lib/avm/git/scms.rb +11 -0
  81. data/sub/avm-git/lib/avm/git/subrepo_check/parent.rb +51 -0
  82. data/sub/avm-git/lib/avm/git/subrepo_check/remote.rb +89 -0
  83. data/sub/avm-git/lib/avm/git/subrepo_check/show_result.rb +32 -0
  84. data/sub/avm-git/lib/avm/git/subrepo_check.rb +38 -0
  85. data/sub/avm-git/lib/avm/git/subrepo_checks.rb +59 -0
  86. data/sub/{avm-tools/lib/avm/launcher → avm-git/lib/avm/git}/vendor/github.rb +1 -1
  87. data/sub/avm-git/lib/avm/git/vendor.rb +11 -0
  88. data/sub/avm-git/lib/avm/git/version.rb +7 -0
  89. data/sub/avm-git/lib/avm/git.rb +11 -0
  90. data/sub/avm-git/spec/lib/avm/git/auto_commit_path_spec.rb +21 -0
  91. data/sub/avm-git/spec/lib/avm/git/commit/deploy_spec.rb +93 -0
  92. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec.rb +13 -0
  93. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/add.source.out +1 -0
  94. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/add.target.yaml +7 -0
  95. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/modify.source.out +1 -0
  96. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/modify.target.yaml +7 -0
  97. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/remove.source.out +1 -0
  98. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/remove.target.yaml +7 -0
  99. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename.source.out +2 -0
  100. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename.target.yaml +13 -0
  101. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename_modify.source.out +2 -0
  102. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename_modify.target.yaml +13 -0
  103. data/sub/avm-git/spec/lib/avm/git/commit_spec.rb +56 -0
  104. data/sub/avm-git/spec/lib/avm/git/scms/git_spec.rb +8 -0
  105. data/sub/avm-git/spec/lib/avm/git/scms/git_subrepo_spec.rb +8 -0
  106. data/sub/{avm-tools/spec/lib/avm/launcher → avm-git/spec/lib/avm/git}/vendor/github_spec.rb +4 -4
  107. data/sub/avm-git/spec/rubocop_spec.rb +3 -0
  108. data/sub/avm-git/spec/spec_helper.rb +4 -0
  109. data/sub/avm-tools/avm-tools.gemspec +3 -3
  110. data/sub/avm-tools/lib/avm/launcher/git/warp_base.rb +2 -2
  111. data/sub/avm-tools/lib/avm/projects/stereotypes/git_subrepo/warp.rb +2 -2
  112. data/sub/avm-tools/lib/avm/projects/stereotypes.rb +0 -9
  113. data/sub/avm-tools/lib/avm/tools/core_ext.rb +0 -1
  114. data/sub/avm-tools/lib/avm/tools/runner/launcher.rb +1 -0
  115. data/sub/avm-tools/lib/avm/tools/runner/source/info.rb +0 -4
  116. data/sub/avm-tools/lib/avm/tools/runner/source/test.rb +1 -1
  117. data/sub/avm-tools/lib/avm/tools/runner/source.rb +0 -12
  118. data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
  119. data/sub/avm-tools/spec/lib/avm/launcher/context_spec.rb +3 -3
  120. data/sub/eac_docker/eac_docker.gemspec +2 -2
  121. data/sub/eac_docker/lib/eac_docker/images/templatized.rb +7 -1
  122. data/sub/eac_docker/lib/eac_docker/version.rb +1 -1
  123. metadata +123 -37
  124. data/sub/avm-tools/lib/avm/launcher/instances.rb +0 -6
  125. data/sub/avm-tools/lib/avm/launcher/paths.rb +0 -4
  126. data/sub/avm-tools/lib/avm/launcher/publish.rb +0 -4
  127. data/sub/avm-tools/lib/avm/launcher/vendor.rb +0 -3
  128. data/sub/avm-tools/lib/avm/patches/i18n.rb +0 -22
  129. data/sub/avm-tools/lib/avm/projects/stereotype/job_comparator.rb +0 -32
  130. data/sub/avm-tools/lib/avm/projects/stereotypes/rails_application/local_project_mixin.rb +0 -18
  131. data/sub/avm-tools/lib/avm/projects/stereotypes/rails_application.rb +0 -25
  132. data/sub/avm-tools/lib/avm/projects/stereotypes/redmine_plugin.rb +0 -23
  133. data/sub/avm-tools/lib/avm/stereotypes.rb +0 -9
  134. data/sub/avm-tools/lib/avm/tools/source.rb +0 -64
  135. data/sub/avm-tools/locale/en.yml +0 -7
  136. data/sub/avm-tools/locale/pt-BR.yml +0 -7
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'clipboard'
4
+
5
+ module Avm
6
+ module Git
7
+ module Issue
8
+ class Complete
9
+ module Tracker
10
+ def clipboard_copy_tracker_message
11
+ ::Clipboard.copy(textile_tracker_message)
12
+ infov 'Copied to clipboard', textile_tracker_message
13
+ end
14
+
15
+ private
16
+
17
+ def textile_tracker_message_uncached
18
+ "Revisado para commit:#{branch_short_hash}, ok."
19
+ end
20
+
21
+ def branch_short_hash
22
+ git_execute(['log', '--pretty=format:%h', '-1', '-q', branch_hash])
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/result'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Issue
9
+ class Complete
10
+ class Validation
11
+ enable_simple_cache
12
+ common_constructor :parent, :key, :label
13
+
14
+ SKIPPED_RESULT_MESSAGE = 'skipped'
15
+
16
+ def skip?
17
+ parent.skip_validations.include?(key)
18
+ end
19
+
20
+ private
21
+
22
+ def result_uncached
23
+ skip? ? skipped_result : validation_result
24
+ end
25
+
26
+ def skipped_result
27
+ ::Avm::Result.neutral(SKIPPED_RESULT_MESSAGE)
28
+ end
29
+
30
+ def validation_result
31
+ parent.send("#{key}_result")
32
+ rescue ::RuntimeError => e
33
+ ::Avm::Result.error("error raised: #{e.message}")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/git/issue/complete/validation'
4
+ require 'avm/result'
5
+ require 'ostruct'
6
+
7
+ module Avm
8
+ module Git
9
+ module Issue
10
+ class Complete
11
+ module Validations
12
+ VALIDATIONS = {
13
+ clean_workspace: 'Clean workspace?',
14
+ branch_name: 'Branch name',
15
+ branch_hash: 'Branch hash',
16
+ follow_master: 'Follow master?',
17
+ commits: 'Commits?',
18
+ bifurcations: 'Bifurcations?',
19
+ dry_push: 'Dry push?',
20
+ git_subrepos: 'Git subrepos ok?',
21
+ test: 'Test ok?'
22
+ }.with_indifferent_access.freeze
23
+
24
+ def valid?
25
+ validations.map(&:result).none?(&:error?)
26
+ end
27
+
28
+ def validations_banner
29
+ validations.each do |v|
30
+ infov "[#{v.key}] #{v.label}", v.result.label
31
+ end
32
+ end
33
+
34
+ def validate_skip_validations
35
+ skip_validations.each do |validation|
36
+ next if VALIDATIONS.keys.include?(validation)
37
+
38
+ raise "\"#{validation}\" is not a registered validation"
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def validations_uncached
45
+ VALIDATIONS.map do |key, label|
46
+ ::Avm::Git::Issue::Complete::Validation.new(self, key, label)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Issue
6
+ class Complete
7
+ module WorkingTree
8
+ def clean_workspace_result
9
+ ::Avm::Result.success_or_error(clean_workspace?, 'yes', 'no')
10
+ end
11
+
12
+ def clean_workspace?
13
+ launcher_git.dirty_files.none?
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/tools/core_ext'
4
+ require 'eac_git/local'
5
+
6
+ module Avm
7
+ module Git
8
+ module Issue
9
+ class Complete
10
+ require_sub __FILE__, include_modules: true
11
+ enable_simple_cache
12
+ enable_speaker
13
+
14
+ BRANCH_NAME_ISSUE_ID_PATTERN =
15
+
16
+ attr_reader :dir, :skip_validations
17
+
18
+ def initialize(options)
19
+ consumer = ::EacRubyUtils::OptionsConsumer.new(options)
20
+ @dir, @skip_validations = consumer.consume_all(:dir, :skip_validations)
21
+ validate_skip_validations
22
+ consumer.validate
23
+ end
24
+
25
+ def start_banner
26
+ validations_banner
27
+ end
28
+
29
+ def run
30
+ return false unless valid?
31
+
32
+ assert_tag
33
+ push
34
+ remove_local_branch
35
+ clipboard_copy_tracker_message
36
+ true
37
+ end
38
+
39
+ def issue_id
40
+ branch ? issue_id_parser.parse(branch_name) : nil
41
+ end
42
+
43
+ # @return [EacRubyUtils::RegexpParser]
44
+ def issue_id_parser
45
+ /\A#{Regexp.quote('issue_')}(\d+)\z/.to_parser { |m| m[1].to_i }
46
+ end
47
+
48
+ private
49
+
50
+ # @return [EacGit::Local]
51
+ def eac_git_uncached
52
+ ::EacGit::Local.new(dir)
53
+ end
54
+
55
+ def git_execute(args, exit_outputs = {})
56
+ r = launcher_git.execute!(args, exit_outputs: exit_outputs)
57
+ r.is_a?(String) ? r.strip : r
58
+ end
59
+
60
+ def launcher_git_uncached
61
+ ::Avm::Launcher::Git::Base.new(dir)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/tools/core_ext'
4
+ require 'clipboard'
5
+
6
+ module Avm
7
+ module Git
8
+ module Issue
9
+ class Deliver
10
+ enable_simple_cache
11
+ enable_speaker
12
+
13
+ common_constructor :git_repo
14
+
15
+ def run
16
+ push
17
+ clipboard_copy_tracker_message
18
+ true
19
+ end
20
+
21
+ def start_banner
22
+ infov 'Branch name', branch_name
23
+ infov 'Commit ID', branch_commit_id
24
+ infov 'Push arguments', ::Shellwords.join(push_args)
25
+ end
26
+
27
+ private
28
+
29
+ def branch_commit_id
30
+ git_repo.rev_parse(branch_name)
31
+ end
32
+
33
+ def branch_name_uncached
34
+ git_repo.command('rev-parse', '--abbrev-ref', 'HEAD').execute!.strip
35
+ end
36
+
37
+ def clipboard_copy_tracker_message
38
+ ::Clipboard.copy(textile_tracker_message)
39
+ infov 'Copied to clipboard', textile_tracker_message
40
+ end
41
+
42
+ def push
43
+ git_repo.command(*push_args).system!
44
+ end
45
+
46
+ def push_args
47
+ %w[push origin --force] + ["#{branch_name}:refs/heads/#{branch_name}"]
48
+ end
49
+
50
+ def textile_tracker_message
51
+ "#{branch_name}: commit:#{branch_commit_id}."
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -4,6 +4,8 @@ require 'eac_ruby_utils/require_sub'
4
4
  ::EacRubyUtils.require_sub(__FILE__)
5
5
 
6
6
  module Avm
7
- module Patches
7
+ module Git
8
+ module Issue
9
+ end
8
10
  end
9
11
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Git
7
+ module Organize
8
+ class ReferenceUpdate
9
+ enable_listable
10
+ lists.add_symbol :operation, :remove
11
+
12
+ common_constructor :repository, :reference, :operation
13
+
14
+ def run_operation
15
+ send("run_operation_#{operation}")
16
+ end
17
+
18
+ def to_s
19
+ "#{reference} [#{operation}]"
20
+ end
21
+
22
+ private
23
+
24
+ def reference_pathname
25
+ repository.refs_root.join(reference)
26
+ end
27
+
28
+ def run_operation_remove
29
+ reference_pathname.unlink
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Git
7
+ module Organize
8
+ class Repository
9
+ enable_simple_cache
10
+ common_constructor :eac_git_local
11
+
12
+ def collected_references
13
+ @collected_references || []
14
+ end
15
+
16
+ def collect_subrepos
17
+ collect_references_with_pattern(
18
+ %r{\Asubrepo/},
19
+ ::Avm::Git::Organize::ReferenceUpdate::OPERATION_REMOVE
20
+ )
21
+ collect_references_with_pattern(
22
+ %r{\Aheads/subrepo/},
23
+ ::Avm::Git::Organize::ReferenceUpdate::OPERATION_REMOVE
24
+ )
25
+ end
26
+
27
+ def collect_originals
28
+ collect_references_with_pattern(
29
+ %r{\Aoriginal/},
30
+ ::Avm::Git::Organize::ReferenceUpdate::OPERATION_REMOVE
31
+ )
32
+ end
33
+
34
+ def all_branches
35
+ eac_git_local.execute!
36
+ end
37
+
38
+ delegate :to_s, to: :eac_git_local
39
+
40
+ private
41
+
42
+ def all_references
43
+ ::Pathname.glob("#{refs_root}/**/*").select(&:file?)
44
+ .map { |p| p.relative_path_from(refs_root).to_path }
45
+ end
46
+
47
+ def reference_update_by_ref(reference)
48
+ collected_references.find { |ru| ru.reference == reference }
49
+ end
50
+
51
+ def collect_reference(reference, operation)
52
+ new_ru = ::Avm::Git::Organize::ReferenceUpdate.new(self, reference, operation)
53
+ reference_update_by_ref(new_ru.reference).if_present do |ru_found|
54
+ raise "Reference #{new_ru} already added (#{ru_found})"
55
+ end
56
+ @collected_references ||= []
57
+ @collected_references << new_ru
58
+ end
59
+
60
+ def collect_references_with_pattern(pattern, operation)
61
+ references_with_pattern(pattern).each do |reference|
62
+ collect_reference(reference, operation)
63
+ end
64
+ end
65
+
66
+ def references_with_pattern(pattern)
67
+ all_references.select { |reference| pattern.if_match(reference, false) }
68
+ end
69
+
70
+ def refs_root_uncached
71
+ eac_git_local.root_path / '.git' / 'refs'
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Git
7
+ module Organize
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/ruby'
5
+
6
+ module Avm
7
+ module Git
8
+ class RevisionTest
9
+ enable_simple_cache
10
+ enable_speaker
11
+ common_constructor :git, :sha1, :options
12
+
13
+ def banner
14
+ infov 'Revision to test', sha1
15
+ ::EacRubyUtils::Speaker.context.on(::EacCli::Speaker.new(err_line_prefix: ' ')) do
16
+ revision_banner
17
+ end
18
+ end
19
+
20
+ def successful_label
21
+ successful?.to_s.send((successful? ? :green : :red))
22
+ end
23
+
24
+ def to_s
25
+ sha1
26
+ end
27
+
28
+ def successful?
29
+ successful
30
+ end
31
+
32
+ private
33
+
34
+ def checkout_revision
35
+ infom 'Checking out revision...'
36
+ git.execute!('checkout', sha1)
37
+ end
38
+
39
+ def commit_uncached
40
+ ::Avm::Git::Commit.new(git, sha1)
41
+ end
42
+
43
+ def git_absolute_path
44
+ ::File.expand_path(git.to_s)
45
+ end
46
+
47
+ def revision_banner
48
+ infov '* Subject', commit.subject
49
+ infov '* Success?', successful_label
50
+ infov '* STDOUT', stdout_cache.content_path
51
+ infov '* STDERR', stderr_cache.content_path
52
+ end
53
+
54
+ def root_cache
55
+ fs_cache.child(git_absolute_path.parameterize, sha1,
56
+ options.fetch(:test_command).to_s.parameterize)
57
+ end
58
+
59
+ def run_test
60
+ infom "Running test command \"#{::Shellwords.join(test_command_args)}\"" \
61
+ " on \"#{git_absolute_path}\"..."
62
+ result = ::EacRubyUtils::Ruby.on_clean_environment { test_command.execute }
63
+ infom 'Test done'
64
+ write_result_cache(result)
65
+ end
66
+
67
+ def stdout_cache
68
+ root_cache.child('stdout')
69
+ end
70
+
71
+ def stderr_cache
72
+ root_cache.child('stderr')
73
+ end
74
+
75
+ def successful_cache
76
+ root_cache.child('successful')
77
+ end
78
+
79
+ def successful_uncached
80
+ if options.fetch(:no_cache) || !successful_cache.stored?
81
+ checkout_revision
82
+ run_test
83
+ end
84
+ successful_cache.read == 'true'
85
+ end
86
+
87
+ def test_command
88
+ ::EacRubyUtils::Envs.local.command(*test_command_args).chdir(git.to_s)
89
+ end
90
+
91
+ def test_command_args
92
+ r = ::Shellwords.split(options.fetch(:test_command).to_s)
93
+ return r if r.any?
94
+
95
+ raise 'No command found'
96
+ end
97
+
98
+ def write_result_cache(result)
99
+ stdout_cache.write(result[:stdout])
100
+ stderr_cache.write(result[:stderr])
101
+ successful_cache.write(result[:exit_code].zero? ? 'true' : 'false')
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Git
7
+ module Scms
8
+ class Git < ::Avm::Scms::Base
9
+ class ChangeTracker
10
+ common_constructor :git_scm, :message
11
+ attr_reader :starting_commit
12
+ delegate :git_repo, to: :git_scm
13
+
14
+ def start
15
+ raise 'Repository is dirty' if git_repo.dirty?
16
+
17
+ self.starting_commit = git_repo.head
18
+ end
19
+
20
+ # @return [Avm::Git::Scms::Git::Commit, nil]
21
+ def stop
22
+ git_scm.commit_dirty
23
+ return nil if starting_commit == git_repo.head
24
+
25
+ git_scm.reset_and_commit(starting_commit, message)
26
+ end
27
+
28
+ private
29
+
30
+ attr_writer :starting_commit
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/commit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class Git < ::Avm::Scms::Base
10
+ class Commit < ::Avm::Scms::Commit
11
+ common_constructor :git_scm, :git_commit do
12
+ git_commit.assert_argument(::EacGit::Local::Commit, 'git_commit')
13
+ end
14
+ delegate :git_repo, to: :git_scm
15
+
16
+ # @return [Array<Pathname>]
17
+ def changed_files
18
+ git_commit.changed_files.map { |cf| cf.path.to_pathname }
19
+ end
20
+
21
+ # @param other [Avm::Git::Scms::Git::Commit]
22
+ # @return [Avm::Git::Scms::Git::Commit]
23
+ def merge_with(other)
24
+ validate_clean_and_head
25
+ raise 'Implemented for only if other is parent' unless
26
+ other.git_commit == git_commit.parent
27
+
28
+ git_scm.reset_and_commit(other.git_commit.parent, other.git_commit.raw_body)
29
+ end
30
+
31
+ def reword(new_message)
32
+ validate_clean_and_head
33
+
34
+ git_repo.command('commit', '--amend', '-m', new_message).execute!
35
+ self.class.new(git_scm, git_repo.head)
36
+ end
37
+
38
+ # @param path [Pathname]
39
+ # @return [TrueClass,FalseClass]
40
+ def scm_file?(path)
41
+ %w[.gitrepo .gitmodules].any? { |file| file.include?(path.basename.to_path) }
42
+ end
43
+
44
+ private
45
+
46
+ def validate_clean_and_head
47
+ raise 'Implemented for only if repository is no dirty' if git_repo.dirty?
48
+ raise 'Implemented for only if self is HEAD' unless
49
+ git_commit == git_repo.head
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/git/scms/git_subrepo'
4
+ require 'avm/scms/base'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Git
9
+ module Scms
10
+ class Git < ::Avm::Scms::Base
11
+ require_sub __FILE__
12
+ include ::Comparable
13
+
14
+ COMMIT_DIRTY_DEFAULT_MESSAGE = 'Dirty files.'
15
+
16
+ def <=>(other)
17
+ git_repo <=> other.git_repo
18
+ end
19
+
20
+ # @return [Avm::Git::Scms::Git::Commit,nil]
21
+ def commitize(source)
22
+ if source.is_a?(::Avm::Git::Scms::Git::Commit)
23
+ return source if source.git_repo == self
24
+
25
+ raise 'Not same Git repository'
26
+ end
27
+ git_repo.commitize(source).if_present do |v|
28
+ ::Avm::Git::Scms::Git::Commit.new(self, v)
29
+ end
30
+ end
31
+
32
+ # @return [Avm::Git::Scms::Git::Commit,nil]
33
+ def commit_dirty(message = nil)
34
+ return nil unless git_repo.dirty?
35
+
36
+ git_repo.command('add', '.').execute!
37
+ git_repo.command('commit', '-m',
38
+ message.call_if_proc.if_present(COMMIT_DIRTY_DEFAULT_MESSAGE)).execute!
39
+ commitize(git_repo.head)
40
+ end
41
+
42
+ # @return [Avm::Git::Scms::Git::Commit,nil]
43
+ def commit_if_change(message = nil)
44
+ tracker = ::Avm::Git::Scms::Git::ChangeTracker.new(self, message)
45
+ tracker.start
46
+ yield
47
+ tracker.stop
48
+ end
49
+
50
+ def git_repo
51
+ @git_repo ||= ::EacGit::Local.new(path)
52
+ end
53
+
54
+ # @return [Avm::Git::Scms::Git::Commit]
55
+ def reset_and_commit(commit_to_reset, message)
56
+ git_repo.command('reset', '--soft', commitize(commit_to_reset).git_commit.id).execute!
57
+ commit_dirty(message)
58
+ end
59
+
60
+ # @return [Enumerable<Avm::Git::Scms::GitSubrepo>]
61
+ def subs
62
+ git_repo.subrepos.map do |subrepo|
63
+ ::Avm::Git::Scms::GitSubrepo.new(subrepo.subpath.expand_path(path))
64
+ end
65
+ end
66
+
67
+ def valid?
68
+ path.join('.git').exist?
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end