eac_git 0.14.1 → 0.16.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: 8c1d971be74edc9e4e7f2a81f58902eaa1ba1088a05bdfac7d93cef450ac8072
4
- data.tar.gz: 8c939b1af9cf4c02b06a0a7d052f6cb135f44ac52cdcbdea47b033c977b14ed2
3
+ metadata.gz: 5801ee9f2b28bd73bd27e83254c1eaff5a473492c3f89dfe05b833f210fa42c3
4
+ data.tar.gz: '0233988a062e873923b7f7d37a4a866f316d30f7589275a22afdf68c3047b0b7'
5
5
  SHA512:
6
- metadata.gz: 68cdc9332985c4f6cfe8476a2d9022d148ea0e247199e29e3efd248060fda1b97d24232f3643dae4db53895a6703921ca7519fe4541d826209b9d1dfec364371
7
- data.tar.gz: c422235a740b26c1715b11d4de6fc2ec5a79e7c4f218f7b76d2f965cb5b311301d48f8b43a2e2a963dd5e78b7afe0e26ef6465cbe95b8a987b145bcf1f889705
6
+ metadata.gz: cb54953f41934dca5f5bc3dfc119cf8197bfa04947376ba96cd06a8945fe9f43bf4eeba748dcd01a13c2dc98ccee6952a40e8e49cc688704468498dd93097b12
7
+ data.tar.gz: 4d6663b3671b046883363d8a1712fc8029636a9a4cbfdbadc9f1de3367125c8949126aea6dab622ab87600f62a58fc7f6ae5aadf91754a90634cfe2f67d5db6c
@@ -10,8 +10,9 @@ module EacGit
10
10
  common_constructor :local, :name
11
11
 
12
12
  # @return [String]
13
+ # @deprecated Use {#head_commit_id} instead.
13
14
  def current_commit_id
14
- local.rev_parse(full_ref_name, true)
15
+ head_commit_id
15
16
  end
16
17
 
17
18
  # @return [Boolean]
@@ -22,6 +23,25 @@ module EacGit
22
23
  def full_ref_name
23
24
  "#{REFS_PREFIX}#{name}"
24
25
  end
26
+
27
+ # @return [EacGit::Local::Commit]
28
+ def head_commit
29
+ local.commit(head_commit_id, true)
30
+ end
31
+
32
+ # @return [String]
33
+ def head_commit_id
34
+ local.rev_parse(full_ref_name, true)
35
+ end
36
+
37
+ # @param remote [EacGit::Local::Remote]
38
+ # @return [void]
39
+ def push(remote, options = {})
40
+ options[:refspec] = name
41
+ options.inject(remote.push) do |a, e|
42
+ a.send(*e)
43
+ end.perform
44
+ end
25
45
  end
26
46
  end
27
47
  end
@@ -20,7 +20,7 @@ module EacGit
20
20
  end
21
21
 
22
22
  def fields
23
- FIELDS.map { |field| [field, send(field)] }.to_h
23
+ FIELDS.index_with { |field| send(field) }
24
24
  end
25
25
 
26
26
  private
@@ -6,6 +6,7 @@ require 'ostruct'
6
6
  module EacGit
7
7
  class Local
8
8
  module DirtyFiles
9
+ QUOTED_PATH_PATTERN = /\A"(.+)"\z/.freeze
9
10
  STATUS_LINE_PATTERN = /\A(.)(.)\s(.+)\z/.freeze
10
11
 
11
12
  def dirty?
@@ -26,12 +27,22 @@ module EacGit
26
27
 
27
28
  private
28
29
 
30
+ # @param line [String]
31
+ # @return [Struct]
29
32
  def parse_status_line(line)
30
33
  STATUS_LINE_PATTERN.if_match(line) do |m|
31
- ::OpenStruct.new(index: m[1], worktree: m[2], path: m[3].to_pathname,
32
- absolute_path: m[3].to_pathname.expand_path(root_path))
34
+ path = parse_status_line_path(m[3]).to_pathname
35
+ { index: m[1], worktree: m[2], path: path, absolute_path: path.expand_path(root_path) }
36
+ .to_struct
33
37
  end
34
38
  end
39
+
40
+ # @param path [String]
41
+ # @return [String]
42
+ def parse_status_line_path(path)
43
+ m = QUOTED_PATH_PATTERN.match(path)
44
+ m ? m[1] : path
45
+ end
35
46
  end
