Module: Git
- Defined in:
- 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/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/repository.rb,
lib/git/base/factory.rb,
lib/git/escaped_path.rb,
lib/git/encoding_utils.rb,
lib/git/working_directory.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: Author, Base, Branch, Branches, Config, Diff, EscapedPath, GitAltURI, GitExecuteError, GitTagNameDoesNotExist, Index, Lib, Log, Object, Path, Remote, Repository, Stash, Stashes, Status, URL, WorkingDirectory, Worktree, Worktrees
Constant Summary collapse
- VERSION =
The current gem version
'1.12.0'
Class Method Summary collapse
-
.bare(git_dir, options = {}) ⇒ Git::Base
Open a bare repository.
-
.clone(repository_url, directory = nil, options = {}) ⇒ Git::Base
Clone a repository into an empty or newly created directory.
- .config ⇒ Object
- .configure {|Base.config| ... } ⇒ Object
-
.export(repository, name, options = {}) ⇒ Object
Export the current HEAD (or a branch, if
options[:branch]
is specified) into thename
directory, then remove all traces of git from the directory. -
.global_config(name = nil, value = nil) ⇒ Object
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) ⇒ Object
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) ⇒ Object
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.
101 102 103 |
# File 'lib/git.rb', line 101 def self.(git_dir, = {}) Base.(git_dir, ) end |
.clone(repository_url, directory = nil, options = {}) ⇒ Git::Base
Clone a repository into an empty or newly created directory
173 174 175 176 177 |
# File 'lib/git.rb', line 173 def self.clone(repository_url, directory = nil, = {}) = .select { |key, _value| i[ mirror].include?(key) } directory ||= Git::URL.clone_to(repository_url, **) Base.clone(repository_url, directory, ) end |
.config ⇒ Object
65 66 67 |
# File 'lib/git.rb', line 65 def self.config return Base.config end |
.configure {|Base.config| ... } ⇒ Object
61 62 63 |
# File 'lib/git.rb', line 61 def self.configure yield Base.config end |
.export(repository, name, options = {}) ⇒ Object
Export the current HEAD (or a branch, if options[:branch]
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.’
186 187 188 189 190 191 |
# File 'lib/git.rb', line 186 def self.export(repository, name, = {}) .delete(:remote) repo = clone(repository, name, {:depth => 1}.merge()) repo.checkout("origin/#{options[:branch]}") if [:branch] Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' } end |
.global_config(name = nil, value = nil) ⇒ Object
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
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/git.rb', line 199 def self.global_config(name = nil, value = nil) lib = Git::Lib.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
263 264 265 |
# File 'lib/git.rb', line 263 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
275 276 277 |
# File 'lib/git.rb', line 275 def self.ls_remote(location = nil, = {}) Git::Lib.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`).
323 324 325 |
# File 'lib/git.rb', line 323 def self.open(working_dir, = {}) Base.open(working_dir, ) end |
Instance Method Details
#config(name = nil, value = nil) ⇒ Object
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
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/git.rb', line 47 def config(name = nil, value = nil) lib = Git::Lib.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) ⇒ Object
69 70 71 |
# File 'lib/git.rb', line 69 def global_config(name = nil, value = nil) self.class.global_config(name, value) end |