git 2.0.1 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c7aebf8b61eb75a0d3e587fae03711b1d9cec89c7fb69462bda24c069daeaa4
4
- data.tar.gz: f73bd8a6e030209305ffbcc1bae372cd6820745569142ddd7239b366ef78d322
3
+ metadata.gz: cf601afe6ddef5cc504f0a350bd9595feb76cc95822bd65716d6b5cecf2d324d
4
+ data.tar.gz: 5f334a391220774ab0fea9c789a87fe3a45d9de55e0745d87f59c0bc9a52e5a9
5
5
  SHA512:
6
- metadata.gz: 32c0e605d3ee280c19cf863f5b9a5fc9437171b9facbbee074b2ddca096c4cae3f08ddf42cb6cad7a91512824f40cd51940e1846c1f1a3e5bb7f4e7ee52e154b
7
- data.tar.gz: 528bf8926dbf6b76681b8333ca3d797b1e28854921f6abcd5b2fd9a13c6861c25e6ad75462efb818c1c74de0980c96974a423ad2a19aaf87d5b27e3e2ffca8cf
6
+ metadata.gz: 20133b00f0f50ccc00dc1bd4bb88107911ff5f438e127b804270752c43029e2447b15a5212c701a24a49a6f98d7b12359cb3326924ea3dadf631408b316e626e
7
+ data.tar.gz: 11ca7ae94de18e0b3d4aad99d315c2b973a8e2521ee24a935e5236fdc91eace943074ad388889a09ef4d8e33e2a4b1355d2590fe16fe0a1eda05357e1a315290
data/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@
5
5
 
6
6
  # Change Log
7
7
 
8
+ ## v2.1.0 (2024-05-31)
9
+
10
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.0.1..v2.1.0)
11
+
12
+ Changes since v2.0.1:
13
+
14
+ * 93c8210 Add Git::Log#max_count
15
+ * d84097b Update YARDoc for a few a few method
16
+
8
17
  ## v2.0.1 (2024-05-21)
9
18
 
10
19
  [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.0.0..v2.0.1)
data/README.md CHANGED
@@ -101,16 +101,28 @@ directory, in the index and in the repository. Similar to running 'git status'
101
101
 
102
102
  **Git::Remote**- A reference to a remote repository that is tracked by this repository.
103
103
 
104
- **Git::Log** - An Enumerable object that references all the `Git::Object::Commit` objects that encompass your log query, which can be constructed through methods on the `Git::Log object`,
105
- like:
104
+ **Git::Log** - An Enumerable object that references all the `Git::Object::Commit`
105
+ objects that encompass your log query, which can be constructed through methods on
106
+ the `Git::Log object`, like:
106
107
 
107
- `@git.log(20).object("some_file").since("2 weeks ago").between('v2.6', 'v2.7').each { |commit| [block] }`
108
+ ```ruby
109
+ git.log
110
+ .max_count(:all)
111
+ .object('README.md')
112
+ .since('10 years ago')
113
+ .between('v1.0.7', 'HEAD')
114
+ .map { |commit| commit.sha }
115
+ ```
108
116
 
109
- Pass the `--all` option to `git log` as follows:
117
+ A maximum of 30 commits are returned if `max_count` is not called. To get all commits
118
+ that match the log query, call `max_count(:all)`.
110
119
 
111
- `@git.log.all.each { |commit| [block] }`
120
+ Note that `git.log.all` adds the `--all` option to the underlying `git log` command.
121
+ This asks for the logs of all refs (basically all commits reachable by HEAD,
122
+ branches, and tags). This does not control the maximum number of commits returned. To
123
+ control how many commits are returned, you should call `max_count`.
112
124
 
113
- **Git::Worktrees** - Enumerable object that holds `Git::Worktree objects`.
125
+ **Git::Worktrees** - Enumerable object that holds `Git::Worktree objects`.
114
126
 
115
127
  ## Errors Raised By This Gem
116
128
 
data/lib/git/base.rb CHANGED
@@ -2,12 +2,14 @@ require 'logger'
2
2
  require 'open3'
3
3
 
4
4
  module Git
