eac_git 0.8.0 → 0.12.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: 666b1ea54c39fca3540650e25d754d02b665e9f66668f190b1f7bf187098edb6
4
- data.tar.gz: 606c1187283de19695be48cf13aadb345b60ac4f0625d3477e97532e763ced4a
3
+ metadata.gz: 0ae089affcb0d05e18f41ec4714b46f5ddc9df84d86cc51fffbae59fdec37bfc
4
+ data.tar.gz: 84ca61a9dcd87fe0a99e7e277706c0b0b45aa63355f7c6367334423adc8c150e
5
5
  SHA512:
6
- metadata.gz: 477b98b77bdefc6d1622603263eea2b60fde7736b2e44f36d201da1f6d0d37113d10c53a609876dad2338cdf48c18303105dfd3106952acb7154bff8491ca00d
7
- data.tar.gz: d2cbcd3b0f43cd10bbfc1c17bb7fad3704927aa7585ab061aa04a396002d53cbb94dc07faef5369738c09e2c260a83183cd27f7ae23ba43a0e9acbdb7b46224c
6
+ metadata.gz: 4660dc27975d833e3b57097f99e15253970c4b33bc5e3877034cd95d61c6f9e1d539562e144799b5f8b8b4355c555a3102c8f3d6cf4bf0a86cfd4a17ebc4fa39
7
+ data.tar.gz: 1d78cd7ed4d5cbeadecfef5b99783d02f1495b380834f17bd45eaa63f2cb85c69017da70bfb30e5d3a4f3de3fde156738ebbde52b5d9a7df6429d25fa0fe5438
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacGit
6
+ class Local
7
+ class Branch
8
+ REFS_PREFIX = 'refs/heads/'
9
+
10
+ common_constructor :local, :name
11
+
12
+ # @return [String]
13
+ def current_commit_id
14
+ local.rev_parse(full_ref_name, true)
15
+ end
16
+
17
+ # @return [Boolean]
18
+ def exist?
19
+ local.command('show-ref', '--quiet', full_ref_name).execute.fetch(:exit_code).zero?
20
+ end
21
+
22
+ def full_ref_name
23
+ "#{REFS_PREFIX}#{name}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -7,17 +7,24 @@ 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',
16
+ commit_hash: '%H', abbreviated_commit_hash: '%h',
15
17
  commiter_name: '%cn', commiter_email: '%ce', commiter_date: '%ci',
16
- commiter_all: '%cn <%ce>, %ci'
18
+ commiter_all: '%cn <%ce>, %ci',
19
+ raw_body: '%B'
17
20
  }.freeze
18
21
 
19
22
  common_constructor :repo, :id
20
23
 
24
+ def <=>(other)
25
+ [repo, id] <=> [other.repo, other.id]
26
+ end
27
+
21
28
  def format(format)
22
29
  repo.command('--no-pager', 'log', '-1', "--pretty=format:#{format}", id).execute!.strip
23
30
  end
@@ -36,8 +43,21 @@ module EacGit
36
43
  changed_files.inject(0) { |a, e| a + e.dst_size }
37
44
  end
38
45
 
46
+ # @return [EacGit::Local::Commit, nil]
47
+ def parent
48
+ ps = parents
49
+ raise "#{self} has more than one parent" if ps.count > 2
50
+
51
+ ps.empty? ? nil : ps.first
52
+ end
53
+
54
+ # @return [Array<EacGit::Local::Commit>]
55
+ def parents
56
+ format('%P').each_line.map { |line| repo.commitize(line) }
57
+ end
58
+
39
59
  def root_child?
40
- format('%P').blank?
60
+ parents.empty?
41
61
  end
42
62
 
43
63
  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
@@ -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
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_git/local/remote'
5
+
6
+ module EacGit
7
+ class Local
8
+ module Remotes
9
+ def remote(name)
10
+ ::EacGit::Local::Remote.new(self, name)
11
+ end
12
+
13
+ def remotes
14
+ command('remote').execute!.each_line.map(&:strip).reject(&:blank?).map do |name|
15
+ remote(name)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
data/lib/eac_git/local.rb CHANGED
@@ -7,17 +7,61 @@ 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
+
33
+ # Retrieves a local branch.
34
+ #
35
+ # @param name [String] Ex.: for "refs/heads/master", name should be "master".
36
+ # @return [EacGit::Local::Branch]
37
+ def branch(name)
38
+ ::EacGit::Local::Branch.new(self, name)
39
+ end
40
+
17
41
  def commit(ref, required = false)
18
42
  rev_parse(ref, required).if_present { |v| ::EacGit::Local::Commit.new(self, v) }
19
43
  end
20
44
 
45
+ def commitize(source)
46
+ if source.is_a?(::EacGit::Local::Commit)
47
+ return source if source.repo == self
48
+
49
+ source = source.id
50
+ end
51
+
52
+ source.to_s.strip.if_present(nil) { |v| ::EacGit::Local::Commit.new(self, v) }
53
+ end
54
+
55
+ # Retrieves the current local branch.
56
+ #
57
+ # @return [EacGit::Local::Branch, nil]
58
+ def current_branch
59
+ command('symbolic-ref', '--quiet', HEAD_REFERENCE)
60
+ .execute!(exit_outputs: { 256 => '' })
61
+ .gsub(%r{\Arefs/heads/}, '').strip
62
+ .if_present { |v| branch(v) }
63
+ end
64
+
21
65
  def descendant?(descendant, ancestor)
22
66
  base = merge_base(descendant, ancestor)
23
67
  return false if base.blank?
@@ -63,6 +107,12 @@ module EacGit
63
107
  ::EacGit::Local::Subrepo.new(self, subpath)
64
108
  end
65
109
 
110
+ # @return [Array<EacGit::Local::Subrepo>]
111
+ def subrepos
112
+ command('subrepo', '-q', 'status').execute!.split("\n").map(&:strip).select(&:present?)
113
+ .map { |subpath| subrepo(subpath) }
114
+ end
115
+
66
116
  def to_s
67
117
  "#{self.class}[#{root_path}]"
68
118
  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.8.0'
4
+ VERSION = '0.12.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.8.0
4
+ version: 0.12.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-09-24 00:00:00.000000000 Z
11
+ date: 2022-01-24 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.74'
19
+ version: '0.83'
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.74'
26
+ version: '0.83'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: parseconfig
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -93,11 +93,15 @@ files:
93
93
  - lib/eac_git.rb
94
94
  - lib/eac_git/executables.rb
95
95
  - lib/eac_git/local.rb
96
+ - lib/eac_git/local/branch.rb
96
97
  - lib/eac_git/local/commit.rb
97
98
  - lib/eac_git/local/commit/archive.rb
98
99
  - lib/eac_git/local/commit/changed_file.rb
99
100
  - lib/eac_git/local/commit/diff_tree_line.rb
100
101
  - lib/eac_git/local/dirty_files.rb
102
+ - lib/eac_git/local/log.rb
103
+ - lib/eac_git/local/remote.rb
104
+ - lib/eac_git/local/remotes.rb
101
105
  - lib/eac_git/local/subrepo.rb
102
106
  - lib/eac_git/local/subrepo/config.rb
103
107
  - lib/eac_git/remote.rb