36
47
  end
37
48
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacGit
6
+ class Local
7
+ class Remote
8
+ class Push
9
+ acts_as_immutable
10
+ immutable_accessor :force, type: :boolean
11
+ immutable_accessor :refspec, type: :array
12
+
13
+ common_constructor :remote
14
+ delegate :local, to: :remote
15
+
16
+ # @return [Array<Object>]
17
+ def immutable_constructor_args
18
+ [remote]
19
+ end
20
+
21
+ # @return [void]
22
+ def perform
23
+ local.command(*git_command_args).system!
24
+ end
25
+
26
+ # @return [Enumerable<String>]
27
+ def git_command_args
28
+ r = ['push', remote.name]
29
+ r << '--force' if force?
30
+ r + refspecs
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -22,6 +22,11 @@ module EacGit
22
22
  local.command(*args)
23
23
  end
24
24
 
25
+ # @return [EacGit::Local::Remote::Push]
26
+ def push
27
+ ::EacGit::Local::Remote::Push.new(self)
28
+ end
29
+
25
30
  # @return [String]
26
31
  def remote_reference
27
32
  name
@@ -38,6 +43,8 @@ module EacGit
38
43
  def url=(new_url)
39
44
  local.command('remote', 'set-url', name, new_url).execute!
40
45
  end
46
+
47
+ require_sub __FILE__
41
48
  end
42
49
  end
43
50
  end
@@ -11,7 +11,7 @@ module EacGit
11
11
  end
12
12
 
13
13
  def remotes
14
- command('remote').execute!.each_line.map(&:strip).reject(&:blank?).map do |name|
14
+ command('remote').execute!.each_line.map(&:strip).compact_blank.map do |name|
15
15
  remote(name)
16
16
  end
17
17
  end
@@ -24,7 +24,7 @@ module EacGit
24
24
  self.values = values.with_indifferent_access
25
25
  end
26
26
 
27
- MAPPING.each do |method_name, _config_key|
27
+ MAPPING.each_key do |method_name|
28
28
  define_method(method_name) do
29
29
  values[MAPPING.fetch(method_name)]
30
30
  end
@@ -35,7 +35,7 @@ module EacGit
35
35
  end
36
36
 
37
37
  def to_content
38
- "[subrepo]\n" + MAPPING.map { |k, v| " #{v} = #{send(k)}\n" }.join
38
+ "[subrepo]\n" + MAPPING.map { |k, v| " #{v} = #{send(k)}\n" }.join # rubocop:disable Style/StringConcatenation
39
39
  end
40
40
  end
41
41
  end
data/lib/eac_git/local.rb CHANGED
@@ -38,7 +38,7 @@ module EacGit
38
38
  ::EacGit::Local::Branch.new(self, name)
39
39
  end
40
40
 
41
- def commit(ref, required = false)
41
+ def commit(ref, required = false) # rubocop:disable Style/OptionalBooleanParameter
42
42
  rev_parse(ref, required).if_present { |v| ::EacGit::Local::Commit.new(self, v) }
43
43
  end
44
44
 
@@ -71,7 +71,7 @@ module EacGit
71
71
  end
72
72
 
73
73
  # @return [EacGit::Local::Commit
74
- def head(required = true)
74
+ def head(required = true) # rubocop:disable Style/OptionalBooleanParameter
75
75
  commit(HEAD_REFERENCE, required)
76
76
  end
77
77
 
@@ -94,7 +94,7 @@ module EacGit
94
94
  raise "#{root_path}: #{message}"
95
95
  end
96
96
 
97
- def rev_parse(ref, required = false)
97
+ def rev_parse(ref, required = false) # rubocop:disable Style/OptionalBooleanParameter
98
98
  r = command('rev-parse', ref).execute!(exit_outputs: { 128 => nil, 32_768 => nil })
99
99
  r.strip! if r.is_a?(String)
100
100
  return r if r.present?
@@ -12,8 +12,8 @@ module EacGit
12
12
  common_constructor :uri
13
13
 
14
14
  # @return [EacRubyUtils::Envs::Command
15
- def git_command(*args, &block)
16
- ::EacGit::Executables.git.command(*args, &block)
15
+ def git_command(...)
16
+ ::EacGit::Executables.git.command(...)
17
17
  end
18
18
 
19
19
  # @return [String]