5
- # Git::Base is the main public interface for interacting with Git commands.
5
+ # The main public interface for interacting with Git commands
6
6
  #
7
7
  # Instead of creating a Git::Base directly, obtain a Git::Base instance by
8
8
  # calling one of the follow {Git} class methods: {Git.open}, {Git.init},
9
9
  # {Git.clone}, or {Git.bare}.
10
10
  #
11
+ # @api public
12
+ #
11
13
  class Base
12
14
  # (see Git.bare)
13
15
  def self.bare(git_dir, options = {})
@@ -119,6 +121,62 @@ module Git
119
121
  @index = options[:index] ? Git::Index.new(options[:index], false) : nil
120
122
  end
121
123
 
124
+ # Update the index from the current worktree to prepare the for the next commit
125
+ #
126
+ # @example
127
+ # lib.add('path/to/file')
128
+ # lib.add(['path/to/file1','path/to/file2'])
129
+ # lib.add(all: true)
130
+ #
131
+ # @param [String, Array<String>] paths a file or files to be added to the repository (relative to the worktree root)
132
+ # @param [Hash] options
133
+ #
134
+ # @option options [Boolean] :all Add, modify, and remove index entries to match the worktree
135
+ # @option options [Boolean] :force Allow adding otherwise ignored files
136
+ #
137
+ def add(paths = '.', **options)
138
+ self.lib.add(paths, options)
139
+ end
140
+
141
+ # adds a new remote to this repository
142
+ # url can be a git url or a Git::Base object if it's a local reference
143
+ #
144
+ # @git.add_remote('scotts_git', 'git://repo.or.cz/rubygit.git')
145
+ # @git.fetch('scotts_git')
146
+ # @git.merge('scotts_git/master')
147
+ #
148
+ # Options:
149
+ # :fetch => true
150
+ # :track => <branch_name>
151
+ def add_remote(name, url, opts = {})
152
+ url = url.repo.path if url.is_a?(Git::Base)
153
+ self.lib.remote_add(name, url, opts)
154
+ Git::Remote.new(self, name)
155
+ end
156
+
157
+ # Create a new git tag
158
+ #
159
+ # @example
160
+ # repo.add_tag('tag_name', object_reference)
161
+ # repo.add_tag('tag_name', object_reference, {:options => 'here'})
162
+ # repo.add_tag('tag_name', {:options => 'here'})
163
+ #
164
+ # @param [String] name The name of the tag to add
165
+ # @param [Hash] options Opstions to pass to `git tag`.
166
+ # See [git-tag](https://git-scm.com/docs/git-tag) for more details.
167
+ # @option options [boolean] :annotate Make an unsigned, annotated tag object
168
+ # @option options [boolean] :a An alias for the `:annotate` option
169
+ # @option options [boolean] :d Delete existing tag with the given names.
170
+ # @option options [boolean] :f Replace an existing tag with the given name (instead of failing)
171
+ # @option options [String] :message Use the given tag message
172
+ # @option options [String] :m An alias for the `:message` option
173
+ # @option options [boolean] :s Make a GPG-signed tag.
174
+ #
175
+ def add_tag(name, *options)
176
+ self.lib.tag(name, *options)
177
+ self.tag(name)
178
+ end
179
+
122
180
  # changes current working directory for a block
123
181
  # to the git working directory
124
182
  #
@@ -251,29 +309,6 @@ module Git
251
309
  self.object('HEAD').grep(string, path_limiter, opts)
252
310
  end
253
311
 
254
- # updates the repository index using the working directory content
255
- #
256
- # @example
257
- # git.add
258
- # git.add('path/to/file')
259
- # git.add(['path/to/file1','path/to/file2'])
260
- # git.add(:all => true)
261
- #
262
- # options:
263
- # :all => true
264
- #
265
- # @param [String,Array] paths files paths to be added (optional, default='.')
266
- # @param [Hash] options
267
- # @option options [boolean] :all
268
- # Update the index not only where the working tree has a file matching
269
- # <pathspec> but also where the index already has an entry.
270
- # See [the --all option to git-add](https://git-scm.com/docs/git-add#Documentation/git-add.txt--A)
271
- # for more details.
272
- #
273
- def add(paths = '.', **options)
274
- self.lib.add(paths, options)
275
- end
276
-
277
312
  # removes file(s) from the git repository
