git 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/CONTRIBUTING.md +135 -60
- data/README.md +4 -1
- data/lib/git/base.rb +10 -7
- data/lib/git/lib.rb +164 -35
- data/lib/git/object.rb +2 -2
- data/lib/git/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfdec3b45e4e9b00ce87e37026c6b8fe81c306fdc7c127f01e1e682a8655986c
|
4
|
+
data.tar.gz: 3273f3eb91ab29af0143f1c5e0e5548bbc4e4575bc0a2a8ad4c6faa7cca3252b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 137c05e180c79fc9b3e2810c1fb67a7a9304c365bf7ea445788cbf392c4e0bfadc04d91871e5f1aaf93db8c457b08b55487043abeff0e6a986fc1f812712ffe4
|
7
|
+
data.tar.gz: 8e7c483a7d5b8699cc48f523678e2d5b586b51fd900ca3a9f5ca3535d3fe9ce3275e449345783de6f5b2656f620dc81225595b17a7881946319c867b089f6d22
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,22 @@
|
|
5
5
|
|
6
6
|
# Change Log
|
7
7
|
|
8
|
+
## v2.2.0 (2024-08-26)
|
9
|
+
|
10
|
+
[Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.1.1..v2.2.0)
|
11
|
+
|
12
|
+
Changes since v2.1.1:
|
13
|
+
|
14
|
+
* 7292f2c Omit the test for signed commit data on Windows
|
15
|
+
* 2d6157c Document this gem's (aspirational) design philosophy
|
16
|
+
* d4f66ab Sanitize non-option arguments passed to `git name-rev`
|
17
|
+
* 0296442 Refactor Git::Lib#rev_parse
|
18
|
+
* 9b9b31e Verify that the revision-range passed to git log does not resemble a command-line option
|
19
|
+
* dc46ede Verify that the commit-ish passed to git describe does not resemble a command-line option
|
20
|
+
* 00c4939 Verify that the commit(s) passed to git diff do not resemble a command-line option
|
21
|
+
* a08f89b Update README
|
22
|
+
* 737c4bb ls-tree optional recursion into subtrees
|
23
|
+
|
8
24
|
## v2.1.1 (2024-06-01)
|
9
25
|
|
10
26
|
[Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.1.0..v2.1.1)
|
data/CONTRIBUTING.md
CHANGED
@@ -3,116 +3,191 @@
|
|
3
3
|
# @title How To Contribute
|
4
4
|
-->
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
* [How to contribute](#how-to-contribute)
|
7
|
+
* [How to report an issue or request a feature](#how-to-report-an-issue-or-request-a-feature)
|
8
|
+
* [How to submit a code or documentation change](#how-to-submit-a-code-or-documentation-change)
|
9
|
+
* [Commit your changes to a fork of `ruby-git`](#commit-your-changes-to-a-fork-of-ruby-git)
|
10
|
+
* [Create a pull request](#create-a-pull-request)
|
11
|
+
* [Get your pull request reviewed](#get-your-pull-request-reviewed)
|
12
|
+
* [Design philosophy](#design-philosophy)
|
13
|
+
* [Direct mapping to git commands](#direct-mapping-to-git-commands)
|
14
|
+
* [Parameter naming](#parameter-naming)
|
15
|
+
* [Output processing](#output-processing)
|
16
|
+
* [Coding standards](#coding-standards)
|
17
|
+
* [1 PR = 1 Commit](#1-pr--1-commit)
|
18
|
+
* [Unit tests](#unit-tests)
|
19
|
+
* [Continuous integration](#continuous-integration)
|
20
|
+
* [Documentation](#documentation)
|
21
|
+
* [Licensing](#licensing)
|
22
|
+
|
23
|
+
|
24
|
+
# Contributing to the git gem
|
25
|
+
|
26
|
+
Thank you for your interest in contributing to the `ruby-git` project.
|
27
|
+
|
28
|
+
This document provides guidelines for contributing to the `ruby-git` project. While
|
29
|
+
these guidelines may not cover every situation, we encourage you to use your best
|
30
|
+
judgment when contributing.
|
31
|
+
|
32
|
+
If you have suggestions for improving these guidelines, please propose changes via a
|
33
|
+
pull request.
|
15
34
|
|
16
35
|
## How to contribute
|
17
36
|
|
18
|
-
You can contribute in
|
37
|
+
You can contribute in the following ways:
|
19
38
|
|
20
|
-
1. [Report an issue or
|
21
|
-
|
39
|
+
1. [Report an issue or request a
|
40
|
+
feature](#how-to-report-an-issue-or-request-a-feature)
|
41
|
+
2. [Submit a code or documentation
|
42
|
+
change](#how-to-submit-a-code-or-documentation-change)
|
22
43
|
|
23
|
-
## How to report an issue or
|
44
|
+
## How to report an issue or request a feature
|
24
45
|
|
25
|
-
ruby-git utilizes [GitHub
|
46
|
+
`ruby-git` utilizes [GitHub
|
47
|
+
Issues](https://help.github.com/en/github/managing-your-work-on-github/about-issues)
|
26
48
|
for issue tracking and feature requests.
|
27
49
|
|
28
|
-
|
29
|
-
Fill in the template
|
50
|
+
To report an issue or request a feature, please [create a `ruby-git` GitHub
|
51
|
+
issue](https://github.com/ruby-git/ruby-git/issues/new). Fill in the template as
|
52
|
+
thoroughly as possible to describe the issue or feature request.
|
30
53
|
|
31
54
|
## How to submit a code or documentation change
|
32
55
|
|
33
|
-
There is three
|
56
|
+
There is a three-step process for submitting code or documentation changes:
|
34
57
|
|
35
|
-
1. [Commit your changes to a fork of
|
58
|
+
1. [Commit your changes to a fork of
|
59
|
+
`ruby-git`](#commit-your-changes-to-a-fork-of-ruby-git)
|
36
60
|
2. [Create a pull request](#create-a-pull-request)
|
37
61
|
3. [Get your pull request reviewed](#get-your-pull-request-reviewed)
|
38
62
|
|
39
|
-
### Commit changes to a fork of ruby-git
|
63
|
+
### Commit your changes to a fork of `ruby-git`
|
40
64
|
|
41
|
-
Make your changes in a fork of the ruby-git repository.
|
65
|
+
Make your changes in a fork of the `ruby-git` repository.
|
42
66
|
|
43
67
|
### Create a pull request
|
44
68
|
|
45
|
-
|
46
|
-
|
69
|
+
If you are not familiar with GitHub Pull Requests, please refer to [this
|
70
|
+
article](https://help.github.com/articles/about-pull-requests/).
|
47
71
|
|
48
72
|
Follow the instructions in the pull request template.
|
49
73
|
|
50
74
|
### Get your pull request reviewed
|
51
75
|
|
52
|
-
Code review takes place in a GitHub pull request using the [
|
76
|
+
Code review takes place in a GitHub pull request using the [GitHub pull request
|
77
|
+
review
|
78
|
+
feature](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-reviews).
|
53
79
|
|
54
80
|
Once your pull request is ready for review, request a review from at least one
|
55
|
-
[maintainer](MAINTAINERS.md) and any
|
81
|
+
[maintainer](MAINTAINERS.md) and any other contributors you deem necessary.
|
82
|
+
|
83
|
+
During the review process, you may need to make additional commits, which should be
|
84
|
+
squashed. Additionally, you may need to rebase your branch to the latest `master`
|
85
|
+
branch if other changes have been merged.
|
86
|
+
|
87
|
+
At least one approval from a project maintainer is required before your pull request
|
88
|
+
can be merged. The maintainer is responsible for ensuring that the pull request meets
|
89
|
+
[the project's coding standards](#coding-standards).
|
90
|
+
|
91
|
+
## Design philosophy
|
92
|
+
|
93
|
+
*Note: As of v2.x of the `git` gem, this design philosophy is aspirational. Future
|
94
|
+
versions may include interface changes to fully align with these principles.*
|
95
|
+
|
96
|
+
The `git` gem is designed as a lightweight wrapper around the `git` command-line
|
97
|
+
tool, providing Ruby developers with a simple and intuitive interface for
|
98
|
+
programmatically interacting with Git.
|
99
|
+
|
100
|
+
This gem adheres to the "principle of least surprise," ensuring that it does not
|
101
|
+
introduce unnecessary abstraction layers or modify Git's core functionality. Instead,
|
102
|
+
the gem maintains a close alignment with the existing `git` command-line interface,
|
103
|
+
avoiding extensions or alterations that could lead to unexpected behaviors.
|
104
|
+
|
105
|
+
By following this philosophy, the `git` gem allows users to leverage their existing
|
106
|
+
knowledge of Git while benefiting from the expressiveness and power of Ruby's syntax
|
107
|
+
and paradigms.
|
108
|
+
|
109
|
+
### Direct mapping to git commands
|
56
110
|
|
57
|
-
|
58
|
-
|
59
|
-
|
111
|
+
Git commands are implemented within the `Git::Base` class, with each method directly
|
112
|
+
corresponding to a `git` command. When a `Git::Base` object is instantiated via
|
113
|
+
`Git.open`, `Git.clone`, or `Git.init`, the user can invoke these methods to interact
|
114
|
+
with the underlying Git repository.
|
60
115
|
|
61
|
-
|
62
|
-
|
63
|
-
|
116
|
+
For example, the `git add` command is implemented as `Git::Base#add`, and the `git
|
117
|
+
ls-files` command is implemented as `Git::Base#ls_files`.
|
118
|
+
|
119
|
+
When a single Git command serves multiple distinct purposes, method names within the
|
120
|
+
`Git::Base` class should use the `git` command name as a prefix, followed by a
|
121
|
+
descriptive suffix to indicate the specific function.
|
122
|
+
|
123
|
+
For instance, `#ls_files_untracked` and `#ls_files_staged` could be used to execute
|
124
|
+
the `git ls-files` command and return untracked and staged files, respectively.
|
125
|
+
|
126
|
+
To enhance usability, aliases may be introduced to provide more user-friendly method
|
127
|
+
names where appropriate.
|
128
|
+
|
129
|
+
### Parameter naming
|
130
|
+
|
131
|
+
Parameters within the `git` gem methods are named after their corresponding long
|
132
|
+
command-line options, ensuring familiarity and ease of use for developers already
|
133
|
+
accustomed to Git. Note that not all Git command options are supported.
|
134
|
+
|
135
|
+
### Output processing
|
136
|
+
|
137
|
+
The `git` gem translates the output of many Git commands into Ruby objects, making it
|
138
|
+
easier to work with programmatically.
|
139
|
+
|
140
|
+
These Ruby objects often include methods that allow for further Git operations where
|
141
|
+
useful, providing additional functionality while staying true to the underlying Git
|
142
|
+
behavior.
|
64
143
|
|
65
144
|
## Coding standards
|
66
145
|
|
67
|
-
|
146
|
+
To ensure high-quality contributions, all pull requests must meet the following
|
147
|
+
requirements:
|
68
148
|
|
69
149
|
### 1 PR = 1 Commit
|
70
150
|
|
71
|
-
* All commits for a PR must be squashed into
|
72
|
-
* To avoid an extra merge commit, the PR must be able to be merged as [a fast
|
73
|
-
merge](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging)
|
74
|
-
* The easiest way to ensure a fast
|
75
|
-
|
151
|
+
* All commits for a PR must be squashed into a single commit.
|
152
|
+
* To avoid an extra merge commit, the PR must be able to be merged as [a fast-forward
|
153
|
+
merge](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging).
|
154
|
+
* The easiest way to ensure a fast-forward merge is to rebase your local branch to
|
155
|
+
the `ruby-git` master branch.
|
76
156
|
|
77
157
|
### Unit tests
|
78
158
|
|
79
|
-
* All changes must be accompanied by new or modified unit tests
|
159
|
+
* All changes must be accompanied by new or modified unit tests.
|
80
160
|
* The entire test suite must pass when `bundle exec rake default` is run from the
|
81
161
|
project's local working copy.
|
82
162
|
|
83
|
-
While working on specific features you can run individual test files or
|
84
|
-
|
163
|
+
While working on specific features, you can run individual test files or a group of
|
164
|
+
tests using `bin/test`:
|
85
165
|
|
86
|
-
|
87
|
-
|
166
|
+
```bash
|
167
|
+
# run a single file (from tests/units):
|
168
|
+
$ bin/test test_object
|
88
169
|
|
89
|
-
|
90
|
-
|
170
|
+
# run multiple files:
|
171
|
+
$ bin/test test_object test_archive
|
91
172
|
|
92
|
-
|
93
|
-
|
173
|
+
# run all unit tests:
|
174
|
+
$ bin/test
|
175
|
+
```
|
94
176
|
|
95
177
|
### Continuous integration
|
96
178
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
* The [Continuous Integration
|
101
|
-
workflow](https://github.com/ruby-git/ruby-git/blob/master/.github/workflows/continuous_integration.yml)
|
102
|
-
runs both `bundle exec rake default` and `bundle exec rake test:gem` from the
|
103
|
-
project's [Rakefile](https://github.com/ruby-git/ruby-git/blob/master/Rakefile).
|
179
|
+
All tests must pass in the project's [GitHub Continuous Integration build](https://github.com/ruby-git/ruby-git/actions?query=workflow%3ACI) before the pull request will be merged.
|
180
|
+
|
181
|
+
The [Continuous Integration workflow](https://github.com/ruby-git/ruby-git/blob/master/.github/workflows/continuous_integration.yml) runs both `bundle exec rake default` and `bundle exec rake test:gem` from the project's [Rakefile](https://github.com/ruby-git/ruby-git/blob/master/Rakefile).
|
104
182
|
|
105
183
|
### Documentation
|
106
184
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
[README.md](README.md)
|
185
|
+
New and updated public methods must include [YARD](https://yardoc.org/) documentation.
|
186
|
+
|
187
|
+
New and updated public-facing features should be documented in the project's [README.md](README.md).
|
111
188
|
|
112
189
|
## Licensing
|
113
190
|
|
114
|
-
ruby-git uses [the MIT license](https://choosealicense.com/licenses/mit/) as
|
115
|
-
declared in the [LICENSE](LICENSE) file.
|
191
|
+
`ruby-git` uses [the MIT license](https://choosealicense.com/licenses/mit/) as declared in the [LICENSE](LICENSE) file.
|
116
192
|
|
117
|
-
Licensing is
|
118
|
-
software continues to be available under the terms that the author desired.
|
193
|
+
Licensing is critical to open-source projects as it ensures the software remains available under the terms desired by the author.
|
data/README.md
CHANGED
@@ -236,6 +236,9 @@ g.index.writable?
|
|
236
236
|
g.repo
|
237
237
|
g.dir
|
238
238
|
|
239
|
+
# ls-tree with recursion into subtrees (list files)
|
240
|
+
g.ls_tree("HEAD", recursive: true)
|
241
|
+
|
239
242
|
# log - returns a Git::Log object, which is an Enumerator of Git::Commit objects
|
240
243
|
# default configuration returns a max of 30 commits
|
241
244
|
g.log
|
@@ -274,7 +277,7 @@ tree.blobs
|
|
274
277
|
tree.subtrees
|
275
278
|
tree.children # blobs and subtrees
|
276
279
|
|
277
|
-
g.
|
280
|
+
g.rev_parse('v2.0.0:README.md')
|
278
281
|
|
279
282
|
g.branches # returns Git::Branch objects
|
280
283
|
g.branches.local
|
data/lib/git/base.rb
CHANGED
@@ -634,16 +634,19 @@ module Git
|
|
634
634
|
# runs git rev-parse to convert the objectish to a full sha
|
635
635
|
#
|
636
636
|
# @example
|
637
|
-
# git.
|
638
|
-
# git.
|
639
|
-
# git.
|
637
|
+
# git.rev_parse("HEAD^^")
|
638
|
+
# git.rev_parse('v2.4^{tree}')
|
639
|
+
# git.rev_parse('v2.4:/doc/index.html')
|
640
640
|
#
|
641
|
-
def
|
642
|
-
self.lib.
|
641
|
+
def rev_parse(objectish)
|
642
|
+
self.lib.rev_parse(objectish)
|
643
643
|
end
|
644
644
|
|
645
|
-
|
646
|
-
|
645
|
+
# For backwards compatibility
|
646
|
+
alias revparse rev_parse
|
647
|
+
|
648
|
+
def ls_tree(objectish, opts = {})
|
649
|
+
self.lib.ls_tree(objectish, opts)
|
647
650
|
end
|
648
651
|
|
649
652
|
def cat_file(objectish)
|
data/lib/git/lib.rb
CHANGED
@@ -169,27 +169,33 @@ module Git
|
|
169
169
|
|
170
170
|
## READ COMMANDS ##
|
171
171
|
|
172
|
+
# Finds most recent tag that is reachable from a commit
|
172
173
|
#
|
173
|
-
#
|
174
|
+
# @see https://git-scm.com/docs/git-describe git-describe
|
174
175
|
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
|
176
|
+
# @param commit_ish [String, nil] target commit sha or object name
|
177
|
+
#
|
178
|
+
# @param opts [Hash] the given options
|
179
|
+
#
|
180
|
+
# @option opts :all [Boolean]
|
181
|
+
# @option opts :tags [Boolean]
|
182
|
+
# @option opts :contains [Boolean]
|
183
|
+
# @option opts :debug [Boolean]
|
184
|
+
# @option opts :long [Boolean]
|
185
|
+
# @option opts :always [Boolean]
|
186
|
+
# @option opts :exact_match [Boolean]
|
187
|
+
# @option opts :dirty [true, String]
|
188
|
+
# @option opts :abbrev [String]
|
189
|
+
# @option opts :candidates [String]
|
190
|
+
# @option opts :match [String]
|
191
|
+
#
|
192
|
+
# @return [String] the tag name
|
193
|
+
#
|
194
|
+
# @raise [ArgumentError] if the commit_ish is a string starting with a hyphen
|
195
|
+
#
|
196
|
+
def describe(commit_ish = nil, opts = {})
|
197
|
+
assert_args_are_not_options('commit-ish object', commit_ish)
|
198
|
+
|
193
199
|
arr_opts = []
|
194
200
|
|
195
201
|
arr_opts << '--all' if opts[:all]
|
@@ -207,12 +213,42 @@ module Git
|
|
207
213
|
arr_opts << "--candidates=#{opts[:candidates]}" if opts[:candidates]
|
208
214
|
arr_opts << "--match=#{opts[:match]}" if opts[:match]
|
209
215
|
|
210
|
-
arr_opts <<
|
216
|
+
arr_opts << commit_ish if commit_ish
|
211
217
|
|
212
218
|
return command('describe', *arr_opts)
|
213
219
|
end
|
214
220
|
|
215
|
-
|
221
|
+
# Return the commits that are within the given revision range
|
222
|
+
#
|
223
|
+
# @see https://git-scm.com/docs/git-log git-log
|
224
|
+
#
|
225
|
+
# @param opts [Hash] the given options
|
226
|
+
#
|
227
|
+
# @option opts :count [Integer] the maximum number of commits to return (maps to max-count)
|
228
|
+
# @option opts :all [Boolean]
|
229
|
+
# @option opts :cherry [Boolean]
|
230
|
+
# @option opts :since [String]
|
231
|
+
# @option opts :until [String]
|
232
|
+
# @option opts :grep [String]
|
233
|
+
# @option opts :author [String]
|
234
|
+
# @option opts :between [Array<String>] an array of two commit-ish strings to specify a revision range
|
235
|
+
#
|
236
|
+
# Only :between or :object options can be used, not both.
|
237
|
+
#
|
238
|
+
# @option opts :object [String] the revision range for the git log command
|
239
|
+
#
|
240
|
+
# Only :between or :object options can be used, not both.
|
241
|
+
#
|
242
|
+
# @option opts :path_limiter [Array<String>, String] only include commits that impact files from the specified paths
|
243
|
+
#
|
244
|
+
# @return [Array<String>] the log output
|
245
|
+
#
|
246
|
+
# @raise [ArgumentError] if the resulting revision range is a string starting with a hyphen
|
247
|
+
#
|
248
|
+
def log_commits(opts = {})
|
249
|
+
assert_args_are_not_options('between', opts[:between]&.first)
|
250
|
+
assert_args_are_not_options('object', opts[:object])
|
251
|
+
|
216
252
|
arr_opts = log_common_options(opts)
|
217
253
|
|
218
254
|
arr_opts << '--pretty=oneline'
|
@@ -222,7 +258,47 @@ module Git
|
|
222
258
|
command_lines('log', *arr_opts).map { |l| l.split.first }
|
223
259
|
end
|
224
260
|
|
225
|
-
|
261
|
+
# Return the commits that are within the given revision range
|
262
|
+
#
|
263
|
+
# @see https://git-scm.com/docs/git-log git-log
|
264
|
+
#
|
265
|
+
# @param opts [Hash] the given options
|
266
|
+
#
|
267
|
+
# @option opts :count [Integer] the maximum number of commits to return (maps to max-count)
|
268
|
+
# @option opts :all [Boolean]
|
269
|
+
# @option opts :cherry [Boolean]
|
270
|
+
# @option opts :since [String]
|
271
|
+
# @option opts :until [String]
|
272
|
+
# @option opts :grep [String]
|
273
|
+
# @option opts :author [String]
|
274
|
+
# @option opts :between [Array<String>] an array of two commit-ish strings to specify a revision range
|
275
|
+
#
|
276
|
+
# Only :between or :object options can be used, not both.
|
277
|
+
#
|
278
|
+
# @option opts :object [String] the revision range for the git log command
|
279
|
+
#
|
280
|
+
# Only :between or :object options can be used, not both.
|
281
|
+
#
|
282
|
+
# @option opts :path_limiter [Array<String>, String] only include commits that impact files from the specified paths
|
283
|
+
# @option opts :skip [Integer]
|
284
|
+
#
|
285
|
+
# @return [Array<Hash>] the log output parsed into an array of hashs for each commit
|
286
|
+
#
|
287
|
+
# Each hash contains the following keys:
|
288
|
+
# * 'sha' [String] the commit sha
|
289
|
+
# * 'author' [String] the author of the commit
|
290
|
+
# * 'message' [String] the commit message
|
291
|
+
# * 'parent' [Array<String>] the commit shas of the parent commits
|
292
|
+
# * 'tree' [String] the tree sha
|
293
|
+
# * 'author' [String] the author of the commit and timestamp of when the changes were created
|
294
|
+
# * 'committer' [String] the committer of the commit and timestamp of when the commit was applied
|
295
|
+
#
|
296
|
+
# @raise [ArgumentError] if the revision range (specified with :between or :object) is a string starting with a hyphen
|
297
|
+
#
|
298
|
+
def full_log_commits(opts = {})
|
299
|
+
assert_args_are_not_options('between', opts[:between]&.first)
|
300
|
+
assert_args_are_not_options('object', opts[:object])
|
301
|
+
|
226
302
|
arr_opts = log_common_options(opts)
|
227
303
|
|
228
304
|
arr_opts << '--pretty=raw'
|
@@ -235,21 +311,48 @@ module Git
|
|
235
311
|
process_commit_log_data(full_log)
|
236
312
|
end
|
237
313
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
314
|
+
# Verify and resolve a Git revision to its full SHA
|
315
|
+
#
|
316
|
+
# @see https://git-scm.com/docs/git-rev-parse git-rev-parse
|
317
|
+
# @see https://git-scm.com/docs/git-rev-parse#_specifying_revisions Valid ways to specify revisions
|
318
|
+
# @see https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt-emltrefnamegtemegemmasterememheadsmasterememrefsheadsmasterem Ref disambiguation rules
|
319
|
+
#
|
320
|
+
# @example
|
321
|
+
# lib.rev_parse('HEAD') # => '9b9b31e704c0b85ffdd8d2af2ded85170a5af87d'
|
322
|
+
# lib.rev_parse('9b9b31e') # => '9b9b31e704c0b85ffdd8d2af2ded85170a5af87d'
|
323
|
+
#
|
324
|
+
# @param revision [String] the revision to resolve
|
325
|
+
#
|
326
|
+
# @return [String] the full commit hash
|
327
|
+
#
|
328
|
+
# @raise [Git::FailedError] if the revision cannot be resolved
|
329
|
+
# @raise [ArgumentError] if the revision is a string starting with a hyphen
|
330
|
+
#
|
331
|
+
def rev_parse(revision)
|
332
|
+
assert_args_are_not_options('rev', revision)
|
333
|
+
|
334
|
+
command('rev-parse', revision)
|
247
335
|
end
|
248
336
|
|
249
|
-
|
250
|
-
|
337
|
+
# For backwards compatibility with the old method name
|
338
|
+
alias :revparse :rev_parse
|
339
|
+
|
340
|
+
# Find the first symbolic name for given commit_ish
|
341
|
+
#
|
342
|
+
# @param commit_ish [String] the commit_ish to find the symbolic name of
|
343
|
+
#
|
344
|
+
# @return [String, nil] the first symbolic name or nil if the commit_ish isn't found
|
345
|
+
#
|
346
|
+
# @raise [ArgumentError] if the commit_ish is a string starting with a hyphen
|
347
|
+
#
|
348
|
+
def name_rev(commit_ish)
|
349
|
+
assert_args_are_not_options('commit_ish', commit_ish)
|
350
|
+
|
351
|
+
command('name-rev', commit_ish).split[1]
|
251
352
|
end
|
252
353
|
|
354
|
+
alias :namerev :name_rev
|
355
|
+
|
253
356
|
def object_type(sha)
|
254
357
|
command('cat-file', '-t', sha)
|
255
358
|
end
|
@@ -374,10 +477,15 @@ module Git
|
|
374
477
|
end
|
375
478
|
end
|
376
479
|
|
377
|
-
def ls_tree(sha)
|
480
|
+
def ls_tree(sha, opts = {})
|
378
481
|
data = { 'blob' => {}, 'tree' => {}, 'commit' => {} }
|
379
482
|
|
380
|
-
|
483
|
+
ls_tree_opts = []
|
484
|
+
ls_tree_opts << '-r' if opts[:recursive]
|
485
|
+
# path must be last arg
|
486
|
+
ls_tree_opts << opts[:path] if opts[:path]
|
487
|
+
|
488
|
+
command_lines('ls-tree', sha, *ls_tree_opts).each do |line|
|
381
489
|
(info, filenm) = line.split("\t")
|
382
490
|
(mode, type, sha) = info.split
|
383
491
|
data[type][filenm] = {:mode => mode, :sha => sha}
|
@@ -521,7 +629,24 @@ module Git
|
|
521
629
|
hsh
|
522
630
|
end
|
523
631
|
|
632
|
+
# Validate that the given arguments cannot be mistaken for a command-line option
|
633
|
+
#
|
634
|
+
# @param arg_name [String] the name of the arguments to mention in the error message
|
635
|
+
# @param args [Array<String, nil>] the arguments to validate
|
636
|
+
#
|
637
|
+
# @raise [ArgumentError] if any of the parameters are a string starting with a hyphen
|
638
|
+
# @return [void]
|
639
|
+
#
|
640
|
+
def assert_args_are_not_options(arg_name, *args)
|
641
|
+
invalid_args = args.select { |arg| arg&.start_with?('-') }
|
642
|
+
if invalid_args.any?
|
643
|
+
raise ArgumentError, "Invalid #{arg_name}: '#{invalid_args.join("', '")}'"
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
524
647
|
def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
|
648
|
+
assert_args_are_not_options('commit or commit range', obj1, obj2)
|
649
|
+
|
525
650
|
diff_opts = ['-p']
|
526
651
|
diff_opts << obj1
|
527
652
|
diff_opts << obj2 if obj2.is_a?(String)
|
@@ -531,6 +656,8 @@ module Git
|
|
531
656
|
end
|
532
657
|
|
533
658
|
def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
|
659
|
+
assert_args_are_not_options('commit or commit range', obj1, obj2)
|
660
|
+
|
534
661
|
diff_opts = ['--numstat']
|
535
662
|
diff_opts << obj1
|
536
663
|
diff_opts << obj2 if obj2.is_a?(String)
|
@@ -551,6 +678,8 @@ module Git
|
|
551
678
|
end
|
552
679
|
|
553
680
|
def diff_name_status(reference1 = nil, reference2 = nil, opts = {})
|
681
|
+
assert_args_are_not_options('commit or commit range', reference1, reference2)
|
682
|
+
|
554
683
|
opts_arr = ['--name-status']
|
555
684
|
opts_arr << reference1 if reference1
|
556
685
|
opts_arr << reference2 if reference2
|
data/lib/git/object.rb
CHANGED
@@ -23,7 +23,7 @@ module Git
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def sha
|
26
|
-
@sha ||= @base.lib.
|
26
|
+
@sha ||= @base.lib.rev_parse(@objectish)
|
27
27
|
end
|
28
28
|
|
29
29
|
def size
|
@@ -175,7 +175,7 @@ module Git
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def name
|
178
|
-
@base.lib.
|
178
|
+
@base.lib.name_rev(sha)
|
179
179
|
end
|
180
180
|
|
181
181
|
def gtree
|
data/lib/git/version.rb
CHANGED
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.
|
4
|
+
version: 2.2.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-
|
11
|
+
date: 2024-08-26 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.
|
247
|
-
documentation_uri: https://rubydoc.info/gems/git/2.
|
246
|
+
changelog_uri: https://rubydoc.info/gems/git/2.2.0/file/CHANGELOG.md
|
247
|
+
documentation_uri: https://rubydoc.info/gems/git/2.2.0
|
248
248
|
post_install_message:
|
249
249
|
rdoc_options: []
|
250
250
|
require_paths:
|