eac_git 0.7.2 → 0.10.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: c1a21c475a5923f4e0a8858b1588cd4147580f9393a21b962f54d8a8a6f475d6
4
- data.tar.gz: 9683a9e6ced4b4957df0a9f3176bbc96e2635a72ffa9492dd87867fc05d56e69
3
+ metadata.gz: 2ec311c88709310162dce2346aaeab5d0f806c34328f59acc2ea441078e67c31
4
+ data.tar.gz: 32a078b92200395e6dd323b67b90d9d25819bc3eacb5da1da79121e14f69d415
5
5
  SHA512:
6
- metadata.gz: d77370cfc40835af8ddd18af0aa2946edd9bf6d91abab76304b5f54271ff66501f4d5ac06c92a99fd556a9e041684615d5e1f300355528be967eb8b38011a8ed
7
- data.tar.gz: 81126f091f53c937f8b9125bb291376ff532092e28c54f3aa9260b52cc6c157a28699babc4b489c13f4ded4b87a0ad12973c47efb85224bcfed1bd20fa764f76
6
+ metadata.gz: 4de5084aa3ec1a3c1ab79565d648fd69561a709fd7ab1be956d6850253275368d6a154b87ebbb3d8d888d1d91400a399f8fd9505aa107c2d3c22adad871154f7
7
+ data.tar.gz: 94bff2c958c603be3c8a9f03fff9961e5065bd6d8ddc61921f2961aa35a45a2b09b0959ababbdd4ccc21bc442a471535948ca4503b258dcdfb808dd363574a67
@@ -9,7 +9,7 @@ module EacGit
9
9
  # @return [EacRubyUtils::Envs::Command]
10
10
  def archive_to_dir(path)
11
11
  path = path.to_pathname
12
- repo.command('archive', '--format=tar', hash).pipe(
12
+ repo.command('archive', '--format=tar', id).pipe(
13
13
  ::EacGit::Executables.tar.command('-xC', path)
14
14
  )
15
15
  end
@@ -7,19 +7,25 @@ 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
- common_constructor :repo, :hash
21
+ common_constructor :repo, :id
22
+
23
+ def <=>(other)
24
+ [repo, id] <=> [other.repo, other.id]
25
+ end
20
26
 
21
27
  def format(format)
22
- repo.command('--no-pager', 'log', '-1', "--pretty=format:#{format}", hash).execute!.strip
28
+ repo.command('--no-pager', 'log', '-1', "--pretty=format:#{format}", id).execute!.strip
23
29
  end
24
30
 
25
31
  FIELDS.each do |field, format|
@@ -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
- format('%P').blank?
59
+ parents.empty?
41
60
  end
42
61
 
43
62
  private
@@ -45,7 +64,7 @@ module EacGit
45
64
  def diff_tree_execute
46
65
  args = []
47
66
  args << '--root' if root_child?
48
- args << hash
67
+ args << id
49
68
  repo.command(*::EacGit::Local::Commit::DiffTreeLine::GIT_COMMAND_ARGS, *args).execute!
50
69
  end
51
70
  end
@@ -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
@@ -0,0 +1,27 @@
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
+ class Remote
9
+ NO_SUCH_REMOTE_CODE = 128
10
+
11
+ enable_simple_cache
12
+
13
+ common_constructor :local, :name
14
+
15
+ def exist?
16
+ url
17
+ end
18
+
19
+ # @return [String, nil]
20
+ def url
21
+ local.command('remote', 'get-url', name)
22
+ .execute!(exit_outputs: { NO_SUCH_REMOTE_CODE => nil })
23
+ .if_present(nil, &:strip)
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/eac_git/local.rb CHANGED
@@ -7,15 +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
11
+
12
+ HEAD_REFERENCE = 'HEAD'
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
10
24
 
11
25
  common_constructor :root_path do
12
26
  self.root_path = root_path.to_pathname
13
27
  end
14
28
 
29
+ def <=>(other)
30
+ root_path <=> other.root_path
31
+ end
32
+
15
33
  def commit(ref, required = false)
16
34
  rev_parse(ref, required).if_present { |v| ::EacGit::Local::Commit.new(self, v) }
17
35
  end
18
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
+
19
47
  def descendant?(descendant, ancestor)
20
48
  base = merge_base(descendant, ancestor)
21
49
  return false if base.blank?
@@ -24,6 +52,11 @@ module EacGit
24
52
  base == revparse
25
53
  end
26
54
 
55
+ # @return [EacGit::Local::Commit
56
+ def head(required = true)
57
+ commit(HEAD_REFERENCE, required)
58
+ end
59
+
27
60
  def merge_base(*commits)
28
61
  refs = commits.dup
29
62
  while refs.count > 1
@@ -56,6 +89,12 @@ module EacGit
56
89
  ::EacGit::Local::Subrepo.new(self, subpath)
57
90
  end
58
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
+
59
98
  def to_s
60
99
  "#{self.class}[#{root_path}]"
61
100
  end
@@ -6,7 +6,7 @@ require 'eac_git/rspec/stubbed_git_local_repo'
6
6
  module EacGit
7
7
  module Rspec
8
8
  module Setup
9
- def self.perform(setup_obj)
9
+ def self.extended(setup_obj)
10
10
  setup_obj.setup_conditional_git
11
11
  setup_obj.setup_stubbed_git_local_repo
12
12
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacGit
4
- VERSION = '0.7.2'
4
+ VERSION = '0.10.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.7.2
4
+ version: 0.10.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-08-14 00:00:00.000000000 Z
11
+ date: 2021-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.73'
19
+ version: '0.74'
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.73'
26
+ version: '0.74'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: parseconfig
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +98,8 @@ 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
102
+ - lib/eac_git/local/remote.rb
101
103
  - lib/eac_git/local/subrepo.rb
102
104
  - lib/eac_git/local/subrepo/config.rb
103
105
  - lib/eac_git/remote.rb