avm-git 0.22.0 → 0.23.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48b7580d391f3fe6d59e88a301e63d071c4a51d4e1e1960a876fba7bca5d625a
4
- data.tar.gz: 4a62191af73ebe6fbd6b94525ac17fe05187c3ccb0855f97095fc298d5f9f527
3
+ metadata.gz: c4c0e911bba94f413eb588e697fc1cb9e554c234113525d54074717ac0a5f1c2
4
+ data.tar.gz: 270016ee525b2fc28b676506b500b0317fcecf091bb0d4c681bb54e65c78f50f
5
5
  SHA512:
6
- metadata.gz: 4d065d6b802c3d7260ee0983e41a1dbf9e1f6f45c520d91f5aeae41a7c507d885a6bfa336bcb75051a8c9932950efd80d9259d0eea564bb2deb2b130e75cee19
7
- data.tar.gz: a957e49c3442c886b75777a9540e30373a4adeeb748b44d2a76dcb013766e4b82d5db76f366195014e21a59ba045b2851ec0a1e0bae37fb60917ffb4ef26db8c
6
+ metadata.gz: 5a50ed12f4fbc5319220c03a8dd2b18cecd5b95331f65c23278a070eb7b22e04481e24196099efcb95e8dae3a82c870dc24d9a2277122e1f43de507a874edb19
7
+ data.tar.gz: 43ed4f6abd73fc9b70e47067d7cc91e04fef7981257ae7a1e6ac091fde237e5145b04a81708514307c2e1154b8b2d2eb31e4401f145847500d9bd38580398fb8
@@ -9,7 +9,7 @@ module Avm
9
9
  return ::Avm::Result.error('Unclean workspace') unless clean_workspace?
10
10
 
11
11
  infom 'Checking Git subrepos...'
12
- r = ::Avm::Git::SubrepoChecks.new(::EacGit::Local.new(launcher_git)).add_all_subrepos
12
+ r = ::Avm::Git::Subrepo::Checks.new(::EacGit::Local.new(launcher_git)).add_all_subrepos
13
13
  r.check_remote = true
14
14
  r.result
15
15
  end
@@ -26,7 +26,7 @@ module Avm
26
26
  private
27
27
 
28
28
  def subrepo_checks_uncached
29
- r = ::Avm::Git::SubrepoChecks.new(local_repos)
29
+ r = ::Avm::Git::Subrepo::Checks.new(local_repos)
30
30
  r.check_remote = parsed.remote?
31
31
  r.fix_parent = parsed.fix_parent?
32
32
  r.add_all_subrepos if parsed.all?
@@ -45,7 +45,7 @@ module Avm
45
45
  end
46
46
 
47
47
  def new_check(fix_parent = false) # rubocop:disable Style/OptionalBooleanParameter
48
- r = ::Avm::Git::SubrepoChecks.new(local_repos).add_all_subrepos
48
+ r = ::Avm::Git::Subrepo::Checks.new(local_repos).add_all_subrepos
49
49
  r.fix_parent = fix_parent
50
50
  r
