eac_git 0.3.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfeec96bd8fe6d5e2457c476ccf55f41633b25e17c717d57a26b8f70a57ef8be
4
- data.tar.gz: 2cf75e8702fbad6dc28eca2554ec5d37d2d63468040fdc2f828672a16ad114e2
3
+ metadata.gz: bf9327d87f6a011e773ef9631b373680cd3a24d08cffe26322ce674f65c886bf
4
+ data.tar.gz: d645885dfa9b7173007e35184f24404092c40a5c06d917e3a246d45019b44eef
5
5
  SHA512:
6
- metadata.gz: '09c6a986c0e5c1bc3ff2f04fefe1b5c637ecae061098ca70ea839f30d155846fef842e4c3439544072b0cab647a6194cfba47d07e37b01db8347cca2808a48e2'
7
- data.tar.gz: 06c25d45b807a312ca5c1d73ef05fa870782228c1b219ccc8e863f662f67a5c93ee2e25196648d71dd9b957c7a1165accbd9bd0285814c8b5147142895a9ed4f
6
+ metadata.gz: c11a55e02341d674725d85dd0921dca0ad97ed067586e71ab2821d3d4ebc0c4941f74e3648c43cbe7bf136e9d925035c10c102fb7bf8b6fc59d49ad757a1f256
7
+ data.tar.gz: e6ee32ee1cb05a9c14173d3d5df118791b6841a9a9d4bddaff36c44ee152f1bb1a92d19df12100f9a03457a1375d254bea83bc66778426d9fce39a905cae18a1
@@ -20,6 +20,10 @@ module EacGit
20
20
  r
21
21
  end
22
22
 
23
+ def tar_uncached
24
+ env.executable('tar', '--version')
25
+ end
26
+
23
27
  module GitCommandExtensions
24
28
  def command(*args)
25
29
  super(*args).envvar('PATH', path_with_git_subrepo)
data/lib/eac_git/local.rb CHANGED
@@ -12,6 +12,10 @@ module EacGit
12
12
  self.root_path = root_path.to_pathname
13
13
  end
14
14
 
15
+ def commit(ref, required = false)
16
+ rev_parse(ref, required).if_present { |v| ::EacGit::Local::Commit.new(self, v) }
17
+ end
18
+
15
19
  def descendant?(descendant, ancestor)
16
20
  base = merge_base(descendant, ancestor)
17
21
  return false if base.blank?
@@ -35,13 +39,17 @@ module EacGit
35
39
  ::EacGit::Executables.git.command('-C', root_path.to_path, *args)
36
40
  end
37
41
 
42
+ def raise_error(message)
43
+ raise "#{root_path}: #{message}"
44
+ end
45
+
38
46
  def rev_parse(ref, required = false)
39
47
  r = command('rev-parse', ref).execute!(exit_outputs: { 128 => nil, 32_768 => nil })
40
48
  r.strip! if r.is_a?(String)
41
49
  return r if r.present?
42
50
  return nil unless required
43
51
 
44
- raise "Reference \"#{ref}\" not found"
52
+ raise_error "Reference \"#{ref}\" not found"
45
53
  end
46
54
 
