avm-git 0.10.1 → 0.12.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: 131f6f492e367fdd20b348f8e4c4f64d55c32d1308c48c467d62b55375dbfb31
4
- data.tar.gz: 6820cfd26ffe40a553a83a7bb4aca84f7be278f4bb84cfa6ac0f68cb7510de82
3
+ metadata.gz: 447507fccfbdccc90a778e94ea7dbc81e2600cab181994857ee1e2644d80ca9a
4
+ data.tar.gz: cf78b8c4eb61432fc10369703fdb2309fca8e4c30fb92c2dc507262c30d8c070
5
5
  SHA512:
6
- metadata.gz: f8717c186d4c5e7114df2845ceafe4de60ae1517fc513c70e7df2c89116f88bbb3d25cb15f44625e0fef56fabf1c89cffd869aaafa921fd36b0a4cc2ddb8111b
7
- data.tar.gz: 77fdbbfedfee9b927d5def461963bef3cc5684bcb52f9c1527b7f5606ba8044931cf38de149707a167f30f43d28f293413af13345f37c4a7ac5f67aaa1742569
6
+ metadata.gz: 2d54484f2a54ca4a8a315e47044f0450acbb74b8f95f39cf9ff2c803600cc7a4d1b08209d3ccb66a3da9070fefb846b71cc3d0cdd8b497e438b76a4bedc1d47e
7
+ data.tar.gz: ea4c503d46c43fce7d44b38e69792a16c6b380a5a448fbd7e959cbb2e7348123f809ac3b9a52c090a670edca80c98e3ba21ab5157327b8d3a608037b4f8c5f1b
@@ -7,7 +7,7 @@ module Avm
7
7
  module Scms
8
8
  class Git < ::Avm::Scms::Base
9
9
  class ChangeTracker
10
- common_constructor :git_scm, :message
10
+ common_constructor :git_scm, :commit_info
11
11
  attr_reader :starting_commit
12
12
  delegate :git_repo, to: :git_scm
13
13
 
@@ -22,7 +22,7 @@ module Avm
22
22
  git_scm.commit_dirty
23
23
  return nil if starting_commit == git_repo.head
24
24
 
25
- git_scm.reset_and_commit(starting_commit, message)
25
+ git_scm.reset_and_commit(starting_commit, commit_info)
26
26
  end
27
27
 
28
28
  private
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/changed_file'
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 ChangedFile < ::Avm::Scms::ChangedFile
11
+ common_constructor :scm, :path
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/git/scms/git/changed_file'
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 ChangedFiles
11
+ enable_method_class
12
+ common_constructor :scm
13
+
14
+ # @return [Avm::Git::Scms::Git::ChangedFile]
15
+ def result
16
+ scm.git_repo.dirty_files.map do |dirty_file|
17
+ ::Avm::Git::Scms::Git::ChangedFile.new(scm, dirty_file.path)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -15,11 +15,18 @@ module Avm
15
15
  delegate :git_repo, to: :git_scm
16
16
  delegate :id, to: :git_commit
17
17
 
18
+ FIXUP_SUBJECT_PATTERN = /\Afixup\!/.freeze
19
+
18
20
  # @return [Array<Pathname>]
19
21
  def changed_files
20
22
  git_commit.changed_files.map { |cf| cf.path.to_pathname }
21
23
  end
22
24
 
25
+ # @return [Boolean]
26
+ def fixup?
27
+ FIXUP_SUBJECT_PATTERN.match?(git_commit.subject)
28
+ end
29
+
23
30
  # @param other [Avm::Git::Scms::Git::Commit]
24
31
  # @return [Avm::Git::Scms::Git::Commit]
25
32
  def merge_with(other)
@@ -43,6 +50,9 @@ module Avm
43
50
  %w[.gitrepo .gitmodules].any? { |file| file.include?(path.basename.to_path) }
44
51
  end
45
52
 
53
+ # @return [String]
54
+ delegate :subject, to: :git_commit
55
+
46
56
  private
47
57
 
48
58
  def validate_clean_and_head