51
51
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Subrepo
6
+ class Check
7
+ module Parent
8
+ def fix_parent
9
+ return if parent_result.success?
10
+
11
+ info(' Fixing...')
12
+ self.parent_hash = expected_parent_hash
13
+ info_banner
14
+ end
15
+
16
+ private
17
+
18
+ def expected_parent_hash_uncached
19
+ subrepo.local.rev_parse("#{last_file_change_rev}^")
20
+ end
21
+
22
+ def last_file_change_rev
23
+ subrepo.local.command('log', '-n', '1', '--pretty=format:%H', '--',
24
+ subrepo.config_relative_path.to_path).execute!.strip
25
+ end
26
+
27
+ def parent_hash
28
+ subrepo.parent_commit_id
29
+ end
30
+
31
+ def parent_hash=(new_hash)
32
+ subrepo.config.parent_commit_id = new_hash
33
+ subrepo.write_config
34
+ end
35
+
36
+ def parent_hash_ok?
37
+ return false if expected_parent_hash.blank? || parent_hash.blank?
38
+
39
+ expected_parent_hash == parent_hash
40
+ end
41
+
42
+ def parent_result_uncached
43
+ ::Avm::Result.success_or_error(parent_hash_ok?,
44
+ parent_hash.presence || blank_text)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Subrepo
6
+ class Check
7
+ module Remote
8
+ private
9
+
10
+ def fetch_uncached
11
+ subrepo.command('clean').execute!
12
+ subrepo.command('fetch').execute!
13
+ end
14
+
15
+ def check_remote_disabled?
16
+ !check_remote?
17
+ end
18
+
19
+ def check_remote_disabled_result
20
+ ::Avm::Result.neutral('Check remote disabled')
21
+ end
22
+
23
+ def local_descend_remote?
24
+ local_id.present? && remote_id.present? && subrepo.local.descendant?(local_id,
25
+ remote_id)
26
+ end
27
+
28
+ def local_descend_remote_result
29
+ ::Avm::Result.pending(remote_result_value)
30
+ end
31
+
32
+ def local_id_uncached
33
+ fetch
34
+ subrepo.command('branch', '--force').execute!
35
+ subrepo.local.rev_parse("subrepo/#{subrepo.subpath}")
36
+ end
37
+
38
+ def remote_descend_local?
39
+ local_id.present? && remote_id.present? && subrepo.local.descendant?(remote_id,
40
+ local_id)
41
+ end
42
+
43
+ def remote_descend_local_result
44
+ ::Avm::Result.outdated(remote_result_value)
45
+ end
46
+
47
+ def remote_branches
48
+ ['', 'refs/heads/', 'refs/tags/'].map { |prefix| "#{prefix}#{subrepo.remote_branch}" }
49
+ end
50
+
51
+ # @return [String, nil]
52
+ def remote_id_uncached
53
+ subrepo.remote.ls.then do |ls_result|
54
+ remote_branches.lazy.map { |b| ls_result[b] }.find(&:present?) ||
55
+ subrepo.remote_branch
56
+ end
57
+ end
58
+
59
+ def remote_result_uncached
60
+ %w[check_remote_disabled same_ids local_descend_remote remote_descend_local]
61
+ .each do |condition|
62
+ return send("#{condition}_result") if send("#{condition}?")
63
+ end
64
+
65
+ ::Avm::Result.error(remote_result_value)
66
+ end
67
+
68
+ def remote_result_value
69
+ local_s = local_id.presence || blank_text
70
+ remote_s = remote_id.presence || blank_text
71
+
72
+ if local_s == remote_s
73
+ "[L/R=#{local_s}]"
74
+ else
75
+ "[L=#{local_s}, R=#{remote_s}]"
76
+ end
77
+ end
78
+
79
+ def same_ids?
80
+ local_id.present? && remote_id.present? && local_id == remote_id
81
+ end
82
+
83
+ def same_ids_result
84
+ ::Avm::Result.success(remote_result_value)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Subrepo
6
+ class Check
7
+ module ShowResult
8
+ def show_result
9
+ out(subrepo.subpath.to_path.cyan)
10
+ out_attr('parent', parent_result.label)
11
+ run_fix_parent
12
+ out_attr('remote', remote_result.label)
13
+ out("\n")
14
+ end
15
+
16
+ def run_fix_parent
17
+ return unless fix_parent?
18
+ return unless parent_result.error?
19
+
20
+ out('|Fixing...'.white)
21
+ self.parent_hash = expected_parent_hash
22
+ out_attr('new parent', parent_result.label)
23
+ end
24
+
25
+ def out_attr(key, value)
26
+ out("|#{"#{key}=".white}#{value}")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Subrepo
6
+ class Check
7
+ require_sub __FILE__, include_modules: true
8
+ enable_speaker
9
+ enable_simple_cache
10
+
11
+ BLANK_TEXT = 'BLANK'
12
+
13
+ common_constructor :subrepo, :options
14
+
15
+ def blank_text
16
+ BLANK_TEXT
17
+ end
18
+
19
+ def check_remote?
20
+ options.fetch(:check_remote) ? true : false
21
+ end
22
+
23
+ def fix_parent?
24
+ options.fetch(:fix_parent) ? true : false
25
+ end
26
+
27
+ private
28
+
29
+ def result_uncached
30
+ return ::Avm::Result.error('Parent failed') if parent_result.error?
31
+ return ::Avm::Result.error('Remote failed') if remote_result.error?
32
+
33
+ ::Avm::Result.success('Parent and remote ok')
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Subrepo
6
+ class Checks
7
+ enable_speaker
8
+ enable_simple_cache
9
+ attr_accessor :check_remote, :fix_parent
10
+
11
+ common_constructor :repository
12
+
13
+ def add_all_subrepos
14
+ add_subrepos(
15
+ *repository.command('subrepo', '-q', 'status').execute!.split("\n").map(&:strip)
16
+ .select(&:present?)
17
+ )
18
+ end
19
+
20
+ def add_subrepos(*subpath_list)
21
+ subpath_list.each do |subpath|
22
+ subpaths.add(subpath)
23
+ end
24
+ reset_cache
25
+ self
26
+ end
27
+
28
+ def check_options
29
+ { fix_parent: fix_parent, check_remote: check_remote }
30
+ end
31
+
32
+ def show_result
33
+ checks.each(&:show_result)
34
+ infov 'Result', result.label
35
+ end
36
+
37
+ private
38
+
39
+ def checks_uncached
40
+ subpaths.map do |subpath|
41
+ ::Avm::Git::Subrepo::Check.new(repository.subrepo(subpath), check_options)
42
+ end
43
+ end
44
+
45
+ def result_uncached
46
+ error_count = checks.count { |check| check.result.error? }
47
+ ::Avm::Result.success_or_error(
48
+ error_count.zero?,
49
+ "#{error_count} of #{checks.count} subrepos failed"
50
+ )
51
+ end
52
+
53
+ def subpaths
54
+ @subpaths ||= ::Set.new
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Git
5
- VERSION = '0.22.0'
5
+ VERSION = '0.23.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.21'
32
+ version: '0.22'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.21'
39
+ version: '0.22'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: eac_ruby_utils
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -218,11 +218,11 @@ files:
218
218
  - lib/avm/git/scms/git_subrepo.rb
219
219
  - lib/avm/git/scms/git_subtree.rb
220
220
  - lib/avm/git/scms/provider.rb
221
- - lib/avm/git/subrepo_check.rb
222
- - lib/avm/git/subrepo_check/parent.rb
223
- - lib/avm/git/subrepo_check/remote.rb
224
- - lib/avm/git/subrepo_check/show_result.rb
225
- - lib/avm/git/subrepo_checks.rb
221
+ - lib/avm/git/subrepo/check.rb
222
+ - lib/avm/git/subrepo/check/parent.rb
223
+ - lib/avm/git/subrepo/check/remote.rb
224
+ - lib/avm/git/subrepo/check/show_result.rb
225
+ - lib/avm/git/subrepo/checks.rb
226
226
  - lib/avm/git/vendor/github.rb
227
227
  - lib/avm/git/version.rb
228
228
  - locale/en.yml
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module Git
5
- class SubrepoCheck
6
- module Parent
7
- def fix_parent
8
- return if parent_result.success?
9
-
10
- info(' Fixing...')
11
- self.parent_hash = expected_parent_hash
12
- info_banner
13
- end
14
-
15
- private
16
-
17
- def expected_parent_hash_uncached
18
- subrepo.local.rev_parse("#{last_file_change_rev}^")
19
- end
20
-
21
- def last_file_change_rev
22
- subrepo.local.command('log', '-n', '1', '--pretty=format:%H', '--',
23
- subrepo.config_relative_path.to_path).execute!.strip
24
- end
25
-
26
- def parent_hash
27
- subrepo.parent_commit_id
28
- end
29
-
30
- def parent_hash=(new_hash)
31
- subrepo.config.parent_commit_id = new_hash
32
- subrepo.write_config
33
- end
34
-
35
- def parent_hash_ok?
36
- return false if expected_parent_hash.blank? || parent_hash.blank?
37
-
38
- expected_parent_hash == parent_hash
39
- end
40
-
41
- def parent_result_uncached
42
- ::Avm::Result.success_or_error(parent_hash_ok?,
43
- parent_hash.presence || blank_text)
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module Git
5
- class SubrepoCheck
6
- module Remote
7
- private
8
-
9
- def fetch_uncached
10
- subrepo.command('clean').execute!
11
- subrepo.command('fetch').execute!
12
- end
13
-
14
- def check_remote_disabled?
15
- !check_remote?
16
- end
17
-
18
- def check_remote_disabled_result
19
- ::Avm::Result.neutral('Check remote disabled')
20
- end
21
-
22
- def local_descend_remote?
23
- local_id.present? && remote_id.present? && subrepo.local.descendant?(local_id, remote_id)
24
- end
25
-
26
- def local_descend_remote_result
27
- ::Avm::Result.pending(remote_result_value)
28
- end
29
-
30
- def local_id_uncached
31
- fetch
32
- subrepo.command('branch', '--force').execute!
33
- subrepo.local.rev_parse("subrepo/#{subrepo.subpath}")
34
- end
35
-
36
- def remote_descend_local?
37
- local_id.present? && remote_id.present? && subrepo.local.descendant?(remote_id, local_id)
38
- end
39
-
40
- def remote_descend_local_result
41
- ::Avm::Result.outdated(remote_result_value)
42
- end
43
-
44
- def remote_branches
45
- ['', 'refs/heads/', 'refs/tags/'].map { |prefix| "#{prefix}#{subrepo.remote_branch}" }
46
- end
47
-
48
- def remote_id_uncached
49
- ls_result = subrepo.remote.ls
50
- remote_branches.each do |b|
51
- return ls_result[b] if ls_result[b].present?
52
- end
53
- nil
54
- end
55
-
56
- def remote_result_uncached
57
- %w[check_remote_disabled same_ids local_descend_remote remote_descend_local]
58
- .each do |condition|
59
- return send("#{condition}_result") if send("#{condition}?")
60
- end
61
-
62
- ::Avm::Result.error(remote_result_value)
63
- end
64
-
65
- def remote_result_value
66
- local_s = local_id.presence || blank_text
67
- remote_s = remote_id.presence || blank_text
68
-
69
- if local_s == remote_s
70
- "[L/R=#{local_s}]"
71
- else
72
- "[L=#{local_s}, R=#{remote_s}]"
73
- end
74
- end
75
-
76
- def same_ids?
77
- local_id.present? && remote_id.present? && local_id == remote_id
78
- end
79
-
80
- def same_ids_result
81
- ::Avm::Result.success(remote_result_value)
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module Git
5
- class SubrepoCheck
6
- module ShowResult
7
- def show_result
8
- out(subrepo.subpath.to_path.cyan)
9
- out_attr('parent', parent_result.label)
10
- run_fix_parent
11
- out_attr('remote', remote_result.label)
12
- out("\n")
13
- end
14
-
15
- def run_fix_parent
16
- return unless fix_parent?
17
- return unless parent_result.error?
18
-
19
- out('|Fixing...'.white)
20
- self.parent_hash = expected_parent_hash
21
- out_attr('new parent', parent_result.label)
22
- end
23
-
24
- def out_attr(key, value)
25
- out("|#{"#{key}=".white}#{value}")
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module Git
5
- class SubrepoCheck
6
- require_sub __FILE__, include_modules: true
7
- enable_speaker
8
- enable_simple_cache
9
-
10
- BLANK_TEXT = 'BLANK'
11
-
12
- common_constructor :subrepo, :options
13
-
14
- def blank_text
15
- BLANK_TEXT
16
- end
17
-
18
- def check_remote?
19
- options.fetch(:check_remote) ? true : false
20
- end
21
-
22
- def fix_parent?
23
- options.fetch(:fix_parent) ? true : false
24
- end
25
-
26
- private
27
-
28
- def result_uncached
29
- return ::Avm::Result.error('Parent failed') if parent_result.error?
30
- return ::Avm::Result.error('Remote failed') if remote_result.error?
31
-
32
- ::Avm::Result.success('Parent and remote ok')
33
- end
34
- end
35
- end
36
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module Git
5
- class SubrepoChecks
6
- enable_speaker
7
- enable_simple_cache
8
- attr_accessor :check_remote, :fix_parent
9
-
10
- common_constructor :repository
11
-
12
- def add_all_subrepos
13
- add_subrepos(
14
- *repository.command('subrepo', '-q', 'status').execute!.split("\n").map(&:strip)
15
- .select(&:present?)
16
- )
17
- end
18
-
19
- def add_subrepos(*subpath_list)
20
- subpath_list.each do |subpath|
21
- subpaths.add(subpath)
22
- end
23
- reset_cache
24
- self
25
- end
26
-
27
- def check_options
28
- { fix_parent: fix_parent, check_remote: check_remote }
29
- end
30
-
31
- def show_result
32
- checks.each(&:show_result)
33
- infov 'Result', result.label
34
- end
35
-
36
- private
37
-
38
- def checks_uncached
39
- subpaths.map do |subpath|
40
- ::Avm::Git::SubrepoCheck.new(repository.subrepo(subpath), check_options)
41
- end
42
- end
43
-
44
- def result_uncached
45
- error_count = checks.count { |check| check.result.error? }
46
- ::Avm::Result.success_or_error(
47
- error_count.zero?,
48
- "#{error_count} of #{checks.count} subrepos failed"
49
- )
50
- end
51
-
52
- def subpaths
53
- @subpaths ||= ::Set.new
54
- end
55
- end
56
- end
57
- end