47
55
  def subrepo(subpath)
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacGit
6
+ class Local
7
+ class Commit
8
+ require_sub __FILE__, include_modules: true
9
+ enable_simple_cache
10
+
11
+ FIELDS = {
12
+ author_name: '%an', author_email: '%ae', author_date: '%ai',
13
+ subject: '%s',
14
+ author_all: '%an <%ae>, %ai',
15
+ commiter_name: '%cn', commiter_email: '%ce', commiter_date: '%ci',
16
+ commiter_all: '%cn <%ce>, %ci'
17
+ }.freeze
18
+
19
+ common_constructor :repo, :hash
20
+
21
+ def format(format)
22
+ repo.command('--no-pager', 'log', '-1', "--pretty=format:#{format}", hash).execute!.strip
23
+ end
24
+
25
+ FIELDS.each do |field, format|
26
+ define_method(field) { format(format) }
27
+ end
28
+
29
+ def changed_files_uncached
30
+ diff_tree_execute.each_line.map do |line|
31
+ ::EacGit::Local::Commit::ChangedFile.new(self, line)
32
+ end
33
+ end
34
+
35
+ def changed_files_size_uncached
36
+ changed_files.inject(0) { |a, e| a + e.dst_size }
37
+ end
38
+
39
+ def root_child?
40
+ format('%P').blank?
41
+ end
42
+
43
+ private
44
+
45
+ def diff_tree_execute
46
+ args = []
47
+ args << '--root' if root_child?
48
+ args << hash
49
+ repo.command(*::EacGit::Local::Commit::DiffTreeLine::GIT_COMMAND_ARGS, *args).execute!
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacGit
6
+ class Local
7
+ class Commit
8
+ module Archive
9
+ # @return [EacRubyUtils::Envs::Command]
10
+ def archive_to_dir(path)
11
+ path = path.to_pathname
12
+ repo.command('archive', '--format=tar', hash).pipe(
13
+ ::EacGit::Executables.tar.command('-xC', path)
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_git/local/commit/diff_tree_line'
5
+
6
+ module EacGit
7
+ class Local
8
+ class Commit
9
+ class ChangedFile
10
+ enable_simple_cache
11
+
12
+ attr_reader :commit, :diff_tree
13
+
14
+ # @param commit [EacGit::Local::Commit]
15
+ # @param diff_tree_line [String] A line from command "repo diff-tree --no-commit-id -r
16
+ # --full-index"'s output.
17
+ def initialize(commit, diff_tree_line)
18
+ @commit = commit
19
+ @diff_tree = ::EacGit::Local::Commit::DiffTreeLine.new(diff_tree_line)
20
+ end
21
+
22
+ delegate(*::EacGit::Local::Commit::DiffTreeLine::FIELDS, to: :diff_tree)
23
+
24
+ def to_s
25
+ "#{path}|#{status}"
26
+ end
27
+
28
+ def src_size_uncached
29
+ size(src_sha1)
30
+ end
31
+
32
+ def dst_size_uncached
33
+ size(dst_sha1)
34
+ end
35
+
36
+ private
37
+
38
+ def size(id)
39
+ return 0 if /\A0+\z/.match(id)
40
+
41
+ commit.repo.command('cat-file', '-s', id).execute!.strip.to_i
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacGit
4
+ class Local
5
+ class Commit
6
+ class DiffTreeLine
7
+ DIFF_TREE_PATTERN = /\A:(\d{6}) (\d{6}) (\S+) (\S+) (\S+)\t(\S.*)\z/.freeze
8
+ FIELDS = %w[src_mode dst_mode src_sha1 dst_sha1 status path].freeze
9
+ GIT_COMMAND_ARGS = %w[-c core.quotepath=off diff-tree --no-commit-id -r --full-index].freeze
10
+
11
+ attr_reader(*FIELDS)
12
+
13
+ # line: a line of command "git [GIT_COMMAND_ARGS]"'s output.
14
+ # Reference: https://git-scm.com/docs/git-diff-tree
15
+ def initialize(line)
16
+ m = DIFF_TREE_PATTERN.match(line.strip)
17
+ raise "\"#{line}\" did not match pattern" unless m
18
+
19
+ FIELDS.count.times { |i| send("#{FIELDS[i]}=", m[i + 1]) }
20
+ end
21
+
22
+ def fields
23
+ FIELDS.map { |field| [field, send(field)] }.to_h
24
+ end
25
+
26
+ private
27
+
28
+ attr_writer(*FIELDS)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -12,7 +12,8 @@ module EacGit
12
12
 
13
13
  common_constructor :local, :subpath do
14
14
  self.subpath = subpath.to_pathname
15
- raise "Config file \"#{config_absolute_path}\" not found" unless config_absolute_path.file?
15
+ local.raise_error "Config file \"#{config_absolute_path}\" not found" unless
16
+ config_absolute_path.file?
16
17
  end
17
18
 
18
19
  def command(subrepo_subcommand, *subrepo_subcommand_args)
data/lib/eac_git/rspec.rb CHANGED
@@ -5,12 +5,17 @@ require 'eac_git/executables'
5
5
 
6
6
  module EacGit
7
7
  module Rspec
8
+ require_sub __FILE__
9
+
8
10
  class << self
9
11
  def configure
10
12
  ::EacRubyUtils::Rspec::Conditional.default.add(:git) do
11
13
  ::EacGit::Executables.git.validate
12
14
  end
13
- RSpec.configure { |config| ::EacRubyUtils::Rspec::Conditional.default.configure(config) }
15
+ RSpec.configure do |config|
16
+ ::EacRubyUtils::Rspec::Conditional.default.configure(config)
17
+ config.include ::EacGit::Rspec::StubbedGitLocalRepo
18
+ end
14
19
  end
15
20
  end
16
21
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/local'
4
+ require 'eac_ruby_utils/envs'
5
+ require 'fileutils'
6
+ require 'tmpdir'
7
+
8
+ module EacGit
9
+ module Rspec
10
+ module StubbedGitLocalRepo
11
+ def stubbed_git_local_repo(bare = false)
12
+ path = ::Dir.mktmpdir
13
+ ::EacRubyUtils::Envs.local.command(stubbed_git_local_repo_args(path, bare)).execute!
14
+ repo = StubbedGitRepository.new(path)
15
+ repo.command('config', 'user.email', 'theuser@example.net').execute!
16
+ repo.command('config', 'user.name', 'The User').execute!
17
+ repo
18
+ end
19
+
20
+ private
21
+
22
+ def stubbed_git_local_repo_args(path, bare)
23
+ r = %w[git init]
24
+ r << '--bare' if bare
25
+ r + [path]
26
+ end
27
+
28
+ class StubbedGitRepository < ::EacGit::Local
29
+ def file(*subpath)
30
+ StubbedGitRepositoryFile.new(self, subpath)
31
+ end
32
+ end
33
+
34
+ class StubbedGitRepositoryFile
35
+ attr_reader :git, :subpath
36
+
37
+ def initialize(git, subpath)
38
+ @git = git
39
+ @subpath = subpath
40
+ end
41
+
42
+ def path
43
+ git.root_path.join(*subpath)
44
+ end
45
+
46
+ def touch
47
+ ::FileUtils.touch(path.to_path)
48
+ end
49
+
50
+ def delete
51
+ path.unlink
52
+ end
53
+
54
+ def write(content)
55
+ path.write(content)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacGit
4
- VERSION = '0.3.3'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.6.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: 2021-02-21 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -45,25 +45,33 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.0.8
47
47
  - !ruby/object:Gem::Dependency
48
- name: eac_ruby_gem_support
48
+ name: aranha-parsers
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.1'
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.1.2
53
+ version: '0.7'
57
54
  type: :development
58
55
  prerelease: false
59
56
  version_requirements: !ruby/object:Gem::Requirement
60
57
  requirements:
61
58
  - - "~>"
62
59
  - !ruby/object:Gem::Version
63
- version: '0.1'
64
- - - ">="
60
+ version: '0.7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: eac_ruby_gem_support
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.2'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
65
73
  - !ruby/object:Gem::Version
66
- version: 0.1.2
74
+ version: '0.2'
67
75
  description:
68
76
  email:
69
77
  executables: []
@@ -73,12 +81,17 @@ files:
73
81
  - lib/eac_git.rb
74
82
  - lib/eac_git/executables.rb
75
83
  - lib/eac_git/local.rb
84
+ - lib/eac_git/local/commit.rb
85
+ - lib/eac_git/local/commit/archive.rb
86
+ - lib/eac_git/local/commit/changed_file.rb
87
+ - lib/eac_git/local/commit/diff_tree_line.rb
76
88
  - lib/eac_git/local/dirty_files.rb
77
89
  - lib/eac_git/local/subrepo.rb
78
90
  - lib/eac_git/local/subrepo/config.rb
79
91
  - lib/eac_git/remote.rb
80
92
  - lib/eac_git/remote/ls_result.rb
81
93
  - lib/eac_git/rspec.rb
94
+ - lib/eac_git/rspec/stubbed_git_local_repo.rb
82
95
  - lib/eac_git/version.rb
83
96
  - vendor/git-subrepo/Changes
84
97
  - vendor/git-subrepo/Intro.pod
@@ -283,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
296
  - !ruby/object:Gem::Version
284
297
  version: '0'
285
298
  requirements: []
286
- rubygems_version: 3.0.8
299
+ rubygems_version: 3.0.9
287
300
  signing_key:
288
301
  specification_version: 4
289
302
  summary: Put here de description.