278
313
  def rm(path = '.', opts = {})
279
314
  self.lib.rm(path, opts)
@@ -434,22 +469,6 @@ module Git
434
469
  self.lib.remotes.map { |r| Git::Remote.new(self, r) }
435
470
  end
436
471
 
437
- # adds a new remote to this repository
438
- # url can be a git url or a Git::Base object if it's a local reference
439
- #
440
- # @git.add_remote('scotts_git', 'git://repo.or.cz/rubygit.git')
441
- # @git.fetch('scotts_git')
442
- # @git.merge('scotts_git/master')
443
- #
444
- # Options:
445
- # :fetch => true
446
- # :track => <branch_name>
447
- def add_remote(name, url, opts = {})
448
- url = url.repo.path if url.is_a?(Git::Base)
449
- self.lib.remote_add(name, url, opts)
450
- Git::Remote.new(self, name)
451
- end
452
-
453
472
  # sets the url for a remote
454
473
  # url can be a git url or a Git::Base object if it's a local reference
455
474
  #
@@ -473,7 +492,7 @@ module Git
473
492
  self.lib.tags.map { |r| tag(r) }
474
493
  end
475
494
 
476
- # Creates a new git tag (Git::Tag)
495
+ # Create a new git tag
477
496
  #
478
497
  # @example
479
498
  # repo.add_tag('tag_name', object_reference)
data/lib/git/lib.rb CHANGED
@@ -38,14 +38,23 @@ module Git
38
38
 
39
39
  # Create a new Git::Lib object
40
40
  #
41
- # @param [Git::Base, Hash] base An object that passes in values for
42
- # @git_work_dir, @git_dir, and @git_index_file
41
+ # @overload initialize(base, logger)
43
42
  #
44
- # @param [Logger] logger
43
+ # @param base [Hash] the hash containing paths to the Git working copy,
44
+ # the Git repository directory, and the Git index file.
45
45
  #
46
- # @option base [Pathname] :working_directory
47
- # @option base [Pathname] :repository
48
- # @option base [Pathname] :index
46
+ # @option base [Pathname] :working_directory
47
+ # @option base [Pathname] :repository
48
+ # @option base [Pathname] :index
49
+ #
50
+ # @param [Logger] logger
51
+ #
52
+ # @overload initialize(base, logger)
53
+ #
54
+ # @param base [#dir, #repo, #index] an object with methods to get the Git worktree (#dir),
55
+ # the Git repository directory (#repo), and the Git index file (#index).
56
+ #
57
+ # @param [Logger] logger
49
58
  #
50
59
  def initialize(base = nil, logger = nil)
51
60
  @git_dir = nil
@@ -670,18 +679,20 @@ module Git
670
679
  command('config', '--global', name, value)
671
680
  end
672
681
 
673
- # updates the repository index using the working directory content
674
- #
675
- # lib.add('path/to/file')
676
- # lib.add(['path/to/file1','path/to/file2'])
677
- # lib.add(:all => true)
682
+
683
+ # Update the index from the current worktree to prepare the for the next commit
678
684
  #
679
- # options:
680
- # :all => true
681
- # :force => true
685
+ # @example
686
+ # lib.add('path/to/file')
687
+ # lib.add(['path/to/file1','path/to/file2'])
688
+ # lib.add(:all => true)
682
689
  #
683
- # @param [String,Array] paths files paths to be added to the repository
690
+ # @param [String, Array<String>] paths files to be added to the repository (relative to the worktree root)
684
691
  # @param [Hash] options
692
+ #
693
+ # @option options [Boolean] :all Add, modify, and remove index entries to match the worktree
694
+ # @option options [Boolean] :force Allow adding otherwise ignored files
695
+ #
685
696
  def add(paths='.',options={})
686
697
  arr_opts = []
687
698
 
data/lib/git/log.rb CHANGED
@@ -1,15 +1,76 @@
1
1
  module Git
