Git/Ruby Library
This provides bindings for working with git in complex interactions, including branching and merging, object inspection and manipulation, history, patch generation and more. You should be able to do most fundamental git operations with this library.
This 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.
| Author | Scott Chacon (schacon@gmail.com) |
| License | MIT License |
open a bare repository
this takes the path to a bare git repo it expects not to be able to use a working directory so you can’t checkout stuff, commit things, etc. but you can do most read operations
# File lib/git.rb, line 59
59: def self.bare(git_dir, options = {})
60: Base.bare(git_dir, options)
61: end
clones a remote repository
options
:bare => true (does a bare clone) :repository => '/path/to/alt_git_dir' :index => '/path/to/alt_index_file'
example
Git.clone('git://repo.or.cz/rubygit.git', 'clone.git', :bare => true)
# File lib/git.rb, line 96
96: def self.clone(repository, name, options = {})
97: Base.clone(repository, name, options)
98: end
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.’
# File lib/git.rb, line 107
107: def self.export(repository, name, options = {})
108: options.delete(:remote)
109: repo = clone(repository, name, {:depth => 1}.merge(options))
110: repo.checkout("origin/#{options[:branch]}") if options[:branch]
111: Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
112: end
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@email.com’) # sets value g.config(‘user.name’) # returns ‘Scott Chacon’ g.config # returns whole config hash
# File lib/git.rb, line 138
138: def self.global_config(name = nil, value = nil)
139: lib = Git::Lib.new(nil, nil)
140: if(name && value)
141: # set value
142: lib.global_config_set(name, value)
143: elsif (name)
144: # return value
145: lib.global_config_get(name)
146: else
147: # return hash
148: lib.global_config_list
149: end
150: end
initialize a new git repository, defaults to the current working directory
options
:repository => '/path/to/alt_git_dir' :index => '/path/to/alt_index_file'
# File lib/git.rb, line 82
82: def self.init(working_dir = '.', options = {})
83: Base.init(working_dir, options)
84: end
open an existing git working directory
this will most likely be the most common way to create a git reference, referring to a working directory. if not provided in the options, the library will assume your git_dir and index are in the default place (.git/, .git/index)
options
:repository => '/path/to/alt_git_dir' :index => '/path/to/alt_index_file'
# File lib/git.rb, line 73
73: def self.open(working_dir, options = {})
74: Base.open(working_dir, options)
75: end
g.config(‘user.name’, ‘Scott Chacon’) # sets value g.config(‘user.email’, ‘email@email.com’) # sets value g.config(‘user.name’) # returns ‘Scott Chacon’ g.config # returns whole config hash
# File lib/git.rb, line 118
118: def config(name = nil, value = nil)
119: lib = Git::Lib.new
120: if(name && value)
121: # set value
122: lib.config_set(name, value)
123: elsif (name)
124: # return value
125: lib.config_get(name)
126: else
127: # return hash
128: lib.config_list
129: end
130: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.