@@ -8,13 +8,13 @@ module EacGit
8
8
  class << self
9
9
  def by_ls_remote_command_output(output)
10
10
  new(
11
- output.each_line.map { |line| line.strip.split(/\s+/) }.map { |x| [x[1], x[0]] }.to_h
11
+ output.each_line.map { |line| line.strip.split(/\s+/) }.to_h { |x| [x[1], x[0]] } # rubocop:disable Style/MapToHash
12
12
  )
13
13
  end
14
14
  end
15
15
 
16
16
  common_constructor :hashes
17
- delegate :fetch, :'[]', :count, :any?, :empty?, to: :hashes
17
+ delegate :fetch, :[], :count, :any?, :empty?, to: :hashes
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/rspec/stubbed_git_local_repo/fs_object'
4
+ require 'fileutils'
5
+
6
+ module EacGit
7
+ module Rspec
8
+ module StubbedGitLocalRepo
9
+ class Directory < ::EacGit::Rspec::StubbedGitLocalRepo::FsObject
10
+ # @return [self]
11
+ def create
12
+ ::FileUtils.mkdir_p(path)
13
+ self
14
+ end
15
+
16
+ # @return [self]
17
+ def delete
18
+ ::FileUtils.rm_rf(path)
19
+ self
20
+ end
21
+
22
+ # @param subpath [Array<String>]
23
+ # @return [EacGit::Rspec::StubbedGitLocalRepo::Directory]
24
+ def directory(*subpath)
25
+ git.directory(*self.subpath, *subpath)
26
+ end
27
+
28
+ # @param subpath [Array<String>]
29
+ # @return [EacGit::Rspec::StubbedGitLocalRepo::File]
30
+ def file(*subpath)
31
+ git.file(*self.subpath, *subpath)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/rspec/stubbed_git_local_repo/fs_object'
4
+ require 'fileutils'
5
+
6
+ module EacGit
7
+ module Rspec
8
+ module StubbedGitLocalRepo
9
+ class File < ::EacGit::Rspec::StubbedGitLocalRepo::FsObject
10
+ def touch
11
+ ::FileUtils.touch(path.to_path)
12
+ end
13
+
14
+ def delete
15
+ path.unlink
16
+ end
17
+
18
+ delegate :write, to: :path
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacGit
6
+ module Rspec
7
+ module StubbedGitLocalRepo
8
+ class FsObject
9
+ # @!attribute [r] git
10
+ # @param git [EacGit::Rspec::StubbedGitLocalRepo::Repository]
11
+
12
+ # @!attribute [r] subpath
13
+ # @param git [Array<String>]
14
+
15
+ # @!method initialize(git, subpath)
16
+ # @param git [EacGit::Rspec::StubbedGitLocalRepo::Repository]
17
+ # @param subpath [Array<String>
18
+ common_constructor :git, :subpath
19
+
20
+ # @return [Pathname]
21
+ def path
22
+ git.root_path.join(*subpath)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_git/local'
4
+ require 'eac_git/rspec/stubbed_git_local_repo/directory'
5
+ require 'eac_git/rspec/stubbed_git_local_repo/file'
6
+ require 'eac_ruby_utils/core_ext'
7
+ require 'securerandom'
8
+
9
+ module EacGit
10
+ module Rspec
11
+ module StubbedGitLocalRepo
12
+ class Repository < ::EacGit::Local
13
+ # @return [EacGit::Rspec::StubbedGitLocalRepo::Directory]
14
+ def directory(*subpath)
15
+ ::EacGit::Rspec::StubbedGitLocalRepo::Directory.new(self, subpath)
16
+ end
17
+
18
+ def file(*subpath)
19
+ ::EacGit::Rspec::StubbedGitLocalRepo::File.new(self, subpath)
20
+ end
21
+
22
+ # @return [EacGit::Local::Commit
23
+ def random_commit
24
+ content = ::SecureRandom.hex
25
+ file = "#{content}.txt"
26
+ file(file).write(content)
27
+ command('add', file).execute!
28
+ command('commit', '-m', "Random commit: #{file}.").execute!
29
+ head
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,18 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_git/local'
4
3
  require 'eac_ruby_utils/envs'
5
- require 'fileutils'
6
- require 'securerandom'
7
4
  require 'tmpdir'
8
5
 
9
6
  module EacGit
10
7
  module Rspec