@@ -0,0 +1,61 @@
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
+ module Commits
11
+ # @return [Avm::Git::Scms::Git::Commit,nil]
12
+ def commit(source)
13
+ if source.is_a?(::Avm::Git::Scms::Git::Commit)
14
+ return source if source.git_repo == git_repo
15
+
16
+ raise 'Not same Git repository'
17
+ end
18
+ git_repo.commitize(source).if_present do |v|
19
+ ::Avm::Git::Scms::Git::Commit.new(self, v)
20
+ end
21
+ end
22
+
23
+ # @param commit_info [Avm::Scms::CommitInfo]
24
+ # @return [Avm::Git::Scms::Git::Commit,nil]
25
+ def commit_dirty(commit_info = nil)
26
+ return nil unless git_repo.dirty?
27
+
28
+ commit_info = ::Avm::Scms::CommitInfo.assert(commit_info)
29
+ commit_info = commit_info.message(COMMIT_DIRTY_DEFAULT_MESSAGE) if
30
+ commit_info.message.blank?
31
+
32
+ git_repo.command('add', '.').execute!
33
+ run_commit(commit_info)
34
+ head_commit
35
+ end
36
+
37
+ # @param commit_info [Avm::Scms::CommitInfo]
38
+ # @return [Avm::Git::Scms::Git::Commit,nil]
39
+ def commit_if_change(commit_info = nil)
40
+ tracker = ::Avm::Git::Scms::Git::ChangeTracker.new(self, commit_info)
41
+ tracker.start
42
+ yield
43
+ tracker.stop
44
+ end
45
+
46
+ # @return [Avm::Git::Scms::Git::Commit]
47
+ def head_commit
48
+ commit(git_repo.head)
49
+ end
50
+
51
+ # @param commit_info [Avm::Scms::CommitInfo]
52
+ # @return [Avm::Git::Scms::Git::Commit]
53
+ def reset_and_commit(commit_to_reset, commit_info)
54
+ git_repo.command('reset', '--soft', commit(commit_to_reset).git_commit.id).execute!
55
+ commit_dirty(commit_info)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/interval'
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 Interval < ::Avm::Scms::Interval
11
+ def initialize(scm, from, to)
12
+ super(scm, from, to)
13
+ self.from = scm.commit(from)
14
+ self.to = scm.commit(to)
15
+ end
16
+
17
+ # @return [Array<Avm::Git::Scms::Git::Commit>]
18
+ def commits
19
+ scm.git_repo.command('log', '--pretty=format:%H', git_commit_interval).execute!
20
+ .each_line.map { |sha1| scm.commit(sha1.strip) }
21
+ end
22
+
23
+ # @return [String]
24
+ def git_commit_interval
25
+ [from.id, to.id].join('..')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
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
+ module Milestones
11
+ BASE_COMMIT_REFERENCE = 'origin/master'
12
+
13
+ # @return [Avm::Git::Scms::Git::Commit]
14
+ def current_milestone_base_commit
15
+ commit(BASE_COMMIT_REFERENCE)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
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 RunCommit
11
+ enable_method_class
12
+
13
+ common_constructor :scm, :commit_info
14
+
15
+ # @return [Avm::Git::Scms::Git::Commit]
16
+ def result
17
+ reset
18
+ add_paths
19
+ commit
20
+
21
+ scm.head_commit
22
+ end
23
+
24
+ protected
25
+
26
+ def add_path(path)
27
+ scm.git_repo.command(
28
+ *(path.exist? ? ['add'] : ['rm', '-f']),
29
+ path.relative_path_from(scm.path)
30
+ ).execute!
31
+ end
32
+
33
+ def add_paths
34
+ commit_info.paths.each { |path| add_path(path) }
35
+ end
36
+
37
+ def commit
38
+ scm.git_repo.command('commit', *commit_args).execute!
39
+ end
40
+
41
+ # @return [Array<String>]
42
+ def commit_args
43
+ r = commit_info.fixup.if_present([]) { |v| ['--fixup', v.id] }
44
+ r += commit_info.message.if_present([]) { |v| ['--message', v] }
45
+ return r if r.any?
46
+
47
+ raise 'Argument list is empty'
48
+ end
49
+
50
+ def reset
51
+ scm.git_repo.command('reset', '--soft', 'HEAD').execute!
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -8,7 +8,7 @@ module Avm
8
8
  module Git
