eac_git 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/eac_git/local/commit.rb +21 -2
- data/lib/eac_git/local/log.rb +17 -0
- data/lib/eac_git/local.rb +32 -0
- data/lib/eac_git/rspec/stubbed_git_local_repo.rb +11 -0
- data/lib/eac_git/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3e59f62094b03ab4c24d4ee36a542cef813a308c797a8835482ae52174d50ea
|
4
|
+
data.tar.gz: 9c1dcb9b11dbd6cd4292f198a77efb089dae5ecc06ff077f89f94a9d6423ad9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbd211017dbe7125bfdff651ca0336573a09cd37ad160ab627a61f0d5bd21a9aa73896a074af517623ea8854d525cee93651f9b23d64b799192aea2ce40a0cff
|
7
|
+
data.tar.gz: ecf155ca625baca1be22721e7dbf29807c49a3d5d3e8d4eaf26c36466f99bea708fc55ddf17d9e0c26dbb3c4c533f6d18917aab860693f14205f36055344f132
|
data/lib/eac_git/local/commit.rb
CHANGED
@@ -7,17 +7,23 @@ module EacGit
|
|
7
7
|
class Commit
|
8
8
|
require_sub __FILE__, include_modules: true
|
9
9
|
enable_simple_cache
|
10
|
+
include ::Comparable
|
10
11
|
|
11
12
|
FIELDS = {
|
12
13
|
author_name: '%an', author_email: '%ae', author_date: '%ai',
|
13
14
|
subject: '%s',
|
14
15
|
author_all: '%an <%ae>, %ai',
|
15
16
|
commiter_name: '%cn', commiter_email: '%ce', commiter_date: '%ci',
|
16
|
-
commiter_all: '%cn <%ce>, %ci'
|
17
|
+
commiter_all: '%cn <%ce>, %ci',
|
18
|
+
raw_body: '%B'
|
17
19
|
}.freeze
|
18
20
|
|
19
21
|
common_constructor :repo, :id
|
20
22
|
|
23
|
+
def <=>(other)
|
24
|
+
[repo, id] <=> [other.repo, other.id]
|
25
|
+
end
|
26
|
+
|
21
27
|
def format(format)
|
22
28
|
repo.command('--no-pager', 'log', '-1', "--pretty=format:#{format}", id).execute!.strip
|
23
29
|
end
|
@@ -36,8 +42,21 @@ module EacGit
|
|
36
42
|
changed_files.inject(0) { |a, e| a + e.dst_size }
|
37
43
|
end
|
38
44
|
|
45
|
+
# @return [EacGit::Local::Commit, nil]
|
46
|
+
def parent
|
47
|
+
ps = parents
|
48
|
+
raise "#{self} has more than one parent" if ps.count > 2
|
49
|
+
|
50
|
+
ps.empty? ? nil : ps.first
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [Array<EacGit::Local::Commit>]
|
54
|
+
def parents
|
55
|
+
format('%P').each_line.map { |line| repo.commitize(line) }
|
56
|
+
end
|
57
|
+
|
39
58
|
def root_child?
|
40
|
-
|
59
|
+
parents.empty?
|
41
60
|
end
|
42
61
|
|
43
62
|
private
|
@@ -0,0 +1,17 @@
|
|
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
|
+
module Log
|
9
|
+
def log(until_commit = nil, from_commit = nil)
|
10
|
+
until_commit, from_commit = [until_commit, from_commit].map { |c| commitize(c) }
|
11
|
+
from_commit ||= head
|
12
|
+
command('log', '--format=%H', "#{until_commit.id}..#{from_commit.id}")
|
13
|
+
.execute!.each_line.map { |line| commitize(line.strip) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/eac_git/local.rb
CHANGED
@@ -7,17 +7,43 @@ module EacGit
|
|
7
7
|
# A Git repository in local filesystem.
|
8
8
|
class Local
|
9
9
|
require_sub __FILE__, include_modules: true
|
10
|
+
include ::Comparable
|
10
11
|
|
11
12
|
HEAD_REFERENCE = 'HEAD'
|
12
13
|
|
14
|
+
class << self
|
15
|
+
def find(path)
|
16
|
+
path = path.to_pathname.expand_path
|
17
|
+
if path.join('.git').exist?
|
18
|
+
new(path)
|
19
|
+
elsif path.to_path != '/'
|
20
|
+
find(path.parent)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
common_constructor :root_path do
|
14
26
|
self.root_path = root_path.to_pathname
|
15
27
|
end
|
16
28
|
|
29
|
+
def <=>(other)
|
30
|
+
root_path <=> other.root_path
|
31
|
+
end
|
32
|
+
|
17
33
|
def commit(ref, required = false)
|
18
34
|
rev_parse(ref, required).if_present { |v| ::EacGit::Local::Commit.new(self, v) }
|
19
35
|
end
|
20
36
|
|
37
|
+
def commitize(source)
|
38
|
+
if source.is_a?(::EacGit::Local::Commit)
|
39
|
+
return source if source.repo == self
|
40
|
+
|
41
|
+
source = source.id
|
42
|
+
end
|
43
|
+
|
44
|
+
source.to_s.strip.if_present(nil) { |v| ::EacGit::Local::Commit.new(self, v) }
|
45
|
+
end
|
46
|
+
|
21
47
|
def descendant?(descendant, ancestor)
|
22
48
|
base = merge_base(descendant, ancestor)
|
23
49
|
return false if base.blank?
|
@@ -63,6 +89,12 @@ module EacGit
|
|
63
89
|
::EacGit::Local::Subrepo.new(self, subpath)
|
64
90
|
end
|
65
91
|
|
92
|
+
# @return [Array<EacGit::Local::Subrepo>]
|
93
|
+
def subrepos
|
94
|
+
command('subrepo', '-q', 'status').execute!.split("\n").map(&:strip).select(&:present?)
|
95
|
+
.map { |subpath| subrepo(subpath) }
|
96
|
+
end
|
97
|
+
|
66
98
|
def to_s
|
67
99
|
"#{self.class}[#{root_path}]"
|
68
100
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'eac_git/local'
|
4
4
|
require 'eac_ruby_utils/envs'
|
5
5
|
require 'fileutils'
|
6
|
+
require 'securerandom'
|
6
7
|
require 'tmpdir'
|
7
8
|
|
8
9
|
module EacGit
|
@@ -29,6 +30,16 @@ module EacGit
|
|
29
30
|
def file(*subpath)
|
30
31
|
StubbedGitRepositoryFile.new(self, subpath)
|
31
32
|
end
|
33
|
+
|
34
|
+
# @return [EacGit::Local::Commit
|
35
|
+
def random_commit
|
36
|
+
content = ::SecureRandom.hex
|
37
|
+
file = "#{content}.txt"
|
38
|
+
file(file).write(content)
|
39
|
+
command('add', file).execute!
|
40
|
+
command('commit', '-m', "Random commit: #{file}.").execute!
|
41
|
+
head
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
45
|
class StubbedGitRepositoryFile
|
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.9.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-
|
11
|
+
date: 2021-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_ruby_utils
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/eac_git/local/commit/changed_file.rb
|
99
99
|
- lib/eac_git/local/commit/diff_tree_line.rb
|
100
100
|
- lib/eac_git/local/dirty_files.rb
|
101
|
+
- lib/eac_git/local/log.rb
|
101
102
|
- lib/eac_git/local/subrepo.rb
|
102
103
|
- lib/eac_git/local/subrepo/config.rb
|
103
104
|
- lib/eac_git/remote.rb
|