11
8
  module StubbedGitLocalRepo
12
- def stubbed_git_local_repo(bare = false)
9
+ def stubbed_git_local_repo(bare = false) # rubocop:disable Style/OptionalBooleanParameter
13
10
  path = ::Dir.mktmpdir
14
11
  ::EacRubyUtils::Envs.local.command(stubbed_git_local_repo_args(path, bare)).execute!
15
- repo = StubbedGitRepository.new(path)
12
+ repo = ::EacGit::Rspec::StubbedGitLocalRepo::Repository.new(path)
16
13
  repo.command('config', 'user.email', 'theuser@example.net').execute!
17
14
  repo.command('config', 'user.name', 'The User').execute!
18
15
  repo
@@ -26,46 +23,7 @@ module EacGit
26
23
  r + [path]
27
24
  end
28
25
 
29
- class StubbedGitRepository < ::EacGit::Local
30
- def file(*subpath)
31
- StubbedGitRepositoryFile.new(self, subpath)
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
43
- end
44
-
45
- class StubbedGitRepositoryFile
46
- attr_reader :git, :subpath
47
-
48
- def initialize(git, subpath)
49
- @git = git
50
- @subpath = subpath
51
- end
52
-
53
- def path
54
- git.root_path.join(*subpath)
55
- end
56
-
57
- def touch
58
- ::FileUtils.touch(path.to_path)
59
- end
60
-
61
- def delete
62
- path.unlink
63
- end
64
-
65
- def write(content)
66
- path.write(content)
67
- end
68
- end
26
+ require_sub __FILE__
69
27
  end
70
28
  end
71
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacGit
4
- VERSION = '0.14.1'
4
+ VERSION = '0.16.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.14.1
4
+ version: 0.16.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: 2023-03-21 00:00:00.000000000 Z
11
+ date: 2024-02-18 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.112'
19
+ version: '0.121'
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.112'
26
+ version: '0.121'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: parseconfig
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,40 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.1.2
47
- - !ruby/object:Gem::Dependency
48
- name: aranha-parsers
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '0.8'
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.8.2
57
- type: :development
58
- prerelease: false
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '0.8'
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 0.8.2
67
47
  - !ruby/object:Gem::Dependency
68
48
  name: eac_ruby_gem_support
69
49
  requirement: !ruby/object:Gem::Requirement
70
50
  requirements:
71
51
  - - "~>"
72
52
  - !ruby/object:Gem::Version
73
- version: 0.5.1
53
+ version: '0.10'
74
54
  type: :development
75
55
  prerelease: false
76
56
  version_requirements: !ruby/object:Gem::Requirement
77
57
  requirements:
78
58
  - - "~>"
79
59
  - !ruby/object:Gem::Version
80
- version: 0.5.1
60
+ version: '0.10'
81
61
  description:
82
62
  email:
83
63
  executables: []
@@ -95,6 +75,7 @@ files:
95
75
  - lib/eac_git/local/dirty_files.rb
96
76
  - lib/eac_git/local/log.rb
97
77
  - lib/eac_git/local/remote.rb
78
+ - lib/eac_git/local/remote/push.rb
98
79
  - lib/eac_git/local/remotes.rb
99
80
  - lib/eac_git/local/subrepo.rb
100
81
  - lib/eac_git/local/subrepo/config.rb
@@ -104,6 +85,10 @@ files:
104
85
  - lib/eac_git/rspec.rb
105
86
  - lib/eac_git/rspec/setup.rb
106
87
  - lib/eac_git/rspec/stubbed_git_local_repo.rb
88
+ - lib/eac_git/rspec/stubbed_git_local_repo/directory.rb
89
+ - lib/eac_git/rspec/stubbed_git_local_repo/file.rb
90
+ - lib/eac_git/rspec/stubbed_git_local_repo/fs_object.rb
91
+ - lib/eac_git/rspec/stubbed_git_local_repo/repository.rb
107
92
  - lib/eac_git/version.rb
108
93
  - vendor/git-subrepo/Changes
109
94
  - vendor/git-subrepo/Intro.pod
@@ -301,7 +286,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
301
286
  requirements:
302
287
  - - ">="
303
288
  - !ruby/object:Gem::Version
304
- version: '0'
289
+ version: '2.7'
305
290
  required_rubygems_version: !ruby/object:Gem::Requirement
306
291
  requirements:
307
292
  - - ">="