2
2
 
3
- # object that holds the last X commits on given branch
3
+ # Return the last n commits that match the specified criteria
4
+ #
5
+ # @example The last (default number) of commits
6
+ # git = Git.open('.')
7
+ # Git::Log.new(git) #=> Enumerable of the last 30 commits
8
+ #
9
+ # @example The last n commits
10
+ # Git::Log.new(git).max_commits(50) #=> Enumerable of last 50 commits
11
+ #
12
+ # @example All commits returned by `git log`
13
+ # Git::Log.new(git).max_count(:all) #=> Enumerable of all commits
14
+ #
15
+ # @example All commits that match complex criteria
16
+ # Git::Log.new(git)
17
+ # .max_count(:all)
18
+ # .object('README.md')
19
+ # .since('10 years ago')
20
+ # .between('v1.0.7', 'HEAD')
21
+ #
22
+ # @api public
23
+ #
4
24
  class Log
5
25
  include Enumerable
6
26
 
7
- def initialize(base, count = 30)
27
+ # Create a new Git::Log object
28
+ #
29
+ # @example
30
+ # git = Git.open('.')
31
+ # Git::Log.new(git)
32
+ #
33
+ # @param base [Git::Base] the git repository object
34
+ # @param max_count [Integer, Symbol, nil] the number of commits to return, or
35
+ # `:all` or `nil` to return all
36
+ #
37
+ # Passing max_count to {#initialize} is equivalent to calling {#max_count} on the object.
38
+ #
39
+ def initialize(base, max_count = 30)
8
40
  dirty_log
9
41
  @base = base
10
- @count = count
42
+ max_count(max_count)
43
+ end
44
+
45
+ # The maximum number of commits to return
46
+ #
47
+ # @example All commits returned by `git log`
48
+ # git = Git.open('.')
49
+ # Git::Log.new(git).max_count(:all)
50
+ #
51
+ # @param num_or_all [Integer, Symbol, nil] the number of commits to return, or
52
+ # `:all` or `nil` to return all
53
+ #
54
+ # @return [self]
55
+ #
56
+ def max_count(num_or_all)
57
+ dirty_log
58
+ @max_count = (num_or_all == :all) ? nil : num_or_all
59
+ self
11
60
  end
12
61
 
62
+ # Adds the --all flag to the git log command
63
+ #
64
+ # This asks for the logs of all refs (basically all commits reachable by HEAD,
65
+ # branches, and tags). This does not control the maximum number of commits
66
+ # returned. To control how many commits are returned, call {#max_count}.
67
+ #
68
+ # @example Return the last 50 commits reachable by all refs
69
+ # git = Git.open('.')
70
+ # Git::Log.new(git).max_count(50).all
71
+ #
72
+ # @return [self]
73
+ #
13
74
  def all
14
75
  dirty_log
15
76
  @all = true
@@ -119,7 +180,7 @@ module Git
119
180
  # actually run the 'git log' command
120
181
  def run_log
121
182
  log = @base.lib.full_log_commits(
122
- count: @count, all: @all, object: @object, path_limiter: @path, since: @since,
183
+ count: @max_count, all: @all, object: @object, path_limiter: @path, since: @since,
123
184
  author: @author, grep: @grep, skip: @skip, until: @until, between: @between,
124
185
  cherry: @cherry
125
186
  )
data/lib/git/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  # The current gem version
3
3
  # @return [String] the current gem version.
4
- VERSION='2.0.1'
4
+ VERSION='2.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon and others
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-21 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -243,8 +243,8 @@ licenses:
243
243
  metadata:
244
244
  homepage_uri: http://github.com/ruby-git/ruby-git
245
245
  source_code_uri: http://github.com/ruby-git/ruby-git
246
- changelog_uri: https://rubydoc.info/gems/git/2.0.1/file/CHANGELOG.md
247
- documentation_uri: https://rubydoc.info/gems/git/2.0.1
246
+ changelog_uri: https://rubydoc.info/gems/git/2.1.0/file/CHANGELOG.md
247
+ documentation_uri: https://rubydoc.info/gems/git/2.1.0
248
248
  post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths: