avm-git 0.23.0 → 0.24.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: c4c0e911bba94f413eb588e697fc1cb9e554c234113525d54074717ac0a5f1c2
4
- data.tar.gz: 270016ee525b2fc28b676506b500b0317fcecf091bb0d4c681bb54e65c78f50f
3
+ metadata.gz: f463713bd688c8f5f38ab60a0798195009a1c7c9e3fdbca0b63019de18af4e7e
4
+ data.tar.gz: 45b78d469200bcb7425ea018167b8ef987036892d255c08b9afc5c6cca25772e
5
5
  SHA512:
6
- metadata.gz: 5a50ed12f4fbc5319220c03a8dd2b18cecd5b95331f65c23278a070eb7b22e04481e24196099efcb95e8dae3a82c870dc24d9a2277122e1f43de507a874edb19
7
- data.tar.gz: 43ed4f6abd73fc9b70e47067d7cc91e04fef7981257ae7a1e6ac091fde237e5145b04a81708514307c2e1154b8b2d2eb31e4401f145847500d9bd38580398fb8
6
+ metadata.gz: 430a782734bd006d843458a05bce5b469d6bb5392215cd1e34110a1f397aabcf0b3d171fb4b7771b37d8b130334838fdf8b54eca5f14ae3b832c1a2393fc79a6
7
+ data.tar.gz: 239b3e62804fe65116688785d63d61a4da64e002d01bb149b75156a14aafc65c56c5c8d92678e537832c46288925198205122430c8dc1096259dfb0596b05f32
@@ -31,7 +31,7 @@ module Avm
31
31
 
32
32
  def commit_parents(commit)
33
33
  launcher_git.execute!('log', '--pretty=%P', '-n', '1', commit).split.map(&:strip)
34
- .select(&:present?)
34
+ .select(&:present?) # rubocop:disable Rails/CompactBlank
35
35
  end
36
36
  end
37
37
  end
@@ -18,11 +18,15 @@ module Avm
18
18
  end
19
19
 
20
20
  def subrepo_url(path)
21
- File.read(path.subpath(CONFIG_SUBPATH)).each_line do |l|
22
- m = /remote\s*=\s(.+)/.match(l)
23
- return m[1] if m
24
- end
25
- raise ::Avm::Git::Launcher::Error.new(path, '"remote = ... " not found')
21
+ configuration(path).remote_uri ||
22
+ raise(::Avm::Git::Launcher::Error.new(path, '"remote = ... " not found'))
23
+ end
24
+
25
+ private
26
+
27
+ # @return [EacGit::Subrepo::Configuration]
28
+ def configuration(path)
29
+ ::EacGit::Subrepo::Configuration.from_file(path.subpath(CONFIG_SUBPATH))
26
30
  end
27
31
  end
28
32
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shellwords'
4
+
5
+ module Avm
6
+ module Git
7
+ module Runners
8
+ class Base
9
+ class Subrepo
10
+ class Fix
11
+ class Rebase
12
+ # @!method initialize(local, upstream, commands)
13
+ # @param local [EacGit::Local]
14
+ # @param upstream [String]
15
+ # @param commands [Hash<String, String>] Commands indexed by full commit ID.
16
+ common_constructor :local, :upstream, :commands
17
+
18
+ # @return [void]
19
+ def perform
20
+ ::EacRubyUtils::Fs::Temp.on_file do |todo_file|
21
+ todo_file.write(todo)
22
+ local.command('rebase', '-i', upstream)
23
+ .envvar('GIT_SEQUENCE_EDITOR', "cp #{todo_file.to_path.shellescape}").system!
24
+ end
25
+ end
26
+
27
+ # @return [String]
28
+ def todo
29
+ commits.flat_map { |commit| commit_lines(commit) }.map { |line| "#{line}\n" }.join
30
+ end
31
+
32
+ protected
33
+
34
+ # @param commit [String]
35
+ # @return [Array<String>]
36
+ def commit_lines(commit)
37
+ ["pick #{commit}", commands[commit].if_present { |v| "exec #{v}" }].compact
38
+ end
39
+
40
+ # @return [Array<String>]
41
+ def commits
42
+ local.command('rev-list', '--reverse', '--no-merges', "#{upstream}..HEAD")
43
+ .execute!.split
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,65 +1,74 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'shellwords'
4
+
3
5
  module Avm
4
6
  module Git
5
7
  module Runners
6
8
  class Base
7
9
  class Subrepo
8
10
  class Fix
11
+ UPSTREAM = 'origin/master'
12
+
9
13
  runner_with :help do
10
14
  desc 'Fix git-subrepos\' parent property.'
11
15
  end
12
16
 
13
17
  def run
14
- loop do
15
- break if fix
18
+ return unless check_failed?
16
19
 
17
- amend_each
18
- rebase_fixup
19
- end
20
+ rebase
21
+ fatal_error 'Failed' if check_failed?
20
22
  end
21
23
 
22
24
  private
23
25
 
24
- def amend_each
25
- infov 'Dirty files', local_repos.dirty_files.count
26
- local_repos.dirty_files.each do |file|
27
- infov ' * Ammending', file.path
28
- ::Avm::Scms::AutoCommit::ForFile.new(
29
- git_scm, file.path,
30
- [::Avm::Scms::AutoCommit::Rules::Unique.new]
31
- ).run
32
- end
26
+ # @return [Boolean]
27
+ def check_failed?
28
+ infom 'Checking...'
29
+ checks = ::Avm::Git::Subrepo::Checks.new(local_repos).add_all_subrepos
30
+ checks.show_result
31
+ checks.result.error?
33
32
  end
