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 @@ def initialize(options = {})
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 @@ def grep(string, path_limiter = nil, opts = {})
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 @@ def remotes
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 @@ def tags
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)
0 commit comments