eac_git 0.3.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_git/executables.rb +4 -0
- data/lib/eac_git/local.rb +4 -0
- data/lib/eac_git/local/commit.rb +53 -0
- data/lib/eac_git/local/commit/archive.rb +19 -0
- data/lib/eac_git/local/commit/changed_file.rb +46 -0
- data/lib/eac_git/local/commit/diff_tree_line.rb +32 -0
- data/lib/eac_git/local/dirty_files.rb +2 -3
- data/lib/eac_git/rspec.rb +6 -1
- data/lib/eac_git/rspec/stubbed_git_local_repo.rb +60 -0
- data/lib/eac_git/version.rb +1 -1
- metadata +24 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e93bc1263137fa2c49da54b4d9e126e66d18a366f3905600123aa29a7d1433b
|
4
|
+
data.tar.gz: e3b1255fcb3afbb74564e8b5e6518066d45c5c4f95a980a302fae55db5e07e4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0093f9f61cca73f4335c53c0e1c454ecb13e35a133d20f575de5c671da4687cd7d0722cfac8d6a5f8507da6dec1a5dd83063fcbd0d18b94bb27044d5cfa9d06
|
7
|
+
data.tar.gz: b7dad37d8394f54b5077fa34933a54a6319275f81544b9c097272a8758261d147a42e04812861f6cfdddebc6778b50a3d04d6e6de996be48234e0bbeb553934b
|
data/lib/eac_git/executables.rb
CHANGED
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?
|
@@ -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
|
@@ -20,9 +20,8 @@ module EacGit
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def dirty_files
|
23
|
-
command('status', '--porcelain', '--untracked-files')
|
24
|
-
parse_status_line(line.gsub(/\n\z/, ''))
|
25
|
-
end
|
23
|
+
command('status', '--porcelain=v1', '--untracked-files', '--no-renames')
|
24
|
+
.execute!.each_line.map { |line| parse_status_line(line.gsub(/\n\z/, '')) }
|
26
25
|
end
|
27
26
|
|
28
27
|
private
|
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
|
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
|
data/lib/eac_git/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2021-06-02 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:
|
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.
|
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.
|
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.
|
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.
|
299
|
+
rubygems_version: 3.0.9
|
287
300
|
signing_key:
|
288
301
|
specification_version: 4
|
289
302
|
summary: Put here de description.
|