avm-git 0.5.0 → 0.7.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/issue/complete.rb +1 -1
- data/lib/avm/git/launcher/base/class_methods.rb +28 -0
- data/lib/avm/git/launcher/base/dirty_files.rb +23 -0
- data/lib/avm/git/launcher/base/remotes.rb +40 -0
- data/lib/avm/git/launcher/base/subrepo.rb +44 -0
- data/lib/avm/git/launcher/base/underlying.rb +63 -0
- data/lib/avm/git/launcher/base.rb +86 -0
- data/lib/avm/git/launcher/error.rb +15 -0
- data/lib/avm/git/launcher/mirror_update.rb +38 -0
- data/lib/avm/git/launcher/publish_base.rb +125 -0
- data/lib/avm/git/launcher/remote.rb +55 -0
- data/lib/avm/git/launcher/sub_warp_base.rb +33 -0
- data/lib/avm/git/launcher/warp_base.rb +67 -0
- data/lib/avm/git/launcher.rb +7 -0
- data/lib/avm/git/launcher_stereotypes/git/local_project_mixin.rb +19 -0
- data/lib/avm/git/launcher_stereotypes/git/publish.rb +15 -0
- data/lib/avm/git/launcher_stereotypes/git/warp.rb +27 -0
- data/lib/avm/git/launcher_stereotypes/git.rb +25 -0
- data/lib/avm/git/launcher_stereotypes/git_subrepo/publish.rb +14 -0
- data/lib/avm/git/launcher_stereotypes/git_subrepo/warp.rb +88 -0
- data/lib/avm/git/launcher_stereotypes/git_subrepo.rb +34 -0
- data/lib/avm/git/launcher_stereotypes/git_subtree/publish.rb +14 -0
- data/lib/avm/git/launcher_stereotypes/git_subtree/warp.rb +32 -0
- data/lib/avm/git/launcher_stereotypes/git_subtree.rb +51 -0
- data/lib/avm/git/launcher_stereotypes/provider.rb +22 -0
- data/lib/avm/git/launcher_stereotypes.rb +11 -0
- data/lib/avm/git/organize/repository.rb +1 -0
- data/lib/avm/git/version.rb +1 -1
- metadata +43 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1b4c7e2df892e08fd3acc46995c6c353476d2f278dbea6d7f4f6610f59c147d
|
4
|
+
data.tar.gz: abfc3a667d26edfd434b471314772e14df09a54fb3c5921cad56c51f2361d400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df7fdde7ab8665aec13a8c1d89279de503a75dc034122c0cfd4b907056741631d834876745431c006ef474107e99075aaf3a3080e700a8d0526d5f4b3afaf110
|
7
|
+
data.tar.gz: a575f67380e389681bbbe28e7d1f738b43eda8d8b2a8578117ba52f2d14d215afe510e6edb4c3fd57f302c0ae5b247eff4cdb188518b8b4eea1c95d67cee6255
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Avm
|
4
|
+
module Git
|
5
|
+
module Launcher
|
6
|
+
class Base < ::Avm::Launcher::Paths::Real
|
7
|
+
module ClassMethods
|
8
|
+
# @return [Avm::Git::Launcher::Base]
|
9
|
+
def by_root(search_base_path)
|
10
|
+
new(find_root(search_base_path).to_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Searches the root path for the Git repository which includes +search_base_path+.
|
14
|
+
# @return [Pathname]
|
15
|
+
def find_root(search_base_path)
|
16
|
+
path = search_base_path.to_pathname.expand_path
|
17
|
+
loop do
|
18
|
+
return path if path.join('.git').exist?
|
19
|
+
raise "\".git\" not found for \"#{search_base_path}\"" if path.parent.root?
|
20
|
+
|
21
|
+
path = path.parent
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
module Launcher
|
8
|
+
class Base < ::Avm::Launcher::Paths::Real
|
9
|
+
module DirtyFiles
|
10
|
+
delegate :dirty?, to: :eac_git
|
11
|
+
|
12
|
+
def dirty_files
|
13
|
+
eac_git.dirty_files.map do |df|
|
14
|
+
::OpenStruct.new(
|
15
|
+
df.to_h.merge(path: df.path.to_path, absolute_path: df.absolute_path.to_path)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'avm/git/launcher/remote'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Git
|
8
|
+
module Launcher
|
9
|
+
class Base < ::Avm::Launcher::Paths::Real
|
10
|
+
module Remotes
|
11
|
+
# @return [Avm::Git::Launcher::Remote]
|
12
|
+
def remote(name)
|
13
|
+
::Avm::Git::Launcher::Remote.new(self, name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def remote_hashs(remote_name)
|
17
|
+
remote(remote_name).ls
|
18
|
+
end
|
19
|
+
|
20
|
+
def remote_exist?(remote_name)
|
21
|
+
remote(remote_name).exist?
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_remote_url(remote_name, url)
|
25
|
+
r = git.remote(remote_name)
|
26
|
+
if !r.url || r.url != url
|
27
|
+
r.remove if r.url
|
28
|
+
git.add_remote(remote_name, url)
|
29
|
+
end
|
30
|
+
r
|
31
|
+
end
|
32
|
+
|
33
|
+
def remote_branch_sha(remote_name, branch_name)
|
34
|
+
remote_hashs(remote_name)["refs/heads/#{branch_name}"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
module Launcher
|
8
|
+
class Base < ::Avm::Launcher::Paths::Real
|
9
|
+
module Subrepo
|
10
|
+
def subrepo_status(subrepo_path)
|
11
|
+
s = execute!('subrepo', 'status', subrepo_path.gsub(%r{\A/}, ''))
|
12
|
+
raise s.strip.to_s if s.include?('is not a subrepo')
|
13
|
+
|
14
|
+
r = subrepo_status_parse_output(s)
|
15
|
+
raise "Empty subrepo status for |#{s}|\n" unless r.any?
|
16
|
+
|
17
|
+
r
|
18
|
+
end
|
19
|
+
|
20
|
+
def subrepo_remote_url(subrepo_path)
|
21
|
+
h = subrepo_status(subrepo_path)
|
22
|
+
url = h['Remote URL']
|
23
|
+
return url if url.present?
|
24
|
+
|
25
|
+
raise "Remote URL is blank for subrepo \"#{subrepo_path}\" (Subrepo status: #{h})"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def subrepo_status_parse_output(output)
|
31
|
+
r = {}.with_indifferent_access
|
32
|
+
output.each_line do |l|
|
33
|
+
m = /\A([^\:]+)\:(.*)\z/.match(l.strip)
|
34
|
+
next unless m && m[2].present?
|
35
|
+
|
36
|
+
r[m[1].strip] = m[2].strip
|
37
|
+
end
|
38
|
+
r
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_git/executables'
|
4
|
+
require 'eac_ruby_utils/envs'
|
5
|
+
require 'git'
|
6
|
+
require 'avm/launcher/paths/real'
|
7
|
+
|
8
|
+
module Avm
|
9
|
+
module Git
|
10
|
+
module Launcher
|
11
|
+
class Base < ::Avm::Launcher::Paths::Real
|
12
|
+
module Underlying
|
13
|
+
def command(*args)
|
14
|
+
args, options = build_args(args)
|
15
|
+
r = ::EacGit::Executables.git.command(*args)
|
16
|
+
(options[:exit_outputs] || {}).each do |status_code, result|
|
17
|
+
r = r.status_result(status_code, result)
|
18
|
+
end
|
19
|
+
r
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute(*args)
|
23
|
+
command(*args).execute
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute!(*args)
|
27
|
+
command(*args).execute!
|
28
|
+
end
|
29
|
+
|
30
|
+
def system!(*args)
|
31
|
+
command(*args).system!
|
32
|
+
end
|
33
|
+
|
34
|
+
def init
|
35
|
+
git
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def build_args(args)
|
42
|
+
options = {}
|
43
|
+
if args.last.is_a?(Hash)
|
44
|
+
options = args.last
|
45
|
+
args.pop
|
46
|
+
end
|
47
|
+
args = args.first if args.first.is_a?(Array)
|
48
|
+
[['-C', self, '--no-pager'] + args, options]
|
49
|
+
end
|
50
|
+
|
51
|
+
def git_uncached
|
52
|
+
FileUtils.mkdir_p(self)
|
53
|
+
if File.exist?(subpath('.git'))
|
54
|
+
::Git.open(self)
|
55
|
+
else
|
56
|
+
::Git.init(self)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_git/local'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/envs'
|
6
|
+
require 'avm/launcher/paths/real'
|
7
|
+
require 'avm/git/launcher/error'
|
8
|
+
|
9
|
+
module Avm
|
10
|
+
module Git
|
11
|
+
module Launcher
|
12
|
+
class Base < ::Avm::Launcher::Paths::Real
|
13
|
+
require_sub __FILE__
|
14
|
+
enable_simple_cache
|
15
|
+
extend ::Avm::Git::Launcher::Base::ClassMethods
|
16
|
+
include ::Avm::Git::Launcher::Base::DirtyFiles
|
17
|
+
include ::Avm::Git::Launcher::Base::Remotes
|
18
|
+
include ::Avm::Git::Launcher::Base::Subrepo
|
19
|
+
include ::Avm::Git::Launcher::Base::Underlying
|
20
|
+
|
21
|
+
attr_reader :eac_git
|
22
|
+
delegate :descendant?, :merge_base, :rev_parse, to: :eac_git
|
23
|
+
|
24
|
+
def initialize(path)
|
25
|
+
super(path)
|
26
|
+
|
27
|
+
@eac_git = ::EacGit::Local.new(path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def init_bare
|
31
|
+
FileUtils.mkdir_p(self)
|
32
|
+
::EacRubyUtils::Envs.local.command('git', 'init', '--bare', self).execute! unless
|
33
|
+
File.exist?(subpath('.git'))
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Pathname]
|
37
|
+
def root_path
|
38
|
+
@root_path ||= self.class.find_root(to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
def descendant?(descendant, ancestor)
|
42
|
+
base = merge_base(descendant, ancestor)
|
43
|
+
return false if base.blank?
|
44
|
+
|
45
|
+
revparse = execute!('rev-parse', '--verify', ancestor).strip
|
46
|
+
base == revparse
|
47
|
+
end
|
48
|
+
|
49
|
+
def subtree_split(prefix)
|
50
|
+
execute!('subtree', '-q', 'split', '-P', prefix).strip
|
51
|
+
end
|
52
|
+
|
53
|
+
def push(remote_name, refspecs, options = {})
|
54
|
+
refspecs = [refspecs] unless refspecs.is_a?(Array)
|
55
|
+
args = ['push']
|
56
|
+
args << '--dry-run' if options[:dryrun]
|
57
|
+
args << '--force' if options[:force]
|
58
|
+
system!(args + [remote_name] + refspecs)
|
59
|
+
end
|
60
|
+
|
61
|
+
def push_all(remote_name)
|
62
|
+
system!('push', '--all', remote_name)
|
63
|
+
system!('push', '--tags', remote_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
def fetch(remote_name, options = {})
|
67
|
+
args = ['fetch', '-p', remote_name]
|
68
|
+
args += %w[--tags --prune-tags --force] if options[:tags]
|
69
|
+
execute!(*args)
|
70
|
+
end
|
71
|
+
|
72
|
+
def current_branch
|
73
|
+
execute!(%w[symbolic-ref -q HEAD]).gsub(%r{\Arefs/heads/}, '').strip
|
74
|
+
end
|
75
|
+
|
76
|
+
def reset_hard(ref)
|
77
|
+
execute!('reset', '--hard', ref)
|
78
|
+
end
|
79
|
+
|
80
|
+
def raise(message)
|
81
|
+
::Kernel.raise Avm::Git::Launcher::Error.new(self, message)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/launcher/errors/base'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
module Launcher
|
8
|
+
class Error < ::Avm::Launcher::Errors::Base
|
9
|
+
def initialize(git_instance, message)
|
10
|
+
super("#{message} (Repository: #{git_instance})")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/git/launcher/base'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
module Launcher
|
8
|
+
class MirrorUpdate < ::Avm::Launcher::Paths::Real
|
9
|
+
include ::EacRubyUtils::SimpleCache
|
10
|
+
|
11
|
+
def initialize(target_path, source_path, source_rev)
|
12
|
+
super(target_path)
|
13
|
+
@target_git = ::Avm::Git::Launcher::Base.new(self)
|
14
|
+
@source_git = ::Avm::Git::Launcher::Base.new(source_path)
|
15
|
+
@source_rev = source_rev
|
16
|
+
run
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def run
|
22
|
+
fetch_remote_source
|
23
|
+
reset_source_rev
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch_remote_source
|
27
|
+
@target_git.git
|
28
|
+
@target_git.assert_remote_url('origin', @source_git)
|
29
|
+
@target_git.fetch('origin', tags: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset_source_rev
|
33
|
+
@target_git.reset_hard(@source_git.rev_parse(@source_rev, true))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/simple_cache'
|
4
|
+
require 'eac_ruby_utils/simple_cache'
|
5
|
+
require 'avm/launcher/publish/base'
|
6
|
+
require 'avm/launcher/publish/check_result'
|
7
|
+
|
8
|
+
module Avm
|
9
|
+
module Git
|
10
|
+
module Launcher
|
11
|
+
class PublishBase < ::Avm::Launcher::Publish::Base
|
12
|
+
include ::EacRubyUtils::SimpleCache
|
13
|
+
enable_speaker
|
14
|
+
|
15
|
+
CHECKERS = %w[remote_url remote_fetch publish_remote_no_exist remote_equal remote_following
|
16
|
+
local_following].freeze
|
17
|
+
|
18
|
+
REMOTE_UNAVAILABLE_MESSAGES = ['could not resolve host', 'connection timed out',
|
19
|
+
'no route to host'].map(&:downcase).freeze
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def internal_check
|
24
|
+
CHECKERS.each do |checker|
|
25
|
+
result = send("#{checker}_check_result")
|
26
|
+
return result if result
|
27
|
+
end
|
28
|
+
divergent_result_check_result
|
29
|
+
rescue ::Avm::Launcher::Instances::Error => e
|
30
|
+
::Avm::Launcher::Publish::CheckResult.blocked(e.message)
|
31
|
+
rescue ::StandardError => e
|
32
|
+
raise e unless remote_unavailable_error?(e)
|
33
|
+
|
34
|
+
::Avm::Launcher::Publish::CheckResult.blocked(e.message)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def remote_url_check_result
|
40
|
+
remote = sgit.remote(remote_name)
|
41
|
+
return if remote.exist? && remote.url.present?
|
42
|
+
|
43
|
+
::Avm::Launcher::Publish::CheckResult.blocked("Remote \"#{remote_name}\" has blank path")
|
44
|
+
end
|
45
|
+
|
46
|
+
def remote_fetch_check_result
|
47
|
+
remote_fetch
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def remote_unavailable_error?(error)
|
52
|
+
error_message = error.message.downcase
|
53
|
+
REMOTE_UNAVAILABLE_MESSAGES.any? do |message|
|
54
|
+
error_message.include?(message)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def publish_remote_no_exist_check_result
|
59
|
+
return nil if sgit.remote_exist?(remote_name)
|
60
|
+
|
61
|
+
::Avm::Launcher::Publish::CheckResult.blocked('Remote does not exist')
|
62
|
+
end
|
63
|
+
|
64
|
+
def remote_equal_check_result
|
65
|
+
return nil unless remote_sha.present? && remote_sha == local_sha
|
66
|
+
|
67
|
+
::Avm::Launcher::Publish::CheckResult.updated('Remote equal')
|
68
|
+
end
|
69
|
+
|
70
|
+
def remote_following_check_result
|
71
|
+
return nil unless remote_sha.present? && sgit.descendant?(remote_sha, local_sha)
|
72
|
+
|
73
|
+
::Avm::Launcher::Publish::CheckResult.outdated('Remote following')
|
74
|
+
end
|
75
|
+
|
76
|
+
def divergent_result_check_result
|
77
|
+
::Avm::Launcher::Publish::CheckResult.blocked(
|
78
|
+
"Divergent (L: #{local_sha}, R: #{remote_sha})"
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def local_following?
|
83
|
+
return true if remote_sha.blank?
|
84
|
+
|
85
|
+
sgit.descendant?(local_sha, remote_sha)
|
86
|
+
end
|
87
|
+
|
88
|
+
def local_following_check_result
|
89
|
+
return nil unless local_following?
|
90
|
+
|
91
|
+
::Avm::Launcher::Publish::CheckResult.pending('Local following')
|
92
|
+
end
|
93
|
+
|
94
|
+
def sgit_uncached
|
95
|
+
::Avm::Git::Launcher::Base.new(instance.warped)
|
96
|
+
end
|
97
|
+
|
98
|
+
def publish
|
99
|
+
info 'Pushing...'
|
100
|
+
sgit.push(remote_name, 'HEAD:master',
|
101
|
+
dryrun: !::Avm::Launcher::Context.current.publish_options[:confirm])
|
102
|
+
info 'Pushed!'
|
103
|
+
end
|
104
|
+
|
105
|
+
def local_sha
|
106
|
+
sgit.git.object('HEAD').sha
|
107
|
+
end
|
108
|
+
|
109
|
+
def remote_sha_uncached
|
110
|
+
remote_fetch
|
111
|
+
b = sgit.git.branches["#{remote_name}/master"]
|
112
|
+
b ? b.gcommit.sha : nil
|
113
|
+
end
|
114
|
+
|
115
|
+
def remote_fetch_uncached
|
116
|
+
sgit.fetch(remote_name)
|
117
|
+
end
|
118
|
+
|
119
|
+
def remote_name
|
120
|
+
::Avm::Git::Launcher::WarpBase::TARGET_REMOTE
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
module Launcher
|
8
|
+
class Remote
|
9
|
+
common_constructor :git, :name
|
10
|
+
|
11
|
+
def exist?
|
12
|
+
git.execute!('remote').each_line.any? { |line| line.strip == name }
|
13
|
+
end
|
14
|
+
|
15
|
+
def ls
|
16
|
+
git.execute!(['ls-remote', name]).each_line.map do |line|
|
17
|
+
x = line.strip.split(/\s+/)
|
18
|
+
[x[1], x[0]]
|
19
|
+
end.to_h
|
20
|
+
end
|
21
|
+
|
22
|
+
# +git remote add ...+
|
23
|
+
def add(url)
|
24
|
+
git.execute!('remote', 'add', name, url)
|
25
|
+
end
|
26
|
+
|
27
|
+
# +git remote rm ...+
|
28
|
+
def remove
|
29
|
+
git.execute!('remote', 'rm', name)
|
30
|
+
end
|
31
|
+
|
32
|
+
# +git remote get-url ...+
|
33
|
+
def url
|
34
|
+
git.execute!('remote', 'get-url', name).strip.if_present(nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
# git remote set-url ...
|
38
|
+
def url_set(url)
|
39
|
+
git.execute!('remote', 'set-url', name, url)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Add or set URL if +url+ is present, remove remote if is blank.
|
43
|
+
def url=(url)
|
44
|
+
if exist? && url.blank?
|
45
|
+
remove
|
46
|
+
elsif exist? && self.url != url
|
47
|
+
url_set(url)
|
48
|
+
elsif !exist?
|
49
|
+
add(url)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/launcher/errors/base'
|
4
|
+
require 'avm/launcher/stereotype'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Git
|
8
|
+
module Launcher
|
9
|
+
module SubWarpBase
|
10
|
+
private
|
11
|
+
|
12
|
+
def parent_instance_uncached
|
13
|
+
r = find_parent_instance(instance.parent)
|
14
|
+
return r if r
|
15
|
+
|
16
|
+
::Avm::Launcher::Errors::Base.new('Git parent not found')
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_parent_instance(current)
|
20
|
+
if ::Avm::Launcher::Stereotype.git_stereotypes.any? { |s| current.stereotype?(s) }
|
21
|
+
return current
|
22
|
+
end
|
23
|
+
|
24
|
+
current.parent ? find_parent_instance(current.parent) : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_parent_git_path
|
28
|
+
instance.logical.gsub(%r{\A#{Regexp.quote(parent_instance.logical)}/}, '')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/git/launcher/mirror_update'
|
4
|
+
require 'avm/launcher/instances/error'
|
5
|
+
require 'avm/git/vendor/github'
|
6
|
+
require 'avm/git/launcher_stereotypes/git/publish'
|
7
|
+
|
8
|
+
module Avm
|
9
|
+
module Git
|
10
|
+
module Launcher
|
11
|
+
# Métodos abstratos:
|
12
|
+
# * source_instance
|
13
|
+
# * source_remote_name
|
14
|
+
# * current_ref
|
15
|
+
class WarpBase < ::Avm::Launcher::Paths::Real
|
16
|
+
include ::EacRubyUtils::SimpleCache
|
17
|
+
|
18
|
+
TARGET_REMOTE = ::Avm::Git::LauncherStereotypes::Git::Publish::PUBLISH_GIT_REMOTE_NAME
|
19
|
+
|
20
|
+
def initialize(instance)
|
21
|
+
@instance = instance
|
22
|
+
cache_git.git.reset_hard(current_ref)
|
23
|
+
cache_git.remote(TARGET_REMOTE).url = target_remote_url
|
24
|
+
super(path)
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
attr_reader :instance
|
30
|
+
|
31
|
+
def validate_source_current_revision
|
32
|
+
if source_git.rev_parse(source_instance.options.git_current_revision, false).present?
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
36
|
+
raise ::Avm::Launcher::Instances::Error, 'Refspec ' \
|
37
|
+
"\"#{source_instance.options.git_current_revision}\" not found in \"#{source_git}\""
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
validate_source_current_revision
|
42
|
+
::Avm::Git::Launcher::MirrorUpdate.new(
|
43
|
+
path,
|
44
|
+
source_instance.real,
|
45
|
+
source_instance.options.git_current_revision
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def path
|
50
|
+
instance.cache_path('git_repository')
|
51
|
+
end
|
52
|
+
|
53
|
+
def source_git_uncached
|
54
|
+
::Avm::Git::Launcher::Base.new(source_instance.real)
|
55
|
+
end
|
56
|
+
|
57
|
+
def cache_git_uncached
|
58
|
+
::Avm::Git::Launcher::Base.new(update)
|
59
|
+
end
|
60
|
+
|
61
|
+
def target_remote_url
|
62
|
+
::Avm::Git::Vendor::Github.to_ssh_url(source_git.git.remote(source_remote_name).url)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_git/local'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Git
|
8
|
+
module LauncherStereotypes
|
9
|
+
class Git
|
10
|
+
module LocalProjectMixin
|
11
|
+
# @return [EacGit::Local]
|
12
|
+
def git_repo
|
13
|
+
@git_repo ||= ::EacGit::Local.new(path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/git/launcher/publish_base'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
module LauncherStereotypes
|
8
|
+
class Git
|
9
|
+
class Publish < ::Avm::Git::Launcher::PublishBase
|
10
|
+
PUBLISH_GIT_REMOTE_NAME = 'publish'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/git/launcher/warp_base'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Git
|
7
|
+
module LauncherStereotypes
|
8
|
+
class Git
|
9
|
+
class Warp < ::Avm::Git::Launcher::WarpBase
|
10
|
+
private
|
11
|
+
|
12
|
+
def current_ref
|
13
|
+
'HEAD'
|
14
|
+
end
|
15
|
+
|
16
|
+
def source_instance
|
17
|
+
instance
|
18
|
+
end
|
19
|
+
|
20
|
+
def source_remote_name
|
21
|
+
::Avm::Git::LauncherStereotypes::Git::Publish::PUBLISH_GIT_REMOTE_NAME
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/launcher/stereotype'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Git
|
8
|
+
module LauncherStereotypes
|
9
|
+
class Git
|
10
|
+
require_sub __FILE__
|
11
|
+
include Avm::Launcher::Stereotype
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def match?(path)
|
15
|
+
File.directory?(path.real.subpath('.git'))
|
16
|
+
end
|
17
|
+
|
18
|
+
def color
|
19
|
+
:white
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/simple_cache'
|
4
|
+
require 'avm/git/launcher/sub_warp_base'
|
5
|
+
require 'avm/launcher/errors/base'
|
6
|
+
require 'avm/launcher/paths/real'
|
7
|
+
require 'avm/git/vendor/github'
|
8
|
+
|
9
|
+
module Avm
|
10
|
+
module Git
|
11
|
+
module LauncherStereotypes
|
12
|
+
class GitSubrepo
|
13
|
+
class Warp < ::Avm::Launcher::Paths::Real
|
14
|
+
include ::Avm::Git::Launcher::SubWarpBase
|
15
|
+
include ::EacRubyUtils::SimpleCache
|
16
|
+
|
17
|
+
attr_reader :instance
|
18
|
+
|
19
|
+
def initialize(instance)
|
20
|
+
@instance = instance
|
21
|
+
check_parent
|
22
|
+
init_aux
|
23
|
+
push_to_aux
|
24
|
+
reset
|
25
|
+
assert_target_remote
|
26
|
+
super(warped_git)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def check_parent
|
32
|
+
return if parent_git_warped.rev_parse(subrepo_parent_hash) &&
|
33
|
+
parent_git_warped.descendant?('HEAD', subrepo_parent_hash)
|
34
|
+
|
35
|
+
raise Avm::Launcher::Errors::Base,
|
36
|
+
"Subrepo parent hash \"#{subrepo_parent_hash}\"" \
|
37
|
+
" not found in \"#{parent_git_warped}\""
|
38
|
+
end
|
39
|
+
|
40
|
+
def subrepo_parent_hash
|
41
|
+
data = parent_git_warped.subrepo_status(to_parent_git_path)
|
42
|
+
h = data['Pull Parent']
|
43
|
+
return h if h.present?
|
44
|
+
|
45
|
+
raise Avm::Launcher::Errors::Base, "Subrepo parent hash is blank: #{data}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def init_aux
|
49
|
+
::Avm::Git::Launcher::Base.new(aux_path).init_bare
|
50
|
+
end
|
51
|
+
|
52
|
+
def parent_git_warped_uncached
|
53
|
+
::Avm::Git::Launcher::Base.new(parent_instance.warped)
|
54
|
+
end
|
55
|
+
|
56
|
+
def aux_path
|
57
|
+
instance.cache_path('subrepo_aux_git_repository')
|
58
|
+
end
|
59
|
+
|
60
|
+
def warped_git_uncached
|
61
|
+
::Avm::Git::Launcher::Base.new(instance.cache_path('git_repository'))
|
62
|
+
end
|
63
|
+
|
64
|
+
def push_to_aux
|
65
|
+
parent_git_warped.execute!('subrepo', 'branch', to_parent_git_path, '-fF')
|
66
|
+
h = parent_git_warped.rev_parse("subrepo/#{to_parent_git_path}", true)
|
67
|
+
parent_git_warped.execute!('push', aux_path, "#{h}:refs/heads/master", '--force')
|
68
|
+
end
|
69
|
+
|
70
|
+
def reset
|
71
|
+
::Avm::Git::Launcher::MirrorUpdate.new(warped_git, aux_path, 'master')
|
72
|
+
end
|
73
|
+
|
74
|
+
def assert_target_remote
|
75
|
+
warped_git.assert_remote_url(::Avm::Git::Launcher::WarpBase::TARGET_REMOTE,
|
76
|
+
target_remote_url)
|
77
|
+
end
|
78
|
+
|
79
|
+
def target_remote_url
|
80
|
+
::Avm::Git::Vendor::Github.to_ssh_url(
|
81
|
+
parent_git_warped.subrepo_remote_url(to_parent_git_path)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/git/launcher/error'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'avm/launcher/stereotype'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Git
|
9
|
+
module LauncherStereotypes
|
10
|
+
class GitSubrepo
|
11
|
+
require_sub __FILE__
|
12
|
+
include Avm::Launcher::Stereotype
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def match?(path)
|
16
|
+
File.exist?(path.real.subpath('.gitrepo')) && subrepo_url(path.real) != 'none'
|
17
|
+
end
|
18
|
+
|
19
|
+
def color
|
20
|
+
:light_cyan
|
21
|
+
end
|
22
|
+
|
23
|
+
def subrepo_url(path)
|
24
|
+
File.read(path.subpath('.gitrepo')).each_line do |l|
|
25
|
+
m = /remote\s*=\s(.+)/.match(l)
|
26
|
+
return m[1] if m
|
27
|
+
end
|
28
|
+
raise ::Avm::Git::Launcher::Error.new(path, '"remote = ... " not found')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/git/launcher/warp_base'
|
4
|
+
require 'avm/git/launcher/sub_warp_base'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Git
|
8
|
+
module LauncherStereotypes
|
9
|
+
class GitSubtree
|
10
|
+
class Warp < ::Avm::Git::Launcher::WarpBase
|
11
|
+
include ::Avm::Git::Launcher::SubWarpBase
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def current_ref
|
16
|
+
instance.cache_key("git_subtree.parent.#{cache_git.git.object('HEAD').sha}") do
|
17
|
+
cache_git.subtree_split(to_parent_git_path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def source_instance
|
22
|
+
parent_instance
|
23
|
+
end
|
24
|
+
|
25
|
+
def source_remote_name
|
26
|
+
instance.project_name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/launcher/stereotype'
|
4
|
+
require 'avm/git/launcher_stereotypes/git'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Git
|
9
|
+
module LauncherStereotypes
|
10
|
+
class GitSubtree
|
11
|
+
require_sub __FILE__
|
12
|
+
include Avm::Launcher::Stereotype
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def match?(path)
|
16
|
+
return false if other_git_stereotype?(path)
|
17
|
+
return false unless other_nogit_stereotype?(path)
|
18
|
+
|
19
|
+
parent = parent_git(path.parent_path)
|
20
|
+
return false unless parent
|
21
|
+
|
22
|
+
::Git.open(parent.real).remote(path.real.basename).url ? true : false
|
23
|
+
end
|
24
|
+
|
25
|
+
def color
|
26
|
+
:green
|
27
|
+
end
|
28
|
+
|
29
|
+
def parent_git(parent_path)
|
30
|
+
return nil unless parent_path
|
31
|
+
|
32
|
+
if ::Avm::Git::LauncherStereotypes::Git.match?(parent_path)
|
33
|
+
parent_path
|
34
|
+
else
|
35
|
+
parent_git(parent_path.parent_path)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def other_git_stereotype?(path)
|
40
|
+
::Avm::Git::LauncherStereotypes::Git.match?(path) ||
|
41
|
+
::Avm::Git::LauncherStereotypes::GitSubrepo.match?(path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def other_nogit_stereotype?(path)
|
45
|
+
Avm::Launcher::Stereotype.nogit_stereotypes.any? { |s| s.match?(path) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/git/launcher_stereotypes/git'
|
4
|
+
require 'avm/git/launcher_stereotypes/git_subrepo'
|
5
|
+
require 'avm/git/launcher_stereotypes/git_subtree'
|
6
|
+
require 'eac_ruby_utils/core_ext'
|
7
|
+
|
8
|
+
module Avm
|
9
|
+
module Git
|
10
|
+
module LauncherStereotypes
|
11
|
+
class Provider
|
12
|
+
STEREOTYPES = [::Avm::Git::LauncherStereotypes::Git,
|
13
|
+
::Avm::Git::LauncherStereotypes::GitSubrepo,
|
14
|
+
::Avm::Git::LauncherStereotypes::GitSubtree].freeze
|
15
|
+
|
16
|
+
def all
|
17
|
+
STEREOTYPES
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/avm/git/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.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-10-
|
11
|
+
date: 2022-10-13 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.
|
19
|
+
version: '0.49'
|
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.
|
26
|
+
version: '0.49'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: avm-files
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0.104'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: git
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.12'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '1.12'
|
81
95
|
- !ruby/object:Gem::Dependency
|
82
96
|
name: aranha-parsers
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +164,31 @@ files:
|
|
150
164
|
- lib/avm/git/issue/complete/validations.rb
|
151
165
|
- lib/avm/git/issue/complete/working_tree.rb
|
152
166
|
- lib/avm/git/issue/deliver.rb
|
167
|
+
- lib/avm/git/launcher.rb
|
168
|
+
- lib/avm/git/launcher/base.rb
|
169
|
+
- lib/avm/git/launcher/base/class_methods.rb
|
170
|
+
- lib/avm/git/launcher/base/dirty_files.rb
|
171
|
+
- lib/avm/git/launcher/base/remotes.rb
|
172
|
+
- lib/avm/git/launcher/base/subrepo.rb
|
173
|
+
- lib/avm/git/launcher/base/underlying.rb
|
174
|
+
- lib/avm/git/launcher/error.rb
|
175
|
+
- lib/avm/git/launcher/mirror_update.rb
|
176
|
+
- lib/avm/git/launcher/publish_base.rb
|
177
|
+
- lib/avm/git/launcher/remote.rb
|
178
|
+
- lib/avm/git/launcher/sub_warp_base.rb
|
179
|
+
- lib/avm/git/launcher/warp_base.rb
|
180
|
+
- lib/avm/git/launcher_stereotypes.rb
|
181
|
+
- lib/avm/git/launcher_stereotypes/git.rb
|
182
|
+
- lib/avm/git/launcher_stereotypes/git/local_project_mixin.rb
|
183
|
+
- lib/avm/git/launcher_stereotypes/git/publish.rb
|
184
|
+
- lib/avm/git/launcher_stereotypes/git/warp.rb
|
185
|
+
- lib/avm/git/launcher_stereotypes/git_subrepo.rb
|
186
|
+
- lib/avm/git/launcher_stereotypes/git_subrepo/publish.rb
|
187
|
+
- lib/avm/git/launcher_stereotypes/git_subrepo/warp.rb
|
188
|
+
- lib/avm/git/launcher_stereotypes/git_subtree.rb
|
189
|
+
- lib/avm/git/launcher_stereotypes/git_subtree/publish.rb
|
190
|
+
- lib/avm/git/launcher_stereotypes/git_subtree/warp.rb
|
191
|
+
- lib/avm/git/launcher_stereotypes/provider.rb
|
153
192
|
- lib/avm/git/organize.rb
|
154
193
|
- lib/avm/git/organize/reference_update.rb
|
155
194
|
- lib/avm/git/organize/repository.rb
|