eac_tools 0.33.0 → 0.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +30 -24
  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-tools → avm}/lib/avm/launcher/instances/base/cache.rb +0 -0
  13. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/base.rb +0 -0
  14. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/error.rb +0 -0
  15. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/runner_helper.rb +0 -0
  16. data/sub/{avm-tools → avm}/lib/avm/launcher/instances/settings.rb +0 -0
  17. data/sub/{avm-tools → avm}/lib/avm/launcher/paths/logical.rb +0 -0
  18. data/sub/{avm-tools → avm}/lib/avm/launcher/publish/base.rb +2 -5
  19. data/sub/avm/lib/avm/registry.rb +0 -2
  20. data/sub/avm/lib/avm/version.rb +1 -1
  21. data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +2 -2
  22. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/runners/bundler/gemfile_local.rb +21 -4
  23. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/runners/bundler/gemfile_lock/git.rb +60 -0
  24. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/runners/bundler/gemfile_lock.rb +89 -0
  25. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
  26. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +1 -1
  27. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/apache_host.rb +2 -1
  28. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  29. data/sub/avm-git/Gemfile +8 -0
  30. data/sub/avm-git/avm-git.gemspec +22 -0
  31. data/sub/avm-git/lib/avm/git/auto_commit/commit_info.rb +23 -0
  32. data/sub/avm-git/lib/avm/git/auto_commit/rules/base.rb +39 -0
  33. data/sub/avm-git/lib/avm/git/auto_commit/rules/last.rb +19 -0
  34. data/sub/avm-git/lib/avm/git/auto_commit/rules/manual.rb +45 -0
  35. data/sub/avm-git/lib/avm/git/auto_commit/rules/new.rb +24 -0
  36. data/sub/avm-git/lib/avm/git/auto_commit/rules/nth.rb +31 -0
  37. data/sub/avm-git/lib/avm/git/auto_commit/rules/unique.rb +21 -0
  38. data/sub/avm-git/lib/avm/git/auto_commit/rules.rb +31 -0
  39. data/sub/avm-git/lib/avm/git/auto_commit_path/ruby.rb +20 -0
  40. data/sub/avm-git/lib/avm/git/auto_commit_path.rb +28 -0
  41. data/sub/avm-git/lib/avm/git/commit/class_methods.rb +31 -0
  42. data/sub/avm-git/lib/avm/git/commit/deploy.rb +38 -0
  43. data/sub/avm-git/lib/avm/git/commit/deploy_methods.rb +19 -0
  44. data/sub/avm-git/lib/avm/git/commit/diff_tree_line.rb +32 -0
  45. data/sub/avm-git/lib/avm/git/commit/file.rb +46 -0
  46. data/sub/avm-git/lib/avm/git/commit.rb +59 -0
  47. data/sub/avm-git/lib/avm/git/file_auto_fixup.rb +83 -0
  48. data/sub/avm-git/lib/avm/git/issue/complete/commits.rb +42 -0
  49. data/sub/avm-git/lib/avm/git/issue/complete/git_subrepos.rb +23 -0
  50. data/sub/avm-git/lib/avm/git/issue/complete/local_branch.rb +61 -0
  51. data/sub/avm-git/lib/avm/git/issue/complete/local_tag.rb +39 -0
  52. data/sub/avm-git/lib/avm/git/issue/complete/push.rb +60 -0
  53. data/sub/avm-git/lib/avm/git/issue/complete/remote.rb +33 -0
  54. data/sub/avm-git/lib/avm/git/issue/complete/test.rb +40 -0
  55. data/sub/avm-git/lib/avm/git/issue/complete/tracker.rb +28 -0
  56. data/sub/avm-git/lib/avm/git/issue/complete/validation.rb +39 -0
  57. data/sub/avm-git/lib/avm/git/issue/complete/validations.rb +53 -0
  58. data/sub/avm-git/lib/avm/git/issue/complete/working_tree.rb +19 -0
  59. data/sub/avm-git/lib/avm/git/issue/complete.rb +66 -0
  60. data/sub/avm-git/lib/avm/git/issue/deliver.rb +56 -0
  61. data/sub/avm-git/lib/avm/git/issue.rb +11 -0
  62. data/sub/avm-git/lib/avm/git/organize/reference_update.rb +34 -0
  63. data/sub/avm-git/lib/avm/git/organize/repository.rb +76 -0
  64. data/sub/avm-git/lib/avm/git/organize.rb +11 -0
  65. data/sub/avm-git/lib/avm/git/revision_test.rb +105 -0
  66. data/sub/avm-git/lib/avm/git/scms/git/change_tracker.rb +35 -0
  67. data/sub/avm-git/lib/avm/git/scms/git/commit.rb +55 -0
  68. data/sub/avm-git/lib/avm/git/scms/git.rb +73 -0
  69. data/sub/avm-git/lib/avm/git/scms/git_subrepo.rb +39 -0
  70. data/sub/avm-git/lib/avm/git/scms/provider.rb +19 -0
  71. data/sub/avm-git/lib/avm/git/scms.rb +11 -0
  72. data/sub/avm-git/lib/avm/git/subrepo_check/parent.rb +51 -0
  73. data/sub/avm-git/lib/avm/git/subrepo_check/remote.rb +89 -0
  74. data/sub/avm-git/lib/avm/git/subrepo_check/show_result.rb +32 -0
  75. data/sub/avm-git/lib/avm/git/subrepo_check.rb +38 -0
  76. data/sub/avm-git/lib/avm/git/subrepo_checks.rb +59 -0
  77. data/sub/{avm-tools/lib/avm/launcher → avm-git/lib/avm/git}/vendor/github.rb +1 -1
  78. data/sub/avm-git/lib/avm/git/vendor.rb +11 -0
  79. data/sub/avm-git/lib/avm/git/version.rb +7 -0
  80. data/sub/avm-git/lib/avm/git.rb +11 -0
  81. data/sub/avm-git/spec/lib/avm/git/auto_commit_path_spec.rb +21 -0
  82. data/sub/avm-git/spec/lib/avm/git/commit/deploy_spec.rb +93 -0
  83. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec.rb +13 -0
  84. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/add.source.out +1 -0
  85. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/add.target.yaml +7 -0
  86. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/modify.source.out +1 -0
  87. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/modify.target.yaml +7 -0
  88. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/remove.source.out +1 -0
  89. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/remove.target.yaml +7 -0
  90. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename.source.out +2 -0
  91. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename.target.yaml +13 -0
  92. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename_modify.source.out +2 -0
  93. data/sub/avm-git/spec/lib/avm/git/commit/diff_tree_line_spec_files/rename_modify.target.yaml +13 -0
  94. data/sub/avm-git/spec/lib/avm/git/commit_spec.rb +56 -0
  95. data/sub/avm-git/spec/lib/avm/git/scms/git_spec.rb +8 -0
  96. data/sub/avm-git/spec/lib/avm/git/scms/git_subrepo_spec.rb +8 -0
  97. data/sub/{avm-tools/spec/lib/avm/launcher → avm-git/spec/lib/avm/git}/vendor/github_spec.rb +4 -4
  98. data/sub/avm-git/spec/rubocop_spec.rb +3 -0
  99. data/sub/avm-git/spec/spec_helper.rb +4 -0
  100. data/sub/avm-tools/avm-tools.gemspec +3 -3
  101. data/sub/avm-tools/lib/avm/launcher/git/warp_base.rb +2 -2
  102. data/sub/avm-tools/lib/avm/projects/stereotypes/git_subrepo/warp.rb +2 -2
  103. data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
  104. data/sub/eac_docker/eac_docker.gemspec +2 -2
  105. data/sub/eac_docker/lib/eac_docker/images/templatized.rb +7 -1
  106. data/sub/eac_docker/lib/eac_docker/version.rb +1 -1
  107. metadata +101 -29
  108. data/sub/avm-tools/lib/avm/launcher/vendor.rb +0 -3
  109. data/sub/avm-tools/lib/avm/tools/runner/source/ruby/bundler/gemfile_lock/git.rb +0 -62
  110. data/sub/avm-tools/lib/avm/tools/runner/source/ruby/bundler/gemfile_lock.rb +0 -105
  111. data/sub/avm-tools/lib/avm/tools/runner/source/ruby/bundler.rb +0 -21
  112. data/sub/avm-tools/lib/avm/tools/runner/source/ruby.rb +0 -19
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Issue
6
+ class Complete
7
+ module Remote
8
+ def remote_master_hash
9
+ remote_hashs['refs/heads/master']
10
+ end
11
+
12
+ def remote_branch_hash
13
+ remote_hashs["refs/heads/#{branch.name}"]
14
+ end
15
+
16
+ def remote_tag_hash
17
+ remote_hashs[tag]
18
+ end
19
+
20
+ private
21
+
22
+ def remote_name
23
+ 'origin'
24
+ end
25
+
26
+ def remote_hashs_uncached
27
+ launcher_git.remote_hashs(remote_name)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/sources/configuration'
4
+ require 'avm/result'
5
+ require 'avm/sources/base'
6
+ require 'avm/sources/tests/builder'
7
+ require 'eac_ruby_utils/fs/temp'
8
+
9
+ module Avm
10
+ module Git
11
+ module Issue
12
+ class Complete
13
+ module Test
14
+ def test_result
15
+ infom 'Running tests...'
16
+ test_performer.units.each do |single|
17
+ return ::Avm::Result.error(test_failed_result_message(single)) if single.failed?
18
+ end
19
+ ::Avm::Result.success('all passed')
20
+ end
21
+
22
+ private
23
+
24
+ def test_failed_result_message(single)
25
+ { 'Source' => single, 'STDOUT' => single.logs[:stdout],
26
+ 'STDERR' => single.logs[:stderr] }.map { |k, v| "#{k}: #{v}" }.join(', ')
27
+ end
28
+
29
+ def test_performer
30
+ ::Avm::Sources::Tests::Builder
31
+ .new(::Avm::Registry.sources.detect(launcher_git))
32
+ .include_main(true)
33
+ .include_subs(true)
34
+ .performer
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Git
8
+ module Issue
9
+ end
10
+ end
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