9
9
  module Scms
10
10
  class Git < ::Avm::Scms::Base
11
- require_sub __FILE__
11
+ require_sub __FILE__, include_modules: true
12
12
  include ::Comparable
13
13
 
14
14
  COMMIT_DIRTY_DEFAULT_MESSAGE = 'Dirty files.'
@@ -17,44 +17,15 @@ module Avm
17
17
  git_repo <=> other.git_repo
18
18
  end
19
19
 
20
- # @return [Avm::Git::Scms::Git::Commit,nil]
21
- def commit(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
- commit(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
20
  def git_repo
51
21
  @git_repo ||= ::EacGit::Local.new(path)
52
22
  end
53
23
 
54
- # @return [Avm::Git::Scms::Git::Commit]
55
- def reset_and_commit(commit_to_reset, message)
56
- git_repo.command('reset', '--soft', commit(commit_to_reset).git_commit.id).execute!
57
- commit_dirty(message)
24
+ # @param from [Avm::Git::Scms::Git::Commit]
25
+ # @param to [Avm::Git::Scms::Git::Commit]
26
+ # @return [Avm::Git::Scms::Git::Interval]
27
+ def interval(from, to)
28
+ ::Avm::Git::Scms::Git::Interval.new(self, from, to)
58
29
  end
59
30
 
60
31
  # @return [Enumerable<Avm::Git::Scms::GitSubrepo>]
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class GitSubBase < ::Avm::Scms::Base
10
+ enable_abstract_methods
11
+
12
+ delegate :changed_files, :commit_if_change, :current_milestone_base_commit, :interval,
13
+ :head_commit, :reset_and_commit, :run_commit, to: :parent_scm
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,15 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/scms/base'
3
+ require 'avm/git/scms/git_sub_base'
4
4
  require 'eac_git/local'
5
5
  require 'eac_ruby_utils/core_ext'
6
6
 
7
7
  module Avm
8
8
  module Git
9
9
  module Scms
10
- class GitSubrepo < ::Avm::Scms::Base
11
- delegate :commit_if_change, to: :parent_scm
12
-
10
+ class GitSubrepo < ::Avm::Git::Scms::GitSubBase
13
11
  def update
14
12
  git_subrepo.command('clean').execute!
15
13
  git_subrepo.command('pull').execute!
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/git/scms/provider'
4
+ require 'avm/git/scms/git_sub_base'
5
+ require 'avm/scms/base'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module Avm
9
+ module Git
10
+ module Scms
11
+ class GitSubtree < ::Avm::Git::Scms::GitSubBase
12
+ def update
13
+ # Do nothing
14
+ end
15
+
16
+ def valid?
17
+ return false unless ::Avm::Git::Scms::Provider
18
+ .new.all.any? { |scm_class| parent_scm.is_a?(scm_class) }
19
+
20
+ (::Avm::Git::Scms::Provider.new.all - [self.class])
21
+ .lazy.map { |scm_class| scm_class.new(path) }.none?(&:valid?)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,13 +2,15 @@
2
2
 
3
3
  require 'avm/git/scms/git'
4
4
  require 'avm/git/scms/git_subrepo'
5
+ require 'avm/git/scms/git_subtree'
5
6
  require 'eac_ruby_utils/core_ext'
6
7
 
7
8
  module Avm
8
9
  module Git
9
10
  module Scms
10
11
  class Provider
11
- SCMS = [::Avm::Git::Scms::Git, ::Avm::Git::Scms::GitSubrepo].freeze
12
+ SCMS = [::Avm::Git::Scms::Git, ::Avm::Git::Scms::GitSubrepo,
13
+ ::Avm::Git::Scms::GitSubtree].freeze
12
14
 
13
15
  def all
14
16
  SCMS
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Git
5
- VERSION = '0.10.1'
5
+ VERSION = '0.12.0'
6
6
  end
7
7
  end
data/locale/en.yml ADDED
@@ -0,0 +1,6 @@
1
+ en:
2
+ avm:
3
+ git:
4
+ scms:
5
+ git_subrepo:
6
+ update_version_scm_message: '**/.gitrepo: fix/update.'
data/locale/pt-BR.yml ADDED
@@ -0,0 +1,6 @@
1
+ pt-BR:
2
+ avm:
3
+ git:
4
+ scms:
5
+ git_subrepo:
6
+ update_version_scm_message: '**/.gitrepo: conserta/atualiza.'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-23 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.57'
19
+ version: '0.61'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.57'
26
+ version: '0.61'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: avm-files
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,40 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.108'
61
+ version: '0.110'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.110.1
62
65
  type: :runtime
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
69
  - - "~>"
67
70
  - !ruby/object:Gem::Version
68
- version: '0.108'
71
+ version: '0.110'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.110.1
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: git
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '1.12'
81
+ version: '1.13'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.13.1
76
85
  type: :runtime
77
86
  prerelease: false
78
87
  version_requirements: !ruby/object:Gem::Requirement
79
88
  requirements:
80
89
  - - "~>"
81
90
  - !ruby/object:Gem::Version
82
- version: '1.12'
91
+ version: '1.13'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.13.1
83
95
  - !ruby/object:Gem::Dependency
84
96
  name: aranha-parsers
85
97
  requirement: !ruby/object:Gem::Requirement
@@ -121,21 +133,10 @@ extensions: []
121
133
  extra_rdoc_files: []
122
134
  files:
123
135
  - lib/avm/git.rb
124
- - lib/avm/git/auto_commit/commit_info.rb
125
- - lib/avm/git/auto_commit/rules.rb
126
- - lib/avm/git/auto_commit/rules/base.rb
127
- - lib/avm/git/auto_commit/rules/last.rb
128
- - lib/avm/git/auto_commit/rules/manual.rb
129
- - lib/avm/git/auto_commit/rules/new.rb
130
- - lib/avm/git/auto_commit/rules/nth.rb
131
- - lib/avm/git/auto_commit/rules/unique.rb
132
- - lib/avm/git/auto_commit_path.rb
133
- - lib/avm/git/auto_commit_path/ruby.rb
134
136
  - lib/avm/git/commit.rb
135
137
  - lib/avm/git/commit/class_methods.rb
136
138
  - lib/avm/git/commit/diff_tree_line.rb
137
139
  - lib/avm/git/commit/file.rb
138
- - lib/avm/git/file_auto_fixup.rb
139
140
  - lib/avm/git/issue.rb
140
141
  - lib/avm/git/issue/complete.rb
141
142
  - lib/avm/git/issue/complete/commits.rb
@@ -182,10 +183,18 @@ files:
182
183
  - lib/avm/git/scms.rb
183
184
  - lib/avm/git/scms/git.rb
184
185
  - lib/avm/git/scms/git/change_tracker.rb
186
+ - lib/avm/git/scms/git/changed_file.rb
187
+ - lib/avm/git/scms/git/changed_files.rb
185
188
  - lib/avm/git/scms/git/commit.rb
186
189
  - lib/avm/git/scms/git/commit/deploy.rb
187
190
  - lib/avm/git/scms/git/commit/deploy_methods.rb
191
+ - lib/avm/git/scms/git/commits.rb
192
+ - lib/avm/git/scms/git/interval.rb
193
+ - lib/avm/git/scms/git/milestones.rb
194
+ - lib/avm/git/scms/git/run_commit.rb
195
+ - lib/avm/git/scms/git_sub_base.rb
188
196
  - lib/avm/git/scms/git_subrepo.rb
197
+ - lib/avm/git/scms/git_subtree.rb
189
198
  - lib/avm/git/scms/provider.rb
190
199
  - lib/avm/git/subrepo_check.rb
191
200
  - lib/avm/git/subrepo_check/parent.rb
@@ -195,6 +204,8 @@ files:
195
204
  - lib/avm/git/vendor.rb
196
205
  - lib/avm/git/vendor/github.rb
197
206
  - lib/avm/git/version.rb
207
+ - locale/en.yml
208
+ - locale/pt-BR.yml
198
209
  homepage:
199
210
  licenses: []
200
211
  metadata: {}
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Git
7
- module AutoCommit
8
- class CommitInfo
9
- enable_immutable
10
-
11
- immutable_accessor :fixup, :message
12
-
13
- def git_commit_args
14
- r = fixup.if_present([]) { |v| ['--fixup', v.sha1] }
15
- r += message.if_present([]) { |v| ['--message', v] }
16
- return r if r.any?
17
-
18
- raise 'Argument list is empty'
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Git
7
- module AutoCommit
8
- module Rules
9
- class Base
10
- class << self
11
- def keys
12
- [long_key, short_key]
13
- end
14
-
15
- def long_key
16
- name.demodulize.variableize
17
- end
18
-
19
- def short_key
20
- long_key[0, 1]
21
- end
22
- end
23
-
24
- def with_file(file)
25
- self.class.const_get('WithFile').new(self, file)
26
- end
27
-
28
- class WithFile
29
- common_constructor :rule, :file
30
-
31
- def new_commit_info
32
- ::Avm::Git::AutoCommit::CommitInfo.new
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/git/auto_commit/rules/base'
4
-
5
- module Avm
6
- module Git
7
- module AutoCommit
8
- module Rules
9
- class Last < ::Avm::Git::AutoCommit::Rules::Base
10
- class WithFile < ::Avm::Git::AutoCommit::Rules::Base::WithFile
11
- def commit_info
12
- file.commits.last.if_present { |v| new_commit_info.fixup(v) }
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/git/auto_commit/rules/base'
4
-
5
- module Avm
6
- module Git
7
- module AutoCommit
8
- module Rules
9
- class Manual < ::Avm::Git::AutoCommit::Rules::Base
10
- class WithFile < ::Avm::Git::AutoCommit::Rules::Base::WithFile
11
- enable_speaker
12
-
13
- COMMIT_FORMAT = '%h - %s (%cr)'
14
- SKIP_OPTION = 's'
15
-
16
- def commit_info
17
- return nil unless file.commits.any?
18
-
19
- commits_banner
20
- input('Which commit?', list: commits_by_position).if_present do |v|
21
- new_commit_info.fixup(v)
22
- end
23
- end
24
-
25
- def commits_banner
26
- file.commits.each_with_index do |commit, _index|
27
- infov " #{commit.position}", format_commit(commit)
28
- end
29
- infov " #{SKIP_OPTION}", 'skip'
30
- end
31
-
32
- def commits_by_position
33
- (file.commits.map { |commit| [commit.position.to_s, commit] } + [[SKIP_OPTION, nil]])
34
- .to_h
35
- end
36
-
37
- def format_commit(commit)
38
- commit.format(COMMIT_FORMAT)
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/git/auto_commit/rules/base'
4
- require 'avm/git/auto_commit_path'
5
-
6
- module Avm
7
- module Git
8
- module AutoCommit
9
- module Rules
10
- class New < ::Avm::Git::AutoCommit::Rules::Base
11
- class WithFile < ::Avm::Git::AutoCommit::Rules::Base::WithFile
12
- def auto_commit_path
13
- ::Avm::Git::AutoCommitPath.new(file.git, file.path)
14
- end
15
-
16
- def commit_info
17
- new_commit_info.message(auto_commit_path.commit_message)
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/git/auto_commit/rules/base'
4
-
5
- module Avm
6
- module Git
7
- module AutoCommit
8
- module Rules
9
- class Nth < ::Avm::Git::AutoCommit::Rules::Base
10
- SHORT_KEY = 't'
11
-
12
- class << self
13
- def short_key
14
- SHORT_KEY
15
- end
16
- end
17
-
18
- common_constructor :number do
19
- self.number = number.to_i
20
- end
21
-
22
- class WithFile < ::Avm::Git::AutoCommit::Rules::Base::WithFile
23
- def commit_info
24
- file.commits(number - 1).if_present { |v| new_commit_info.fixup(v) }
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/git/auto_commit/rules/base'
4
-
5
- module Avm
6
- module Git
7
- module AutoCommit
8
- module Rules
9
- class Unique < ::Avm::Git::AutoCommit::Rules::Base
10
- class WithFile < ::Avm::Git::AutoCommit::Rules::Base::WithFile
11
- def commit_info
12
- return nil unless file.commits.count == 1
13
-
14
- new_commit_info.fixup(file.commits.first)
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- ::EacRubyUtils.require_sub __FILE__
6
-
7
- module Avm
8
- module Git
9
- module AutoCommit
10
- module Rules
11
- RULES_CLASSES = %w[last manual new nth unique]
12
- .map { |key| ::Avm::Git::AutoCommit::Rules.const_get(key.camelcase) }
13
-
14
- class << self
15
- def parse(string)
16
- parts = string.split(':')
17
-
18
- klass = rule_class_by_key(parts.shift)
19
- klass.new(*parts)
20
- end
21
-
22
- def rule_class_by_key(key)
23
- RULES_CLASSES.find { |klass| klass.keys.include?(key) } ||
24
- raise("Rule not find with key \"#{key}\" (Available: " +
25
- RULES_CLASSES.flat_map(&:keys).join(', ') + ')')
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Git
7
- class AutoCommitPath
8
- module Ruby
9
- RUBY_CLASS_NAME_PATTERNS = [%r{lib/((?!.*/lib/).+)\.rb\z}, %r{app/[^/]+/(.+)\.rb\z}].freeze
10
-
11
- def ruby_class_name
12
- RUBY_CLASS_NAME_PATTERNS.each do |pattern|
13
- pattern.if_match(relative_path.to_path, false) { |m| return m[1].camelize }
14
- end
15
- nil
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Git
7
- class AutoCommitPath
8
- require_sub __FILE__, include_modules: true
9
- common_constructor :git, :path do
10
- self.path = path.to_pathname
11
- end
12
-
13
- def class_name
14
- ruby_class_name || relative_path.to_path
15
- end
16
-
17
- def commit_message
18
- r = class_name
19
- r += ': remove' unless path.file?
20
- r + '.'
21
- end
22
-
23
- def relative_path
24
- path.expand_path.relative_path_from(git.root_path.expand_path)
25
- end
26
- end
27
- end
28
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/git/auto_commit/commit_info'
4
- require 'eac_ruby_utils/core_ext'
5
-
6
- module Avm
7
- module Git
8
- class FileAutoFixup
9
- enable_speaker
10
- enable_simple_cache
11
- enable_listable
12
-
13
- common_constructor :git, :path, :rules do
14
- self.path = path.to_pathname.expand_path(git.root_path)
15
- end
16
-
17
- COMMITS_SEARCH_INTERVAL = 'origin/master..HEAD'
18
-
19
- def git_relative_path
20
- path.to_pathname.relative_path_from(git.root_path)
21
- end
22
-
23
- def run
24
- start_banner
25
- run_commit || warn("No rule returned commit information for \"#{path}\"")
26
- end
27
-
28
- private
29
-
30
- def commit_args
31
- commit_info.if_present([], &:git_commit_args) + ['--', git_relative_path]
32
- end
33
-
34
- def commit_info_uncached
35
- rules.lazy.map { |rule| rule.with_file(self).commit_info }.find(&:present?)
36
- end
37
-
38
- def start_banner
39
- infov 'Path', path
40
- infov ' Commits found', commits.count
41
- end
42
-
43
- def run_commit
44
- return false if commit_info.blank?
45
-
46
- infov ' Commit arguments', ::Shellwords.join(commit_args)
47
- run_git_add_and_commit
48
- success ' Commited'
49
- true
50
- end
51
-
52
- def run_git_add_and_commit
53
- git.execute!('reset', '--soft', 'HEAD')
54
- if path.exist?
55
- git.execute!('add', git_relative_path)
56
- else
57
- git.execute!('rm', '-f', git_relative_path)
58
- end
59
- git.execute!('commit', *commit_args)
60
- end
61
-
62
- def commits_uncached
63
- git.execute!('log', '--pretty=format:%H', COMMITS_SEARCH_INTERVAL, '--', path)
64
- .each_line.map { |sha1| ::Avm::Git::Commit.new(git, sha1.strip) }
65
- .reject { |commit| commit.subject.start_with?('fixup!') }
66
- .each_with_index.map { |commit, index| CommitDelegator.new(commit, index) }
67
- end
68
-
69
- class CommitDelegator < ::SimpleDelegator
70
- attr_reader :index
71
-
72
- def initialize(commit, index)
73
- super(commit)
74
- @index = index
75
- end
76
-
77
- def position
78
- index + 1
79
- end
80
- end
81
- end
82
- end
83
- end