avm-tools 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/git/file_auto_fixup.rb +95 -0
- data/lib/avm/patches/eac_launcher_git_base.rb +16 -0
- data/lib/avm/tools/runner/git.rb +5 -0
- data/lib/avm/tools/runner/git/auto_fixup.rb +46 -0
- data/lib/avm/tools/runner/git/dirty_files.rb +49 -0
- data/lib/avm/tools/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c43972836fb5b4414055f3b478a1f85e814c1c86bf84d2975031c7aa1890902
|
4
|
+
data.tar.gz: c0ab56207e455dee36a9dc480b23f8e1d6e494421913c830dd746779d9293f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e482a38d4fa941481cf58e635776884ed86fece1df69e458b2be979de63f67f345ae738218d4f911ac6e0c184811eb6b77d88dce6b6169670e7e7fc48ae3781
|
7
|
+
data.tar.gz: 5a969b9d92a2b1d21dd85f99d0d286a7e4f01bc9d101d60632d43eea5a70fea98e41bbf00f7a2331c62e7855b9c079b5171eae5208ee25354b8b40eb9dd9a2b1
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
class FileAutoFixup
|
8
|
+
enable_console_speaker
|
9
|
+
enable_simple_cache
|
10
|
+
|
11
|
+
common_constructor :git, :path
|
12
|
+
|
13
|
+
COMMIT_FORMAT = '%h - %s (%cr)'
|
14
|
+
COMMITS_SEARCH_INTERVAL = 'origin/master..HEAD'
|
15
|
+
SKIP_OPTION = 's'
|
16
|
+
|
17
|
+
def run
|
18
|
+
start_banner
|
19
|
+
if commits.count.zero?
|
20
|
+
run_no_commits_found
|
21
|
+
elsif commits.count == 1
|
22
|
+
fixup_commit(commits.first)
|
23
|
+
else
|
24
|
+
run_commits_selection
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def start_banner
|
31
|
+
infov 'Path', path
|
32
|
+
infov ' Commits found', commits.count
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_no_commits_found
|
36
|
+
infom ' No commits found'
|
37
|
+
end
|
38
|
+
|
39
|
+
def fixup_commit(commit)
|
40
|
+
infov ' Commit selected/found', format_commit(commit)
|
41
|
+
git.execute!('commit', '--fixup', commit.sha1, '--', path)
|
42
|
+
success " Fixup with \"#{format_commit(commit)}\""
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_commits_selection
|
46
|
+
selected_commit = select_commit
|
47
|
+
if selected_commit
|
48
|
+
fixup_commit(selected_commit)
|
49
|
+
else
|
50
|
+
infom ' Skipped'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def select_commit
|
55
|
+
commits_banner
|
56
|
+
request_input('Which commit?', list: commits_by_position)
|
57
|
+
end
|
58
|
+
|
59
|
+
def commits_banner
|
60
|
+
commits.each_with_index do |commit, _index|
|
61
|
+
infov " #{commit.position}", format_commit(commit)
|
62
|
+
end
|
63
|
+
infov " #{SKIP_OPTION}", 'skip'
|
64
|
+
end
|
65
|
+
|
66
|
+
def commits_by_position
|
67
|
+
(commits.map { |commit| [commit.position.to_s, commit] } + [[SKIP_OPTION, nil]]).to_h
|
68
|
+
end
|
69
|
+
|
70
|
+
def commits_uncached
|
71
|
+
git.execute!('log', '--pretty=format:%H', COMMITS_SEARCH_INTERVAL, '--', path)
|
72
|
+
.each_line.map { |sha1| ::Avm::Git::Commit.new(git, sha1.strip) }
|
73
|
+
.reject { |commit| commit.subject.start_with?('fixup!') }
|
74
|
+
.each_with_index.map { |commit, index| CommitDelegator.new(commit, index) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def format_commit(commit)
|
78
|
+
commit.format(COMMIT_FORMAT)
|
79
|
+
end
|
80
|
+
|
81
|
+
class CommitDelegator < ::SimpleDelegator
|
82
|
+
attr_reader :index
|
83
|
+
|
84
|
+
def initialize(commit, index)
|
85
|
+
super(commit)
|
86
|
+
@index = index
|
87
|
+
end
|
88
|
+
|
89
|
+
def position
|
90
|
+
index + 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_launcher/git/base'
|
4
|
+
require 'eac_launcher/git/error'
|
4
5
|
require 'eac_ruby_utils/patch'
|
5
6
|
require 'eac_ruby_utils/require_sub'
|
6
7
|
::EacRubyUtils.require_sub(__FILE__)
|
@@ -17,6 +18,21 @@ module Avm
|
|
17
18
|
args, _options = build_args(args)
|
18
19
|
::EacRubyUtils::Envs.local.command(*args)
|
19
20
|
end
|
21
|
+
|
22
|
+
def dirty_files
|
23
|
+
execute!('status', '--porcelain', '--untracked-files').each_line.map do |line|
|
24
|
+
parse_status_line(line.gsub(/\n\z/, ''))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def parse_status_line(line)
|
31
|
+
m = /\A(.)(.)\s(.+)\z/.match(line)
|
32
|
+
::Kernel.raise "Status pattern does not match \"#{line}\"" unless m
|
33
|
+
::OpenStruct.new(index: m[1], worktree: m[2], path: m[3],
|
34
|
+
absolute_path: ::File.expand_path(m[3], self))
|
35
|
+
end
|
20
36
|
end
|
21
37
|
end
|
22
38
|
end
|
data/lib/avm/tools/runner/git.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/console/docopt_runner'
|
4
4
|
require 'eac_ruby_utils/require_sub'
|
5
|
+
require 'avm/patches/eac_launcher_git_base'
|
5
6
|
::EacRubyUtils.require_sub(__FILE__)
|
6
7
|
|
7
8
|
module Avm
|
@@ -23,6 +24,10 @@ module Avm
|
|
23
24
|
def repository_path
|
24
25
|
options.fetch('-C')
|
25
26
|
end
|
27
|
+
|
28
|
+
def git
|
29
|
+
@git ||= ::EacLauncher::Git::Base.new(repository_path)
|
30
|
+
end
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
4
|
+
require 'avm/git/file_auto_fixup'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Tools
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class Git < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
class AutoFixup < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
DOC = <<~DOCOPT
|
12
|
+
Auto fixup files.
|
13
|
+
|
14
|
+
Usage:
|
15
|
+
__PROGRAM__ [options] [<files>...]
|
16
|
+
__PROGRAM__ -h | --help
|
17
|
+
|
18
|
+
Options:
|
19
|
+
-h --help Mostra esta ajuda.
|
20
|
+
DOCOPT
|
21
|
+
|
22
|
+
def run
|
23
|
+
files.each do |file|
|
24
|
+
::Avm::Git::FileAutoFixup.new(context(:git), file).run
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def files
|
31
|
+
files_from_option || dirty_files
|
32
|
+
end
|
33
|
+
|
34
|
+
def files_from_option
|
35
|
+
r = options.fetch('<files>')
|
36
|
+
r.any? ? r : nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def dirty_files
|
40
|
+
context(:git).dirty_files.map(&:path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Tools
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class Git < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
class DirtyFiles < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
enable_console_speaker
|
12
|
+
|
13
|
+
FIELDS = {
|
14
|
+
i: :index, w: :worktree, p: :path, a: :absolute_path
|
15
|
+
}.map { |k, v| ["%#{k}", v] }.to_h
|
16
|
+
|
17
|
+
FIELDS_DOC = FIELDS.map { |k, v| " #{k} => #{v}" }.join("\n")
|
18
|
+
|
19
|
+
DOC = <<~DOCOPT
|
20
|
+
Lists dirty files in Git repository.
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
__PROGRAM__ [options]
|
24
|
+
__PROGRAM__ -h | --help
|
25
|
+
|
26
|
+
Options:
|
27
|
+
-h --help Mostra esta ajuda.
|
28
|
+
-f --format=<format> Format of each line (See "Format fields") [default: %p].
|
29
|
+
|
30
|
+
Format fields:
|
31
|
+
#{FIELDS_DOC}
|
32
|
+
DOCOPT
|
33
|
+
|
34
|
+
def run
|
35
|
+
context(:git).dirty_files.each do |file|
|
36
|
+
out("#{format_file(file)}\n")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def format_file(file)
|
43
|
+
FIELDS.inject(options.fetch('--format')) { |a, e| a.gsub(e.first, file.send(e.last)) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/avm/tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avm-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha-parsers
|
@@ -76,14 +76,14 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '0.
|
79
|
+
version: '0.15'
|
80
80
|
type: :runtime
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '0.
|
86
|
+
version: '0.15'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: filesize
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- lib/avm/git/commit/deploy.rb
|
189
189
|
- lib/avm/git/commit/diff_tree_line.rb
|
190
190
|
- lib/avm/git/commit/file.rb
|
191
|
+
- lib/avm/git/file_auto_fixup.rb
|
191
192
|
- lib/avm/git/issue.rb
|
192
193
|
- lib/avm/git/issue/complete.rb
|
193
194
|
- lib/avm/git/issue/complete/_commits.rb
|
@@ -227,8 +228,10 @@ files:
|
|
227
228
|
- lib/avm/tools/runner/files.rb
|
228
229
|
- lib/avm/tools/runner/files/rotate.rb
|
229
230
|
- lib/avm/tools/runner/git.rb
|
231
|
+
- lib/avm/tools/runner/git/auto_fixup.rb
|
230
232
|
- lib/avm/tools/runner/git/commit.rb
|
231
233
|
- lib/avm/tools/runner/git/deploy.rb
|
234
|
+
- lib/avm/tools/runner/git/dirty_files.rb
|
232
235
|
- lib/avm/tools/runner/git/issue.rb
|
233
236
|
- lib/avm/tools/runner/git/issue/complete.rb
|
234
237
|
- lib/avm/tools/version.rb
|