Module: Git
- Defined in:
- lib/git.rb,
lib/git.rb,
lib/git/lib.rb,
lib/git/log.rb,
lib/git/url.rb,
lib/git/base.rb,
lib/git/diff.rb,
lib/git/path.rb,
lib/git/index.rb,
lib/git/stash.rb,
lib/git/author.rb,
lib/git/branch.rb,
lib/git/config.rb,
lib/git/errors.rb,
lib/git/object.rb,
lib/git/remote.rb,
lib/git/status.rb,
lib/git/stashes.rb,
lib/git/version.rb,
lib/git/branches.rb,
lib/git/worktree.rb,
lib/git/worktrees.rb,
lib/git/diff_stats.rb,
lib/git/repository.rb,
lib/git/fsck_object.rb,
lib/git/fsck_result.rb,
lib/git/args_builder.rb,
lib/git/command_line.rb,
lib/git/escaped_path.rb,
lib/git/encoding_utils.rb,
lib/git/diff_path_status.rb,
lib/git/working_directory.rb,
lib/git/command_line_result.rb
Overview
The Git module provides the basic functions to open a git reference to work with. You can open a working directory, open a bare repository, initialize a new repo or clone an existing remote repository.
Defined Under Namespace
Modules: EncodingUtils Classes: ArgsBuilder, Author, Base, Branch, Branches, CommandLine, CommandLineError, CommandLineResult, Config, Diff, DiffPathStatus, DiffStats, Error, EscapedPath, FailedError, FsckObject, FsckResult, GitAltURI, Index, Lib, Log, Object, Path, ProcessIOError, Remote, Repository, SignaledError, Stash, Stashes, Status, TimeoutError, URL, UnexpectedResultError, WorkingDirectory, Worktree, Worktrees
Constant Summary collapse
- Deprecation =
The deprecation instance used to emit deprecation warnings for the Git gem
ActiveSupport::Deprecation.new('5.0.0', 'Git')
- LibImpl =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal alias for Git::Lib, used by the gem itself after the public constant is deprecated. Code outside the gem should not reference this constant.
remove_const(:Lib)
- GitExecuteError =
Deprecated.
Use Git::Error instead
An alias for Git::Error
Git::GitExecuteError error class is an alias for Git::Error for backwards compatibility. It is recommended to use Git::Error directly.
ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Git::GitExecuteError', 'Git::Error', Git::Deprecation)
- VERSION =
The current gem version
'4.4.2'
Class Method Summary collapse
-
.bare(git_dir, options = {}) ⇒ Git::Base
Open a bare repository.
-
.binary_version(binary_path = Git::Base.config.binary_path) ⇒ Array<Integer>
Return the version of the git binary.
-
.clone(repository_url, directory = nil, options = {}) ⇒ Git::Base
Clone a repository into an empty or newly created directory.
- .config
- .configure {|Base.config| ... }
- .const_missing(name) private
-
.default_branch(repository, options = {}) ⇒ String
Returns the name of the default branch of the given repository.
-
.export(repository, name, options = {})
Export the current HEAD (or a branch, if options is specified) into the
namedirectory, then remove all traces of git from the directory. -
.global_config(name = nil, value = nil)
Same as g.config, but forces it to be at the global level.
-
.init(directory = '.', options = {}) ⇒ Git::Base
Create an empty Git repository or reinitialize an existing Git repository.
-
.ls_remote(location = nil, options = {}) ⇒ {String=>Hash}
returns a Hash containing information about the references of the target repository.
-
.open(working_dir, options = {}) ⇒ Git::Base
Open a an existing Git working directory.
Instance Method Summary collapse
-
#config(name = nil, value = nil)
g.config('user.name', 'Scott Chacon') # sets value g.config('user.email', '[email protected]') # sets value g.config('user.name') # returns 'Scott Chacon' g.config # returns whole config hash.
- #global_config(name = nil, value = nil)
Class Method Details
.bare(git_dir, options = {}) ⇒ Git::Base
Open a bare repository
Opens a bare repository located in the git_dir directory.
Since there is no working copy, you can not checkout or commit
but you can do most read operations.
146 147 148 |
# File 'lib/git.rb', line 146 def self.(git_dir, = {}) Base.(git_dir, ) end |
.binary_version(binary_path = Git::Base.config.binary_path) ⇒ Array<Integer>
Return the version of the git binary
471 472 473 |
# File 'lib/git.rb', line 471 def self.binary_version(binary_path = Git::Base.config.binary_path) Base.binary_version(binary_path) end |
.clone(repository_url, directory = nil, options = {}) ⇒ Git::Base
Clone a repository into an empty or newly created directory
257 258 259 260 261 |
# File 'lib/git.rb', line 257 def self.clone(repository_url, directory = nil, = {}) = .slice(:bare, :mirror) directory ||= Git::URL.clone_to(repository_url, **) Base.clone(repository_url, directory, ) end |
.configure {|Base.config| ... }
100 101 102 |
# File 'lib/git.rb', line 100 def self.configure yield Base.config end |
.const_missing(name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 75 76 77 78 79 80 |
# File 'lib/git.rb', line 72 def self.const_missing(name) return super unless name == :Lib Git::Deprecation.warn( 'Git::Lib is deprecated and will be removed in version 5.x. ' \ 'Use the #lib accessor on the object returned by Git.init, Git.open, or Git.clone instead.' ) const_set(:Lib, LibImpl) end |
.default_branch(repository, options = {}) ⇒ String
Returns the name of the default branch of the given repository
300 301 302 |
# File 'lib/git.rb', line 300 def self.default_branch(repository, = {}) Base.repository_default_branch(repository, ) end |
.export(repository, name, options = {})
Export the current HEAD (or a branch, if options
is specified) into the name directory, then remove all traces of git from the
directory.
See clone for options. Does not obey the :remote option,
since the .git info will be deleted anyway; always uses the default
remote, 'origin.'
311 312 313 314 315 316 |
# File 'lib/git.rb', line 311 def self.export(repository, name, = {}) .delete(:remote) repo = clone(repository, name, { depth: 1 }.merge()) repo.checkout("origin/#{[:branch]}") if [:branch] FileUtils.rm_r File.join(repo.dir.to_s, '.git') end |
.global_config(name = nil, value = nil)
Same as g.config, but forces it to be at the global level
g.config('user.name', 'Scott Chacon') # sets value g.config('user.email', '[email protected]') # sets value g.config('user.name') # returns 'Scott Chacon' g.config # returns whole config hash
324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/git.rb', line 324 def self.global_config(name = nil, value = nil) lib = LibImpl.new(nil, nil) if name && value # set value lib.global_config_set(name, value) elsif name # return value lib.global_config_get(name) else # return hash lib.global_config_list end end |
.init(directory = '.', options = {}) ⇒ Git::Base
Create an empty Git repository or reinitialize an existing Git repository
394 395 396 |
# File 'lib/git.rb', line 394 def self.init(directory = '.', = {}) Base.init(directory, ) end |
.ls_remote(location = nil, options = {}) ⇒ {String=>Hash}
returns a Hash containing information about the references of the target repository
options :refs
406 407 408 |
# File 'lib/git.rb', line 406 def self.ls_remote(location = nil, = {}) LibImpl.new.ls_remote(location, ) end |
.open(working_dir, options = {}) ⇒ Git::Base
Open a an existing Git working directory
Git.open will most likely be the most common way to create a git reference, referring to an existing working directory.
If not provided in the options, the library will assume
the repository and index are in the default places (.git/, .git/index).
460 461 462 |
# File 'lib/git.rb', line 460 def self.open(working_dir, = {}) Base.open(working_dir, ) end |
Instance Method Details
#config(name = nil, value = nil)
g.config('user.name', 'Scott Chacon') # sets value g.config('user.email', '[email protected]') # sets value g.config('user.name') # returns 'Scott Chacon' g.config # returns whole config hash
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/git.rb', line 86 def config(name = nil, value = nil) lib = LibImpl.new if name && value # set value lib.config_set(name, value) elsif name # return value lib.config_get(name) else # return hash lib.config_list end end |
#global_config(name = nil, value = nil)
108 109 110 |
# File 'lib/git.rb', line 108 def global_config(name = nil, value = nil) self.class.global_config(name, value) end |