eac_git 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 950c9a3032c7b567df429f08449a4c3cc79cf09088c34baff66a091c5e8b4cc8
4
+ data.tar.gz: 645347929c4062d2dd982909d03919629d1327790f0a707ec108f9d2715cf3b5
5
+ SHA512:
6
+ metadata.gz: 59eb9e3bd7d20d5345768ee7d6c1837169f24b7fa48cc14f4f241677ada1d770974ce90901caa04ed08323c221bd15891829f29f104ed14f4718f8b096b926d7
7
+ data.tar.gz: 368ef48ac16375e6387e1ace60f61e6e03ecb09a070af72da64b88262d6f9e19960123aea81faafece3e832e4bc38140da7a60d8780f58dbf1bc409b9c215522
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacGit
6
+ require_sub __FILE__
7
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/envs'
4
+ require 'eac_ruby_utils/simple_cache'
5
+
6
+ module EacGit
7
+ module Executables
8
+ class << self
9
+ include ::EacRubyUtils::SimpleCache
10
+
11
+ def env
12
+ ::EacRubyUtils::Envs.local
13
+ end
14
+
15
+ private
16
+
17
+ %w[git].each do |program|
18
+ define_method(program.underscore + '_uncached') do
19
+ env.executable(program, '--version')
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/executables'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacGit
7
+ # A Git repository in local filesystem.
8
+ class Local
9
+ require_sub __FILE__
10
+
11
+ common_constructor :root_path do
12
+ self.root_path = root_path.to_pathname
13
+ end
14
+
15
+ def descendant?(descendant, ancestor)
16
+ base = merge_base(descendant, ancestor)
17
+ return false if base.blank?
18
+
19
+ revparse = command('rev-parse', '--verify', ancestor).execute!.strip
20
+ base == revparse
21
+ end
22
+
23
+ def merge_base(*commits)
24
+ refs = commits.dup
25
+ while refs.count > 1
26
+ refs[1] = merge_base_pair(refs[0], refs[1])
27
+ return nil if refs[1].blank?
28
+
29
+ refs.shift
30
+ end
31
+ refs.first
32
+ end
33
+
34
+ def command(*args)
35
+ ::EacGit::Executables.git.command('-C', root_path.to_path, *args)
36
+ end
37
+
38
+ def rev_parse(ref, required = false)
39
+ r = command('rev-parse', ref).execute!(exit_outputs: { 128 => nil, 32_768 => nil })
40
+ r.strip! if r.is_a?(String)
41
+ return r if r.present?
42
+ return nil unless required
43
+
44
+ raise "Reference \"#{ref}\" not found"
45
+ end
46
+
47
+ def subrepo(subpath)
48
+ ::EacGit::Local::Subrepo.new(self, subpath)
49
+ end
50
+
51
+ private
52
+
53
+ def merge_base_pair(commit1, commit2)
54
+ command('merge-base', commit1, commit2).execute!(exit_outputs: { 256 => nil }).strip
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/remote'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacGit
7
+ class Local
8
+ # A git-subrepo (https://github.com/ingydotnet/git-subrepo) in a [EacGit::Local].
9
+ class Subrepo
10
+ require_sub __FILE__
11
+ enable_simple_cache
12
+
13
+ common_constructor :local, :subpath do
14
+ self.subpath = subpath.to_pathname
15
+ raise "Config file \"#{config_absolute_path}\" not found" unless config_absolute_path.file?
16
+ end
17
+
18
+ def command(subrepo_subcommand, *subrepo_subcommand_args)
19
+ local.command('subrepo', subrepo_subcommand, subpath.to_path,
20
+ *subrepo_subcommand_args)
21
+ end
22
+
23
+ delegate(*::EacGit::Local::Subrepo::Config::MAPPING.keys, to: :config)
24
+
25
+ def write_config
26
+ config_absolute_path.write(config.to_content)
27
+ end
28
+
29
+ private
30
+
31
+ def config_uncached
32
+ ::EacGit::Local::Subrepo::Config.from_file(config_absolute_path)
33
+ end
34
+
35
+ def config_absolute_path_uncached
36
+ config_relative_path.expand_path(local.root_path)
37
+ end
38
+
39
+ def config_relative_path_uncached
40
+ subpath.join('.gitrepo')
41
+ end
42
+
43
+ def remote_uncached
44
+ ::EacGit::Remote.new(remote_uri)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'parseconfig'
5
+
6
+ module EacGit
7
+ class Local
8
+ class Subrepo
9
+ class Config
10
+ MAPPING = {
11
+ command_version: :cmdver, commit_id: :commit, join_method: :method,
12
+ parent_commit_id: :parent, remote_branch: :branch, remote_uri: :remote
13
+ }.freeze
14
+
15
+ class << self
16
+ def from_file(file_path)
17
+ new(
18
+ ::ParseConfig.new(file_path.to_pathname)['subrepo']
19
+ )
20
+ end
21
+ end
22
+
23
+ common_constructor :values do
24
+ self.values = values.with_indifferent_access
25
+ end
26
+
27
+ MAPPING.each do |method_name, _config_key|
28
+ define_method(method_name) do
29
+ values[MAPPING.fetch(method_name)]
30
+ end
31
+
32
+ define_method("#{method_name}=") do |value|
33
+ values[MAPPING.fetch(method_name)] = value
34
+ end
35
+ end
36
+
37
+ def to_content
38
+ "[subrepo]\n" + MAPPING.map { |k, v| " #{v} = #{send(k)}\n" }.join
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/executables'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacGit
7
+ # A Git remote repository referenced by URI.
8
+ class Remote
9
+ require_sub __FILE__
10
+
11
+ common_constructor :uri
12
+
13
+ def ls
14
+ ::EacGit::Remote::LsResult.by_ls_remote_command_output(
15
+ ::EacGit::Executables.git.command('ls-remote', uri).execute!
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacGit
6
+ class Remote
7
+ class LsResult
8
+ class << self
9
+ def by_ls_remote_command_output(output)
10
+ new(
11
+ output.each_line.map { |line| line.strip.split(/\s+/) }.map { |x| [x[1], x[0]] }.to_h
12
+ )
13
+ end
14
+ end
15
+
16
+ common_constructor :hashes
17
+ delegate :fetch, :'[]', :count, :any?, :empty?, to: :hashes
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacGit
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eac_git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Put here the authors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eac_ruby_utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.37'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.37'
27
+ - !ruby/object:Gem::Dependency
28
+ name: parseconfig
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.0.8
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.8
47
+ - !ruby/object:Gem::Dependency
48
+ name: eac_ruby_gem_support
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.1'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.1.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '0.1'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.1.2
67
+ description:
68
+ email:
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - lib/eac_git.rb
74
+ - lib/eac_git/executables.rb
75
+ - lib/eac_git/local.rb
76
+ - lib/eac_git/local/subrepo.rb
77
+ - lib/eac_git/local/subrepo/config.rb
78
+ - lib/eac_git/remote.rb
79
+ - lib/eac_git/remote/ls_result.rb
80
+ - lib/eac_git/version.rb
81
+ homepage:
82
+ licenses: []
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.7.7
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Put here de description.
104
+ test_files: []