34
33
 
35
- def fix # rubocop:disable Naming/PredicateMethod
36
- infom 'Checking/fixing...'
37
- c = new_check(true)
38
- c.show_result
39
- !c.result.error?
34
+ # @param subrepos [Array<EacGit::Local::Subrepo>]
35
+ # @return [String]
36
+ def fix_parent_command(subrepos)
37
+ paths = subrepos.map { |subrepo| subrepo.config_relative_path.to_path.shellescape }
38
+ paths.map { |path| fix_parent_path_command(path) }
39
+ .push("git add -- #{paths.join(' ')}", 'git commit --amend --no-edit')
40
+ .join(' && ')
40
41
  end
41
42
 
42
- # @return [Avm::Git::Scms::Git]
43
- def git_scm_uncached
44
- ::Avm::Git::Scms::Git.new(runner_context.call(:git).root_path)
43
+ # @param path [String]
44
+ # @return [String]
45
+ def fix_parent_path_command(path)
46
+ "git config --file=#{path} subrepo.parent \"$(git rev-parse HEAD^)\""
45
47
  end
46
48
 
47
- def new_check(fix_parent = false) # rubocop:disable Style/OptionalBooleanParameter
48
- r = ::Avm::Git::Subrepo::Checks.new(local_repos).add_all_subrepos
49
- r.fix_parent = fix_parent
50
- r
49
+ # @param subrepo [EacGit::Local::Subrepo]
50
+ # @return [String]
51
+ def last_config_change(subrepo)
52
+ local_repos.command('log', '-n', '1', '--pretty=format:%H', '--',
53
+ subrepo.config_relative_path.to_path).execute!.strip
51
54
  end
52
55
 
53
- def local_repos_uncached
56
+ # @return [EacGit::Local]
57
+ memoize def local_repos
54
58
  ::EacGit::Local.new(runner_context.call(:git))
55
59
  end
56
60
 
57
- def rebase_fixup
58
- local_repos.command('rebase', '-i', 'origin/master', '--autosquash').envvar(
59
- 'GIT_SEQUENCE_EDITOR', 'true'
60
- ).or(
61
- local_repos.command('rebase', '--continue').envvar('GIT_SEQUENCE_EDITOR', 'true')
62
- ).system!
61
+ # @return [void]
62
+ def rebase
63
+ ::Avm::Git::Runners::Base::Subrepo::Fix::Rebase.new(
64
+ local_repos, UPSTREAM,
65
+ subrepos_by_last_config_change.transform_values { |v| fix_parent_command(v) }
66
+ ).perform
67
+ end
68
+
69
+ # @return [Hash<String, Array<EacGit::Local::Subrepo>>]
70
+ memoize def subrepos_by_last_config_change
71
+ local_repos.subrepos.group_by { |subrepo| last_config_change(subrepo) }
63
72
  end
64
73
  end
65
74
  end
@@ -13,7 +13,7 @@ module Avm
13
13
  def add_all_subrepos
14
14
  add_subrepos(
15
15
  *repository.command('subrepo', '-q', 'status').execute!.split("\n").map(&:strip)
16
- .select(&:present?)
16
+ .select(&:present?) # rubocop:disable Rails/CompactBlank
17
17
  )
18
18
  end
19
19
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Git
5
- VERSION = '0.23.0'
5
+ VERSION = '0.24.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.23.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
@@ -30,6 +30,9 @@ dependencies:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0.22'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.22.1
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
@@ -37,20 +40,23 @@ dependencies:
37
40
  - - "~>"
38
41
  - !ruby/object:Gem::Version
39
42
  version: '0.22'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.22.1
40
46
  - !ruby/object:Gem::Dependency
41
47
  name: eac_ruby_utils
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
50
  - - "~>"
45
51
  - !ruby/object:Gem::Version
46
- version: '0.134'
52
+ version: '0.136'
47
53
  type: :runtime
48
54
  prerelease: false
49
55
  version_requirements: !ruby/object:Gem::Requirement
50
56
  requirements:
51
57
  - - "~>"
52
58
  - !ruby/object:Gem::Version
53
- version: '0.134'
59
+ version: '0.136'
54
60
  - !ruby/object:Gem::Dependency
55
61
  name: filesize
56
62
  requirement: !ruby/object:Gem::Requirement
@@ -131,14 +137,14 @@ dependencies:
131
137
  requirements:
132
138
  - - "~>"
133
139
  - !ruby/object:Gem::Version
134
- version: '0.15'
140
+ version: '0.16'
135
141
  type: :development
136
142
  prerelease: false
137
143
  version_requirements: !ruby/object:Gem::Requirement
138
144
  requirements:
139
145
  - - "~>"
140
146
  - !ruby/object:Gem::Version
141
- version: '0.15'
147
+ version: '0.16'
142
148
  executables: []
143
149
  extensions: []
144
150
  extra_rdoc_files: []
@@ -195,6 +201,7 @@ files:
195
201
  - lib/avm/git/runners/base/subrepo/check.rb
196
202
  - lib/avm/git/runners/base/subrepo/clone.rb
197
203
  - lib/avm/git/runners/base/subrepo/fix.rb
204
+ - lib/avm/git/runners/base/subrepo/fix/rebase.rb
198
205
  - lib/avm/git/scms/git.rb
199
206
  - lib/avm/git/scms/git/branch.rb
200
207
  - lib/avm/git/scms/git/branches.rb