Class: Rugged::Repository
- Inherits:
-
Object
- Object
- Rugged::Repository
- Defined in:
- lib/rugged/repository.rb,
lib/rugged/attributes.rb,
ext/rugged/rugged_repo.c
Overview
Repository is an interface into a Git repository on-disk. It's the primary interface between your app and the main Git objects Rugged makes available to you.
Defined Under Namespace
Classes: Attributes
Class Method Summary collapse
-
.bare(*args) ⇒ Object
Open a bare Git repository at
pathand return aRepositoryobject representing it. -
.clone_at(url, local_path[, options]) ⇒ Object
Clone a repository from
urltolocal_path. -
.discover(path = nil, across_fs = true) ⇒ Object
Traverse
pathupwards until a Git working directory with a.gitfolder has been found, open it and return it as aRepositoryobject. -
.hash_data(str, type) ⇒ Object
Hash the contents of
stras raw bytes (ignoring any encoding information) and adding the relevant header corresponding totype, and return a hex string representing the result from the hash. -
.hash_file(path, type) ⇒ Object
Hash the contents of the file pointed at by
path, assuming that it'd be stored in the ODB with the giventype, and return a hex string representing the SHA1 OID resulting from the hash. -
.init_at(path, is_bare = false, opts = {}) ⇒ Object
Initialize a Git repository in
path. -
.new(path, options = {}) ⇒ Object
Open a Git repository in the given
pathand return aRepositoryobject representing it.
Instance Method Summary collapse
-
#ahead_behind(local, upstream) ⇒ Array
Returns a 2 element Array containing the number of commits that the upstream object is ahead and behind the local object.
-
#apply(diff, options = {}) ⇒ Boolean
Applies the given diff to the repository.
- #attributes(path, options = {}) ⇒ Object
-
#bare? ⇒ Boolean
Return whether a repository is bare or not.
-
#blob_at(revision, path) ⇒ Object
Get the blob at a path for a specific revision.
-
#branches ⇒ Object
All the branches in the repository.
-
#checkout(target, options = {}) ⇒ Object
Checkout the specified branch, reference or commit.
-
#checkout_head([options]) ⇒ nil
Updates files in the index and the working tree to match the content of the commit pointed at by
HEAD. -
#checkout_index(index[,options]) ⇒ nil
Updates files in the index and the working tree to match the content of the commit pointed at by
index. -
#checkout_tree(treeish[, options]) ⇒ Object
Updates files in the index and working tree to match the content of the tree pointed at by the
treeish. -
#cherrypick(commit[, options]) ⇒ nil
Cherry-pick the given commit and update the index and working directory accordingly.
-
#cherrypick_commit(commit, our_commit, [mainline, options]) ⇒ nil
Cherry-pick the given commit on the given base in-memory and return an index with the result.
-
#close ⇒ nil
Frees all the resources used by this repository immediately.
-
#config ⇒ Object
Return a Rugged::Config object representing this repository's config.
-
#config=(cfg) ⇒ Object
Set the configuration file for this
Repository. -
#create_branch(name, sha_or_ref = "HEAD") ⇒ Object
Create a new branch in the repository.
-
#notes_default_ref ⇒ String
Get the default notes reference for a
repository:. -
#default_signature ⇒ nil
Returns a
Hashwith the default usersignatureornil. -
#descendant_of?(commit, ancestor) ⇒ Boolean
commitandancestormust be String commit OIDs or instances of Rugged::Commit. - #diff(left, right, opts = {}) ⇒ Object
-
#diff_from_buffer(buffer) ⇒ Rugged::Diff object
Where
bufferis aString. - #diff_workdir(left, opts = {}) ⇒ Object
-
#each_id ⇒ Object
Call the given
blockonce with every object ID found inrepoand all its alternates. -
#each_note(*args) ⇒ Object
Call the given block once for each note_blob/annotated_object pair in
repository-notes_ref: (optional): canonical name of the reference to use defaults to "refs/notes/commits". -
#empty? ⇒ Boolean
Return whether a repository is empty or not.
-
#exists?(hex) ⇒ Object
Return whether an object with the given SHA1 OID (represented as a hex string of at least 7 characters) exists in the repository.
-
#expand_oids(*args) ⇒ Object
Expand a list of short oids to their full value, assuming they exist in the repository.
- #fetch(remote_or_url, *args, **kwargs) ⇒ Object
- #fetch_attributes(*args) ⇒ Object
-
#head ⇒ Object
Retrieve and resolve the reference pointed at by the repository's
HEAD. -
#head=(str) ⇒ Object
Make the repository's
HEADpoint to the specified reference. -
#head_detached? ⇒ Boolean
Return whether the
HEADof a repository is detached or not. -
#head_unborn? ⇒ Boolean
Return whether the current branch is unborn (+HEAD+ points to a non-existent branch).
-
#ident ⇒ Object
Return a Hash containing the identity that is used to write reflogs.
-
#ident=(ident) ⇒ Object
Set the identity to be used for writing reflogs.
-
#include?(hex) ⇒ Object
Return whether an object with the given SHA1 OID (represented as a hex string of at least 7 characters) exists in the repository.
-
#index ⇒ Object
Return the default index for this repository.
-
#index=(idx) ⇒ Object
Set the index for this
Repository. -
#inspect ⇒ Object
Pretty formatting of a Repository.
-
#last_commit ⇒ Object
Get the most recent commit from this repo.
-
#lookup(oid) ⇒ Object
Look up a SHA1.
-
#merge_analysis(their_commit) ⇒ Array
Analyzes the given commit and determines the opportunities for merging it into the repository's HEAD.
-
#merge_base(rb_args) ⇒ Object
Find a merge base, given two or more commits or oids.
-
#merge_bases(rb_args) ⇒ Object
Find all merge bases, given two or more commits or oids.
-
#merge_commits(our_commit, their_commit, options = {}) ⇒ Object
Merges the two given commits, returning a Rugged::Index that reflects the result of the merge.
-
#namespace ⇒ String
Returns the active namespace for the repository.
-
#namespace=(new_namespace) ⇒ Object
Sets the active namespace for the repository.
-
#path ⇒ Object
Return the full, normalized path to this repository.
-
#path_ignored?(path) ⇒ Boolean
Return whether a path is ignored or not.
-
#push(remote_or_url, *args, **kwargs) ⇒ Object
Push a list of refspecs to the given remote.
-
#read(oid) ⇒ String
Read and return the raw data of the object identified by the given
oid. -
#read_header(oid) ⇒ Hash
Read and return the header information in +repo+'s ODB for the object identified by the given
oid. -
#ref(ref_name) ⇒ Object
Look up a single reference by name.
- #ref_names(glob = nil) ⇒ Object
- #references ⇒ Object
- #refs(glob = nil) ⇒ Object
-
#remotes ⇒ Object
All the remotes in the repository.
-
#reset(target, reset_type) ⇒ nil
Sets the current head to the specified commit oid and optionally resets the index and working tree to match.
-
#reset_path(pathspecs, target = nil) ⇒ nil
Updates entries in the index from the
targetcommit tree, matching the givenpathspecs. -
#rev_parse(spec) ⇒ Object
Look up an object by a revision string.
-
#rev_parse_oid(spec) ⇒ Object
Look up an object by a revision string.
-
#revert_commit(revert_commit, our_commit, options = {}) ⇒ Object
Reverts the given commit against the given "our" commit, producing an index that reflects the result of the revert.
-
#shallow? ⇒ Boolean
Return whether a repository is a shallow clone or not.
-
#status(file = nil, &block) ⇒ Object
call-seq: repo.status { |file, status_data| block } repo.status(path) -> status_data.
-
#submodules ⇒ Object
All the submodules in the repository.
-
#tags ⇒ Object
All the tags in the repository.
-
#walk(from, sorting = Rugged::SORT_DATE, &block) ⇒ Object
Walks over a set of commits using Rugged::Walker.
-
#workdir ⇒ nil
Return the working directory for this repository, or
nilif the repository is bare. -
#workdir=(path) ⇒ Object
Sets the working directory of
repotopath. -
#write(buffer, type) ⇒ Object
Write the data contained in the
bufferstring as a raw object of the giventypeinto the repository's object database.
Class Method Details
.bare(path[, alternates]) ⇒ Object .bare(path[, options]) ⇒ Object
Open a bare Git repository at path and return a Repository
object representing it.
This is faster than Rugged::Repository.new, as it won't attempt to perform
any .git directory discovery, won't try to load the config options to
determine whether the repository is bare and won't try to load the workdir.
Optionally, you can pass a list of alternate object folders or an options Hash.
Rugged::Repository.(path, ['./other/repo/.git/objects'])
Rugged::Repository.(path, opts)
The following options can be passed in the options Hash:
:backend ::
A Rugged::Backend instance
:alternates ::
A list of alternate object folders.
Rugged::Repository.(path, :alternates => ['./other/repo/.git/objects'])
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'ext/rugged/rugged_repo.c', line 308
static VALUE rb_git_repo_open_bare(int argc, VALUE *argv, VALUE klass)
{
git_repository *repo = NULL;
int error = 0;
VALUE rb_path, rb_options, rb_alternates = 0;
rb_scan_args(argc, argv, "11", &rb_path, &rb_options);
if (!NIL_P(rb_options) && TYPE(rb_options) == T_ARRAY)
rb_alternates = rb_options;
if (!NIL_P(rb_options) && TYPE(rb_options) == T_HASH) {
/* Check for `:backend` */
VALUE rb_backend = rb_hash_aref(rb_options, CSTR2SYM("backend"));
if (!NIL_P(rb_backend)) {
rugged_repo_new_with_backend(&repo, rb_path, rb_backend);
}
/* Check for `:alternates` */
rb_alternates = rb_hash_aref(rb_options, CSTR2SYM("alternates"));
}
if (!repo) {
FilePathValue(rb_path);
error = git_repository_open_bare(&repo, StringValueCStr(rb_path));
rugged_exception_check(error);
}
if (rb_alternates) {
load_alternates(repo, rb_alternates);
}
return rugged_repo_new(klass, repo);
}
|
.clone_at(url, local_path[, options]) ⇒ Object
Clone a repository from url to local_path.
The following options can be passed in the options Hash:
:bare ::
If +true+, the clone will be created as a bare repository.
Defaults to +false+.
:checkout_branch ::
The name of a branch to checkout. Defaults to the remote's +HEAD+.
:remote ::
The name to give to the "origin" remote. Defaults to <tt>"origin"</tt>.
:ignore_cert_errors ::
If set to +true+, errors while validating the remote's host certificate will be ignored.
:proxy_url ::
The url of an http proxy to use to access the remote repository.
:credentials ::
The credentials to use for the clone operation. Can be either an instance of one
of the Rugged::Credentials types, or a proc returning one of the former.
The proc will be called with the +url+, the +username+ from the url (if applicable) and
a list of applicable credential types.
:progress ::
A callback that will be executed with the textual progress received from the remote.
This is the text send over the progress side-band (ie. the "counting objects" output).
:transfer_progress ::
A callback that will be executed to report clone progress information. It will be passed
the amount of +total_objects+, +indexed_objects+, +received_objects+, +local_objects+,
+total_deltas+, +indexed_deltas+, and +received_bytes+.
:update_tips ::
A callback that will be executed each time a reference was updated locally. It will be
passed the +refname+, +old_oid+ and +new_oid+.
Example:
Repository.clone_at("https://github.com/libgit2/rugged.git", "./some/dir", {
transfer_progress: lambda { |total_objects, indexed_objects, received_objects, local_objects, total_deltas, indexed_deltas, received_bytes|
# ...
}
})
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'ext/rugged/rugged_repo.c', line 602
static VALUE rb_git_repo_clone_at(int argc, VALUE *argv, VALUE klass)
{
VALUE url, local_path, rb_options_hash;
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
struct rugged_remote_cb_payload remote_payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
git_repository *repo;
int error;
rb_scan_args(argc, argv, "21", &url, &local_path, &rb_options_hash);
Check_Type(url, T_STRING);
FilePathValue(local_path);
parse_clone_options(&options, rb_options_hash, &remote_payload);
error = git_clone(&repo, StringValueCStr(url), StringValueCStr(local_path), &options);
if (RTEST(remote_payload.exception))
rb_jump_tag(remote_payload.exception);
rugged_exception_check(error);
return rugged_repo_new(klass, repo);
}
|
.discover(path = nil, across_fs = true) ⇒ Object
Traverse path upwards until a Git working directory with a .git
folder has been found, open it and return it as a Repository
object.
If path is nil, the current working directory will be used as
a starting point.
If across_fs is true, the traversal won't stop when reaching
a different device than the one that contained path (only applies
to UNIX-based OSses).
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 |
# File 'ext/rugged/rugged_repo.c', line 1638
static VALUE rb_git_repo_discover(int argc, VALUE *argv, VALUE klass)
{
git_repository *repo;
VALUE rb_path, rb_across_fs;
git_buf repository_path = { NULL };
int error, across_fs = 0;
rb_scan_args(argc, argv, "02", &rb_path, &rb_across_fs);
if (NIL_P(rb_path)) {
VALUE rb_dir = rb_const_get(rb_cObject, rb_intern("Dir"));
rb_path = rb_funcall(rb_dir, rb_intern("pwd"), 0);
}
if (!NIL_P(rb_across_fs)) {
across_fs = rugged_parse_bool(rb_across_fs);
}
FilePathValue(rb_path);
error = git_repository_discover(
&repository_path,
StringValueCStr(rb_path),
across_fs,
NULL
);
rugged_exception_check(error);
error = git_repository_open(&repo, repository_path.ptr);
git_buf_dispose(&repository_path);
rugged_exception_check(error);
return rugged_repo_new(klass, repo);
}
|
.hash_data(str, type) ⇒ Object
Hash the contents of str as raw bytes (ignoring any encoding
information) and adding the relevant header corresponding to type,
and return a hex string representing the result from the hash.
Repository.hash_data('hello world', :commit) #=> "de5ba987198bcf2518885f0fc1350e5172cded78"
Repository.hash_data('hello_world', :tag) #=> "9d09060c850defbc7711d08b57def0d14e742f4e"
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 |
# File 'ext/rugged/rugged_repo.c', line 1347
static VALUE rb_git_repo_hash(VALUE self, VALUE rb_buffer, VALUE rb_type)
{
int error;
git_oid oid;
Check_Type(rb_buffer, T_STRING);
error = git_odb_hash(&oid,
RSTRING_PTR(rb_buffer),
RSTRING_LEN(rb_buffer),
rugged_otype_get(rb_type)
);
rugged_exception_check(error);
return rugged_create_oid(&oid);
}
|
.hash_file(path, type) ⇒ Object
Hash the contents of the file pointed at by path, assuming
that it'd be stored in the ODB with the given type, and return
a hex string representing the SHA1 OID resulting from the hash.
Repository.hash_file('foo.txt', :commit) #=> "de5ba987198bcf2518885f0fc1350e5172cded78"
Repository.hash_file('foo.txt', :tag) #=> "9d09060c850defbc7711d08b57def0d14e742f4e"
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 |
# File 'ext/rugged/rugged_repo.c', line 1376
static VALUE rb_git_repo_hashfile(VALUE self, VALUE rb_path, VALUE rb_type)
{
int error;
git_oid oid;
FilePathValue(rb_path);
error = git_odb_hashfile(&oid,
StringValueCStr(rb_path),
rugged_otype_get(rb_type)
);
rugged_exception_check(error);
return rugged_create_oid(&oid);
}
|
.init_at(path, is_bare = false, opts = {}) ⇒ Object
Initialize a Git repository in path. This implies creating all the
necessary files on the FS, or re-initializing an already existing
repository if the files have already been created.
The is_bare (optional, defaults to false) attribute specifies whether
the Repository should be created on disk as bare or not.
Bare repositories have no working directory and are created in the root
of path. Non-bare repositories are created in a .git folder and
use path as working directory.
The following options can be passed in the options Hash:
:backend ::
A Rugged::Backend instance
Rugged::Repository.init_at('repository', :bare) #=> #<Rugged::Repository:0x108849488>
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'ext/rugged/rugged_repo.c', line 411
static VALUE rb_git_repo_init_at(int argc, VALUE *argv, VALUE klass)
{
git_repository *repo = NULL;
VALUE rb_path, rb_is_bare, rb_options;
int error;
rb_scan_args(argc, argv, "11:", &rb_path, &rb_is_bare, &rb_options);
FilePathValue(rb_path);
if (!NIL_P(rb_options)) {
/* Check for `:backend` */
VALUE rb_backend = rb_hash_aref(rb_options, CSTR2SYM("backend"));
if (rb_backend && !NIL_P(rb_backend)) {
rugged_repo_new_with_backend(&repo, rb_path, rb_backend);
}
}
if(!repo) {
error = git_repository_init(&repo, StringValueCStr(rb_path), RTEST(rb_is_bare));
rugged_exception_check(error);
}
return rugged_repo_new(klass, repo);
}
|
.new(path, options = {}) ⇒ Object
Open a Git repository in the given path and return a Repository object
representing it. An exception will be thrown if path doesn't point to a
valid repository. If you need to create a repository from scratch, use
Rugged::Repository.init_at instead.
The path must point to either the actual folder (+.git+) of a Git repository,
or to the directorly that contains the .git folder.
See also Rugged::Repository.discover and Rugged::Repository.bare.
The following options can be passed in the options Hash:
:alternates ::
A list of alternate object folders.
Examples:
Rugged::Repository.new('test/.git') #=> #<Rugged::Repository:0x108849488>
Rugged::Repository.new(path, :alternates => ['./other/repo/.git/objects'])
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'ext/rugged/rugged_repo.c', line 369
static VALUE rb_git_repo_new(int argc, VALUE *argv, VALUE klass)
{
git_repository *repo;
int error = 0;
VALUE rb_path, rb_options;
rb_scan_args(argc, argv, "10:", &rb_path, &rb_options);
FilePathValue(rb_path);
error = git_repository_open(&repo, StringValueCStr(rb_path));
rugged_exception_check(error);
if (!NIL_P(rb_options)) {
/* Check for `:alternates` */
load_alternates(repo, rb_hash_aref(rb_options, CSTR2SYM("alternates")));
}
return rugged_repo_new(klass, repo);
}
|
Instance Method Details
#ahead_behind(local, upstream) ⇒ Array
Returns a 2 element Array containing the number of commits that the upstream object is ahead and behind the local object.
local and upstream can either be strings containing SHA1 OIDs or
Rugged::Object instances.
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 |
# File 'ext/rugged/rugged_repo.c', line 1978
static VALUE rb_git_repo_ahead_behind(VALUE self, VALUE rb_local, VALUE rb_upstream) {
git_repository *repo;
int error;
git_oid local, upstream;
size_t ahead, behind;
VALUE rb_result;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
error = rugged_oid_get(&local, repo, rb_local);
rugged_exception_check(error);
error = rugged_oid_get(&upstream, repo, rb_upstream);
rugged_exception_check(error);
error = git_graph_ahead_behind(&ahead, &behind, repo, &local, &upstream);
rugged_exception_check(error);
rb_result = rb_ary_new2(2);
rb_ary_push(rb_result, INT2FIX((int) ahead));
rb_ary_push(rb_result, INT2FIX((int) behind));
return rb_result;
}
|
#apply(diff, options = {}) ⇒ Boolean
Applies the given diff to the repository.
The following options can be passed in the options Hash:
:location ::
Whether to apply the changes to the workdir (default for non-bare),
the index (default for bare) or both. Valid values: +:index+, +:workdir+,
+:both+.
:delta_callback ::
While applying the patch, this callback will be executed per delta (file).
The current +delta+ will be passed to the block. The block's return value
determines further behavior. When the block evaluates to:
- +true+: the hunk will be applied and the apply process will continue.
- +false+: the hunk will be skipped, but the apply process continues.
- +nil+: the hunk is not applied, and the apply process is aborted.
:hunk_callback ::
While applying the patch, this callback will be executed per hunk.
The current +hunk+ will be passed to the block. The block's return value
determines further behavior, as per +:delta_callback+.
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 |
# File 'ext/rugged/rugged_repo.c', line 1032
static VALUE rb_git_repo_apply(int argc, VALUE *argv, VALUE self)
{
VALUE rb_diff, rb_options;
git_diff *diff;
git_repository *repo;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
git_apply_location_t location;
struct rugged_apply_cb_payload payload = { Qnil, Qnil, 0 };
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
if (git_repository_is_bare(repo)) {
location = GIT_APPLY_LOCATION_INDEX;
} else {
location = GIT_APPLY_LOCATION_WORKDIR;
}
rb_scan_args(argc, argv, "11", &rb_diff, &rb_options);
if (!rb_obj_is_kind_of(rb_diff, rb_cRuggedDiff)) {
rb_raise(rb_eArgError, "Expected a Rugged::Diff.");
}
if (!NIL_P(rb_options)) {
Check_Type(rb_options, T_HASH);
rugged_parse_apply_options(&opts, &location, rb_options, &payload);
}
TypedData_Get_Struct(rb_diff, git_diff, &rugged_diff_type, diff);
error = git_apply(repo, diff, location, &opts);
rugged_exception_check(error);
return Qtrue;
}
|
#attributes(path, options = {}) ⇒ Object
8 9 10 |
# File 'lib/rugged/attributes.rb', line 8 def attributes(path, = {}) Attributes.new(self, path, ) end |
#bare? ⇒ Boolean
Return whether a repository is bare or not. A bare repository has no working directory.
1451 1452 1453 1454 |
# File 'ext/rugged/rugged_repo.c', line 1451
static VALUE rb_git_repo_is_bare(VALUE self)
{
RB_GIT_REPO_GETTER(is_bare);
}
|
#blob_at(revision, path) ⇒ Object
Get the blob at a path for a specific revision.
revision - The String SHA1. path - The String file path.
Returns a Rugged::Blob object
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/rugged/repository.rb', line 242 def blob_at(revision, path) tree = Rugged::Commit.lookup(self, revision).tree begin blob_data = tree.path(path) rescue Rugged::TreeError return nil end blob = Rugged::Blob.lookup(self, blob_data[:oid]) (blob.type == :blob) ? blob : nil end |
#branches ⇒ Object
All the branches in the repository
Returns a BranchCollection containing Rugged::Branch objects
207 208 209 |
# File 'lib/rugged/repository.rb', line 207 def branches @branches ||= BranchCollection.new(self) end |
#checkout(target, options = {}) ⇒ Object
Checkout the specified branch, reference or commit.
target - A revparse spec for the branch, reference or commit to check out. options - Options passed to #checkout_tree.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rugged/repository.rb', line 29 def checkout(target, = {}) [:strategy] ||= :safe .delete(:paths) return checkout_head(**) if target == "HEAD" if target.kind_of?(Rugged::Branch) branch = target else branch = branches[target] end if branch self.checkout_tree(branch.target, **) if branch.remote? references.create("HEAD", branch.target_id, force: true) else references.create("HEAD", branch.canonical_name, force: true) end else commit = Commit.lookup(self, self.rev_parse_oid(target)) references.create("HEAD", commit.oid, force: true) self.checkout_tree(commit, **) end end |
#checkout_head([options]) ⇒ nil
Updates files in the index and the working tree to match the content of the
commit pointed at by HEAD.
See Repository#checkout_tree for a list of supported options.
2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 |
# File 'ext/rugged/rugged_repo.c', line 2472
static VALUE rb_git_checkout_head(int argc, VALUE *argv, VALUE self)
{
VALUE rb_options;
git_repository *repo;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
struct rugged_cb_payload *payload;
int error, exception = 0;
rb_scan_args(argc, argv, "00:", &rb_options);
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
rugged_parse_checkout_options(&opts, rb_options);
error = git_checkout_head(repo, &opts);
xfree(opts.paths.strings);
if ((payload = opts.notify_payload) != NULL) {
exception = payload->exception;
xfree(opts.notify_payload);
}
if ((payload = opts.progress_payload) != NULL) {
exception = payload->exception;
xfree(opts.progress_payload);
}
if (exception)
rb_jump_tag(exception);
rugged_exception_check(error);
return Qnil;
}
|
#checkout_index(index[,options]) ⇒ nil
Updates files in the index and the working tree to match the content of the
commit pointed at by index.
See Repository#checkout_tree for a list of supported options.
2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 |
# File 'ext/rugged/rugged_repo.c', line 2424
static VALUE rb_git_checkout_index(int argc, VALUE *argv, VALUE self)
{
VALUE rb_index, rb_options;
git_repository *repo;
git_index *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
struct rugged_cb_payload *payload;
int error, exception = 0;
rb_scan_args(argc, argv, "10:", &rb_index, &rb_options);
if (!rb_obj_is_kind_of(rb_index, rb_cRuggedIndex))
rb_raise(rb_eTypeError, "Expected Rugged::Index");
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
TypedData_Get_Struct(rb_index, git_index, &rugged_index_type, index);
rugged_parse_checkout_options(&opts, rb_options);
error = git_checkout_index(repo, index, &opts);
xfree(opts.paths.strings);
if ((payload = opts.notify_payload) != NULL) {
exception = payload->exception;
xfree(opts.notify_payload);
}
if ((payload = opts.progress_payload) != NULL) {
exception = payload->exception;
xfree(opts.progress_payload);
}
if (exception)
rb_jump_tag(exception);
rugged_exception_check(error);
return Qnil;
}
|
#checkout_tree(treeish[, options]) ⇒ Object
Updates files in the index and working tree to match the content of the
tree pointed at by the treeish.
The following options can be passed in the options Hash:
:progress ::
A callback that will be executed for checkout progress notifications.
Up to 3 parameters are passed on each execution:
- The path to the last updated file (or +nil+ on the very first invocation).
- The number of completed checkout steps.
- The number of total checkout steps to be performed.
:notify ::
A callback that will be executed for each checkout notification types specified
with +:notify_flags+. Up to 5 parameters are passed on each execution:
- An array containing the +:notify_flags+ that caused the callback execution.
- The path of the current file.
- A hash describing the baseline blob (or +nil+ if it does not exist).
- A hash describing the target blob (or +nil+ if it does not exist).
- A hash describing the workdir blob (or +nil+ if it does not exist).
:strategy ::
A single symbol or an array of symbols representing the strategies to use when
performing the checkout. Possible values are:
:none ::
Perform a dry run (default).
:safe ::
Allow safe updates that cannot overwrite uncommitted data.
:recreate_missing ::
Allow checkout to recreate missing files.
:force ::
Allow all updates to force working directory to look like index.
:allow_conflicts ::
Allow checkout to make safe updates even if conflicts are found.
:remove_untracked ::
Remove untracked files not in index (that are not ignored).
:remove_ignored ::
Remove ignored files not in index.
:update_only ::
Only update existing files, don't create new ones.
:dont_update_index ::
Normally checkout updates index entries as it goes; this stops that.
:no_refresh ::
Don't refresh index/config/etc before doing checkout.
:disable_pathspec_match ::
Treat pathspec as simple list of exact match file paths.
:skip_locked_directories ::
Ignore directories in use, they will be left empty.
:skip_unmerged ::
Allow checkout to skip unmerged files (NOT IMPLEMENTED).
:use_ours ::
For unmerged files, checkout stage 2 from index (NOT IMPLEMENTED).
:use_theirs ::
For unmerged files, checkout stage 3 from index (NOT IMPLEMENTED).
:update_submodules ::
Recursively checkout submodules with same options (NOT IMPLEMENTED).
:update_submodules_if_changed ::
Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED).
:disable_filters ::
If +true+, filters like CRLF line conversion will be disabled.
:dir_mode ::
Mode for newly created directories. Default: +0755+.
:file_mode ::
Mode for newly created files. Default: +0755+ or +0644+.
:file_open_flags ::
Mode for opening files. Default: <code>IO::CREAT | IO::TRUNC | IO::WRONLY</code>.
:notify_flags ::
A single symbol or an array of symbols representing the cases in which the +:notify+
callback should be invoked. Possible values are:
:none ::
Do not invoke the +:notify+ callback (default).
:conflict ::
Invoke the callback for conflicting paths.
:dirty ::
Invoke the callback for "dirty" files, i.e. those that do not need an update but
no longer match the baseline.
:updated ::
Invoke the callback for any file that was changed.
:untracked ::
Invoke the callback for untracked files.
:ignored ::
Invoke the callback for ignored files.
:all ::
Invoke the callback for all these cases.
:paths ::
A glob string or an array of glob strings specifying which paths should be taken
into account for the checkout operation. +nil+ will match all files.
Default: +nil+.
:baseline ::
A Rugged::Tree that represents the current, expected contents of the workdir.
Default: +HEAD+.
:target_directory ::
A path to an alternative workdir directory in which the checkout should be performed.
2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 |
# File 'ext/rugged/rugged_repo.c', line 2369
static VALUE rb_git_checkout_tree(int argc, VALUE *argv, VALUE self)
{
VALUE rb_treeish, rb_options;
git_repository *repo;
git_object *treeish;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
struct rugged_cb_payload *payload;
int error, exception = 0;
rb_scan_args(argc, argv, "10:", &rb_treeish, &rb_options);
if (TYPE(rb_treeish) == T_STRING) {
rb_treeish = rugged_object_rev_parse(self, rb_treeish, 1);
}
if (!rb_obj_is_kind_of(rb_treeish, rb_cRuggedCommit) &&
!rb_obj_is_kind_of(rb_treeish, rb_cRuggedTag) &&
!rb_obj_is_kind_of(rb_treeish, rb_cRuggedTree)) {
rb_raise(rb_eTypeError, "Expected Rugged::Commit, Rugged::Tag or Rugged::Tree");
}
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
TypedData_Get_Struct(rb_treeish, git_object, &rugged_object_type, treeish);
rugged_parse_checkout_options(&opts, rb_options);
error = git_checkout_tree(repo, treeish, &opts);
xfree(opts.paths.strings);
if ((payload = opts.notify_payload) != NULL) {
exception = payload->exception;
xfree(opts.notify_payload);
}
if ((payload = opts.progress_payload) != NULL) {
exception = payload->exception;
xfree(opts.progress_payload);
}
if (exception)
rb_jump_tag(exception);
rugged_exception_check(error);
return Qnil;
}
|
#cherrypick(commit[, options]) ⇒ nil
Cherry-pick the given commit and update the index and working directory accordingly.
commit can be either a string containing a commit id or a
Rugged::Commit object.
The following options can be passed in the options Hash:
:mainline ::
When cherry-picking a merge, you need to specify the parent number
(starting from 1) which should be considered the mainline.
2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 |
# File 'ext/rugged/rugged_repo.c', line 2668
static VALUE rb_git_repo_cherrypick(int argc, VALUE *argv, VALUE self)
{
VALUE rb_options, rb_commit;
git_repository *repo;
git_commit *commit;
git_cherrypick_options opts = GIT_CHERRYPICK_OPTIONS_INIT;
int error;
rb_scan_args(argc, argv, "10:", &rb_commit, &rb_options);
if (TYPE(rb_commit) == T_STRING) {
rb_commit = rugged_object_rev_parse(self, rb_commit, 1);
}
if (!rb_obj_is_kind_of(rb_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
TypedData_Get_Struct(rb_commit, git_commit, &rugged_object_type, commit);
rugged_parse_cherrypick_options(&opts, rb_options);
error = git_cherrypick(repo, commit, &opts);
rugged_exception_check(error);
return Qnil;
}
|
#cherrypick_commit(commit, our_commit, [mainline, options]) ⇒ nil
Cherry-pick the given commit on the given base in-memory and return an index with the result.
commit can be either a string containing a commit id or a
Rugged::Commit object.
our_commit is the base commit, can be either a string containing
a commit id or a Rugged::Commit object.
mainline when cherry-picking a merge, this is the parent number
(starting from 1) which should be considered the mainline.
2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 |
# File 'ext/rugged/rugged_repo.c', line 2715
static VALUE rb_git_repo_cherrypick_commit(int argc, VALUE *argv, VALUE self)
{
VALUE rb_options, rb_commit, rb_our_commit, rb_mainline;
git_repository *repo;
git_commit *commit, *our_commit;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_index *index;
int error, mainline;
rb_scan_args(argc, argv, "21:", &rb_commit, &rb_our_commit, &rb_mainline, &rb_options);
if (TYPE(rb_commit) == T_STRING) {
rb_commit = rugged_object_rev_parse(self, rb_commit, 1);
}
if (TYPE(rb_our_commit) == T_STRING) {
rb_our_commit = rugged_object_rev_parse(self, rb_our_commit, 1);
}
if (!rb_obj_is_kind_of(rb_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
if (!rb_obj_is_kind_of(rb_our_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
TypedData_Get_Struct(rb_commit, git_commit, &rugged_object_type, commit);
TypedData_Get_Struct(rb_our_commit, git_commit, &rugged_object_type, our_commit);
rugged_parse_merge_options(&opts, rb_options);
mainline = NIL_P(rb_mainline) ? 0 : FIX2UINT(rb_mainline);
error = git_cherrypick_commit(&index, repo, commit, our_commit, mainline, &opts);
rugged_exception_check(error);
return rugged_index_new(rb_cRuggedIndex, self, index);
}
|
#close ⇒ nil
Frees all the resources used by this repository immediately. The repository can still be used after this call. Resources will be opened as necessary.
It is not required to call this method explicitly. Repositories are closed automatically before garbage collection
1916 1917 1918 1919 1920 1921 1922 1923 1924 |
# File 'ext/rugged/rugged_repo.c', line 1916
static VALUE rb_git_repo_close(VALUE self)
{
git_repository *repo;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
git_repository__cleanup(repo);
return Qnil;
}
|
#config ⇒ Object
Return a Rugged::Config object representing this repository's config.
711 712 713 714 |
# File 'ext/rugged/rugged_repo.c', line 711
static VALUE rb_git_repo_get_config(VALUE self)
{
RB_GIT_REPO_OWNED_GET(rb_cRuggedConfig, config);
}
|
#config=(cfg) ⇒ Object
Set the configuration file for this Repository. cfg must be a instance of
Rugged::Config. This config file will be used internally by all
operations that need to lookup configuration settings on repo.
Note that it's not necessary to set the config for any repository;
by default repositories are loaded with their relevant config files
on the filesystem, and the corresponding global and system files if
they can be found.
700 701 702 703 |
# File 'ext/rugged/rugged_repo.c', line 700
static VALUE rb_git_repo_set_config(VALUE self, VALUE rb_data)
{
RB_GIT_REPO_OWNED_SET(rb_cRuggedConfig, config);
}
|
#create_branch(name, sha_or_ref = "HEAD") ⇒ Object
Create a new branch in the repository
name - The name of the branch (without a full reference path) sha_or_ref - The target of the branch; either a String representing an OID or a reference name, or a Rugged::Object instance.
Returns a Rugged::Branch object
225 226 227 228 229 230 231 232 233 234 |
# File 'lib/rugged/repository.rb', line 225 def create_branch(name, sha_or_ref = "HEAD") case sha_or_ref when Rugged::Object target = sha_or_ref.oid else target = rev_parse_oid(sha_or_ref) end branches.create(name, target) end |
#notes_default_ref ⇒ String
Get the default notes reference for a repository:
Returns a new String object.
repo.default_notes_ref #=> "refs/notes/commits"
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'ext/rugged/rugged_note.c', line 332
static VALUE rb_git_note_default_ref_GET(VALUE self)
{
git_repository *repo = NULL;
git_buf ref_name = { 0 };
VALUE rb_result;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
rugged_exception_check(
git_note_default_ref(&ref_name, repo)
);
rb_result = rb_enc_str_new(ref_name.ptr, ref_name.size, rb_utf8_encoding());
git_buf_dispose(&ref_name);
return rb_result;
}
|
#default_signature ⇒ nil
Returns a Hash with the default user signature or nil.
Looks up the user.name and user.email from the configuration and
uses the current time as the timestamp, and creates a new signature
based on that information. It will return nil if either the
user.name or user.email are not set.
Returns a Hash:
:name: theuser.nameconfig value:email: theuser.emailconfig value:time: the current time as aTimeinstance
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 |
# File 'ext/rugged/rugged_repo.c', line 2018
static VALUE rb_git_repo_default_signature(VALUE self) {
int error;
git_repository *repo;
git_signature *signature;
VALUE rb_signature;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
error = git_signature_default(&signature, repo);
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
rb_signature = rugged_signature_new(signature, NULL);
git_signature_free(signature);
return rb_signature;
}
|
#descendant_of?(commit, ancestor) ⇒ Boolean
commit and ancestor must be String commit OIDs or instances of Rugged::Commit.
Returns true if commit is a descendant of ancestor, or false if not.
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 |
# File 'ext/rugged/rugged_repo.c', line 1314
static VALUE rb_git_repo_descendant_of(VALUE self, VALUE rb_commit, VALUE rb_ancestor)
{
int result;
int error;
git_repository *repo;
git_oid commit, ancestor;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
error = rugged_oid_get(&commit, repo, rb_commit);
rugged_exception_check(error);
error = rugged_oid_get(&ancestor, repo, rb_ancestor);
rugged_exception_check(error);
result = git_graph_descendant_of(repo, &commit, &ancestor);
rugged_exception_check(result);
return result ? Qtrue : Qfalse;
}
|
#diff(left, right, opts = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rugged/repository.rb', line 99 def diff(left, right, opts = {}) left = rev_parse(left) if left.kind_of?(String) right = rev_parse(right) if right.kind_of?(String) if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit) && !left.nil? raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance" end if !right.is_a?(Rugged::Tree) && !right.is_a?(Rugged::Commit) && !right.nil? raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance" end if left left.diff(right, opts) elsif right right.diff(left, opts.merge(:reverse => !opts[:reverse])) end end |
#diff_from_buffer(buffer) ⇒ Rugged::Diff object
Where buffer is a String.
Returns A Rugged::Diff object
2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 |
# File 'ext/rugged/rugged_repo.c', line 2760
static VALUE rb_git_diff_from_buffer(VALUE self, VALUE rb_buffer)
{
git_diff *diff = NULL;
const char *buffer;
size_t len;
int error;
Check_Type(rb_buffer, T_STRING);
buffer = RSTRING_PTR(rb_buffer);
len = RSTRING_LEN(rb_buffer);
error = git_diff_from_buffer(&diff, buffer, len);
rugged_exception_check(error);
return rugged_diff_new(rb_cRuggedDiff, self, diff);
}
|
#diff_workdir(left, opts = {}) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/rugged/repository.rb', line 118 def diff_workdir(left, opts = {}) left = rev_parse(left) if left.kind_of?(String) if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit) raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance" end left.diff_workdir(opts) end |
#each_id {|id| ... } ⇒ Object #each_id ⇒ Enumerator
Call the given block once with every object ID found in repo
and all its alternates. Object IDs are passed as 40-character
strings.
1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 |
# File 'ext/rugged/rugged_repo.c', line 1774
static VALUE rb_git_repo_each_id(VALUE self)
{
git_repository *repo;
git_odb *odb;
int error, exception = 0;
RETURN_ENUMERATOR(self, 0, 0);
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
error = git_repository_odb(&odb, repo);
rugged_exception_check(error);
error = git_odb_foreach(odb, &rugged__each_id_cb, &exception);
git_odb_free(odb);
if (exception)
rb_jump_tag(exception);
rugged_exception_check(error);
return Qnil;
}
|
#each_note(notes_ref = "refs/notes/commits") {|note_blob, annotated_object| ... } ⇒ Object #each_note(notes_ref = "refs/notes/commits") ⇒ Object
Call the given block once for each note_blob/annotated_object pair in repository
notes_ref: (optional): canonical name of the reference to use defaults to "refs/notes/commits"
If no block is given, an Enumerator is returned.
@repo.each_note do |note_blob, annotated_object|
puts "#{note_blob.oid} => #{annotated_object.oid}"
end
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'ext/rugged/rugged_note.c', line 295
static VALUE rb_git_note_each(int argc, VALUE *argv, VALUE self)
{
git_repository *repo;
const char *notes_ref = NULL;
int error;
struct rugged_cb_payload payload = { self, 0 };
VALUE rb_notes_ref;
RETURN_ENUMERATOR(self, argc, argv);
rb_scan_args(argc, argv, "01", &rb_notes_ref);
if (!NIL_P(rb_notes_ref)) {
Check_Type(rb_notes_ref, T_STRING);
notes_ref = StringValueCStr(rb_notes_ref);
}
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
error = git_note_foreach(repo, notes_ref, &cb_note__each, &payload);
if (payload.exception)
rb_jump_tag(payload.exception);
rugged_exception_check(error);
return Qnil;
}
|
#empty? ⇒ Boolean
Return whether a repository is empty or not. An empty repository has HEAD pointing to the default value and there are no other references.
1476 1477 1478 1479 |
# File 'ext/rugged/rugged_repo.c', line 1476
static VALUE rb_git_repo_is_empty(VALUE self)
{
RB_GIT_REPO_GETTER(is_empty);
}
|
#include?(oid) ⇒ Boolean #exists?(oid) ⇒ Boolean
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
# File 'ext/rugged/rugged_repo.c', line 1135
static VALUE rb_git_repo_exists(VALUE self, VALUE hex)
{
git_repository *repo;
git_odb *odb;
git_oid oid;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
Check_Type(hex, T_STRING);
error = git_oid_fromstrn(&oid, RSTRING_PTR(hex), RSTRING_LEN(hex));
rugged_exception_check(error);
error = git_repository_odb(&odb, repo);
rugged_exception_check(error);
error = git_odb_exists_prefix(NULL, odb, &oid, RSTRING_LEN(hex));
git_odb_free(odb);
if (error == 0 || error == GIT_EAMBIGUOUS)
return Qtrue;
return Qfalse;
}
|
#expand_oids([oid..], object_type = :any) ⇒ Hash #expand_oids([oid..], object_type = [type..]) ⇒ Hash
Expand a list of short oids to their full value, assuming they exist
in the repository. If object_type is passed and is an array, it must
be the same length as the OIDs array. If it's a single type name, all
OIDs will be expected to resolve to that object type. OIDs that don't
match the expected object types will not be expanded.
Returns a hash of { short_oid => full_oid } for the short OIDs which
exist in the repository and match the expected object type. Missing OIDs
will not appear in the resulting hash.
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
# File 'ext/rugged/rugged_repo.c', line 1241
static VALUE rb_git_repo_expand_oids(int argc, VALUE *argv, VALUE self)
{
VALUE rb_result, rb_oids, rb_expected_type;
git_repository *repo;
git_odb *odb;
git_odb_expand_id *expand;
long i, expand_count;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
rb_scan_args(argc, argv, "11", &rb_oids, &rb_expected_type);
Check_Type(rb_oids, T_ARRAY);
expand_count = RARRAY_LEN(rb_oids);
expand = alloca(expand_count * sizeof(git_odb_expand_id));
for (i = 0; i < expand_count; ++i) {
VALUE rb_hex = rb_ary_entry(rb_oids, i);
Check_Type(rb_hex, T_STRING);
rugged_exception_check(
git_oid_fromstrn(&expand[i].id, RSTRING_PTR(rb_hex), RSTRING_LEN(rb_hex))
);
expand[i].length = RSTRING_LEN(rb_hex);
}
if (TYPE(rb_expected_type) == T_ARRAY) {
if (RARRAY_LEN(rb_expected_type) != expand_count)
rb_raise(rb_eRuntimeError,
"the `object_type` array must be the same length as the `oids` array");
for (i = 0; i < expand_count; ++i) {
VALUE rb_type = rb_ary_entry(rb_expected_type, i);
expand[i].type = rugged_otype_get(rb_type);
}
} else {
git_otype expected_type = GIT_OBJ_ANY;
if (!NIL_P(rb_expected_type))
expected_type = rugged_otype_get(rb_expected_type);
for (i = 0; i < expand_count; ++i)
expand[i].type = expected_type;
}
error = git_repository_odb(&odb, repo);
rugged_exception_check(error);
error = git_odb_expand_ids(odb, expand, (size_t)expand_count);
git_odb_free(odb);
rugged_exception_check(error);
rb_result = rb_hash_new();
for (i = 0; i < expand_count; ++i) {
if (expand[i].length) {
rb_hash_aset(rb_result,
rb_ary_entry(rb_oids, i), rugged_create_oid(&expand[i].id));
}
}
return rb_result;
}
|
#fetch(remote_or_url, *args, **kwargs) ⇒ Object
253 254 255 256 257 258 |
# File 'lib/rugged/repository.rb', line 253 def fetch(remote_or_url, *args, **kwargs) unless remote_or_url.kind_of? Remote remote_or_url = remotes[remote_or_url] || remotes.create_anonymous(remote_or_url) end remote_or_url.fetch(*args, **kwargs) end |
#fetch_attributes(*args) ⇒ Object
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 |
# File 'ext/rugged/rugged_repo.c', line 2566
static VALUE rb_git_repo_attributes(int argc, VALUE *argv, VALUE self)
{
VALUE rb_path, rb_names, rb_options;
git_repository *repo;
int error, options = 0;
rb_scan_args(argc, argv, "12", &rb_path, &rb_names, &rb_options);
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
FilePathValue(rb_path);
if (!NIL_P(rb_options)) {
Check_Type(rb_options, T_FIXNUM);
options = FIX2INT(rb_options);
}
switch (TYPE(rb_names)) {
case T_ARRAY:
{
VALUE rb_result;
const char **values;
const char **names;
long i, num_attr = RARRAY_LEN(rb_names);
if (num_attr > 32)
rb_raise(rb_eRuntimeError, "Too many attributes requested");
values = alloca(num_attr * sizeof(const char *));
names = alloca(num_attr * sizeof(const char *));
for (i = 0; i < num_attr; ++i) {
VALUE attr = rb_ary_entry(rb_names, i);
Check_Type(attr, T_STRING);
names[i] = StringValueCStr(attr);
}
error = git_attr_get_many(
values, repo, options,
StringValueCStr(rb_path),
(size_t)num_attr, names);
rugged_exception_check(error);
rb_result = rb_hash_new();
for (i = 0; i < num_attr; ++i) {
VALUE attr = rb_ary_entry(rb_names, i);
rb_hash_aset(rb_result, attr, rugged_create_attr(values[i]));
}
return rb_result;
}
case T_STRING:
{
const char *value;
error = git_attr_get(
&value, repo, options,
StringValueCStr(rb_path),
StringValueCStr(rb_names));
rugged_exception_check(error);
return rugged_create_attr(value);
}
case T_NIL:
{
VALUE rb_result = rb_hash_new();
error = git_attr_foreach(
repo, options,
StringValueCStr(rb_path),
&foreach_attr_hash,
(void *)rb_result);
rugged_exception_check(error);
return rb_result;
}
default:
rb_raise(rb_eTypeError,
"Invalid attribute name (expected String or Array)");
}
}
|
#head ⇒ Object
Retrieve and resolve the reference pointed at by the repository's HEAD.
Returns nil if HEAD is missing.
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 |
# File 'ext/rugged/rugged_repo.c', line 1532
static VALUE rb_git_repo_get_head(VALUE self)
{
git_repository *repo;
git_reference *head;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
error = git_repository_head(&head, repo);
if (error == GIT_ENOTFOUND)
return Qnil;
else
rugged_exception_check(error);
return rugged_ref_new(rb_cRuggedReference, self, head);
}
|
#head=(str) ⇒ Object
Make the repository's HEAD point to the specified reference.
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 |
# File 'ext/rugged/rugged_repo.c', line 1510
static VALUE rb_git_repo_set_head(VALUE self, VALUE rb_head)
{
git_repository *repo;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
Check_Type(rb_head, T_STRING);
error = git_repository_set_head(repo, StringValueCStr(rb_head));
rugged_exception_check(error);
return Qnil;
}
|
#head_detached? ⇒ Boolean
Return whether the HEAD of a repository is detached or not.
1487 1488 1489 1490 |
# File 'ext/rugged/rugged_repo.c', line 1487
static VALUE rb_git_repo_head_detached(VALUE self)
{
RB_GIT_REPO_GETTER(head_detached);
}
|
#head_unborn? ⇒ Boolean
Return whether the current branch is unborn (+HEAD+ points to a non-existent branch).
1499 1500 1501 1502 |
# File 'ext/rugged/rugged_repo.c', line 1499
static VALUE rb_git_repo_head_unborn(VALUE self)
{
RB_GIT_REPO_GETTER(head_unborn);
}
|
#ident ⇒ Object
Return a Hash containing the identity that is used to write reflogs.
ident is a Hash containing name and/or email entries, or nil.
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
# File 'ext/rugged/rugged_repo.c', line 761
static VALUE rb_git_repo_get_ident(VALUE self)
{
VALUE rb_ident = rb_hash_new();
git_repository *repo;
const char *name = NULL, *email = NULL;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
rugged_exception_check(
git_repository_ident(&name, &email, repo)
);
if (name) {
rb_hash_aset(rb_ident, CSTR2SYM("name"), rb_str_new_utf8(name));
}
if (email) {
rb_hash_aset(rb_ident, CSTR2SYM("email"), rb_str_new_utf8(email));
}
return rb_ident;
}
|
#ident=(ident) ⇒ Object
Set the identity to be used for writing reflogs.
ident can be either nil or a Hash containing name and/or email entries.
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
# File 'ext/rugged/rugged_repo.c', line 724
static VALUE rb_git_repo_set_ident(VALUE self, VALUE rb_ident) {
VALUE rb_val;
git_repository *repo;
const char *name = NULL, *email = NULL;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
if (!NIL_P(rb_ident)) {
Check_Type(rb_ident, T_HASH);
if (!NIL_P(rb_val = rb_hash_aref(rb_ident, CSTR2SYM("name")))) {
Check_Type(rb_val, T_STRING);
name = StringValueCStr(rb_val);
}
if (!NIL_P(rb_val = rb_hash_aref(rb_ident, CSTR2SYM("email")))) {
Check_Type(rb_val, T_STRING);
email = StringValueCStr(rb_val);
}
}
rugged_exception_check(
git_repository_set_ident(repo, name, email)
);
return Qnil;
}
|
#include?(oid) ⇒ Boolean #exists?(oid) ⇒ Boolean
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
# File 'ext/rugged/rugged_repo.c', line 1135
static VALUE rb_git_repo_exists(VALUE self, VALUE hex)
{
git_repository *repo;
git_odb *odb;
git_oid oid;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
Check_Type(hex, T_STRING);
error = git_oid_fromstrn(&oid, RSTRING_PTR(hex), RSTRING_LEN(hex));
rugged_exception_check(error);
error = git_repository_odb(&odb, repo);
rugged_exception_check(error);
error = git_odb_exists_prefix(NULL, odb, &oid, RSTRING_LEN(hex));
git_odb_free(odb);
if (error == 0 || error == GIT_EAMBIGUOUS)
return Qtrue;
return Qfalse;
}
|
#index ⇒ Object
Return the default index for this repository.
682 683 684 685 |
# File 'ext/rugged/rugged_repo.c', line 682
static VALUE rb_git_repo_get_index(VALUE self)
{
RB_GIT_REPO_OWNED_GET(rb_cRuggedIndex, index);
}
|
#index=(idx) ⇒ Object
Set the index for this Repository. idx must be a instance of
Rugged::Index. This index will be used internally by all
operations that use the Git index on repo.
Note that it's not necessary to set the index for any repository;
by default repositories are loaded with the index file that can be
located on the .git folder in the filesystem.
671 672 673 674 |
# File 'ext/rugged/rugged_repo.c', line 671
static VALUE rb_git_repo_set_index(VALUE self, VALUE rb_data)
{
RB_GIT_REPO_OWNED_SET(rb_cRuggedIndex, index);
}
|
#inspect ⇒ Object
Pretty formatting of a Repository.
Returns a very pretty String.
14 15 16 |
# File 'lib/rugged/repository.rb', line 14 def inspect "#<Rugged::Repository:#{object_id} {path: #{path.inspect}}>" end |
#last_commit ⇒ Object
Get the most recent commit from this repo.
Returns a Rugged::Commit object.
21 22 23 |
# File 'lib/rugged/repository.rb', line 21 def last_commit self.head.target end |
#lookup(oid) ⇒ Object
Look up a SHA1.
Returns one of the four classes that inherit from Rugged::Object.
146 147 148 |
# File 'lib/rugged/repository.rb', line 146 def lookup(oid) Rugged::Object.lookup(self, oid) end |
#merge_analysis(their_commit) ⇒ Array
Analyzes the given commit and determines the opportunities for merging it into the repository's HEAD. Returns an Array containing a combination of the following symbols:
:normal ::
A "normal" merge is possible, both HEAD and the given commit have
diverged from their common ancestor. The divergent commits must be
merged.
:up_to_date ::
The given commit is reachable from HEAD, meaning HEAD is up-to-date
and no merge needs to be performed.
:fastforward ::
The given commit is a fast-forward from HEAD and no merge needs to be
performed. HEAD can simply be set to the given commit.
:unborn ::
The HEAD of the current repository is "unborn" and does not point to
a valid commit. No merge can be performed, but the caller may wish
to simply set HEAD to the given commit.
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 |
# File 'ext/rugged/rugged_repo.c', line 904
static VALUE rb_git_repo_merge_analysis(int argc, VALUE *argv, VALUE self)
{
int error;
git_repository *repo;
git_commit *their_commit;
git_annotated_commit *annotated_commit;
git_merge_analysis_t analysis;
git_merge_preference_t preference;
VALUE rb_their_commit, result;
rb_scan_args(argc, argv, "10", &rb_their_commit);
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
if (TYPE(rb_their_commit) == T_STRING) {
rb_their_commit = rugged_object_rev_parse(self, rb_their_commit, 1);
}
if (!rb_obj_is_kind_of(rb_their_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
TypedData_Get_Struct(rb_their_commit, git_commit, &rugged_object_type, their_commit);
error = git_annotated_commit_lookup(&annotated_commit, repo, git_commit_id(their_commit));
rugged_exception_check(error);
error = git_merge_analysis(&analysis, &preference, repo,
/* hack as we currently only do one commit */
(const git_annotated_commit **) &annotated_commit, 1);
git_annotated_commit_free(annotated_commit);
rugged_exception_check(error);
result = rb_ary_new();
if (analysis & GIT_MERGE_ANALYSIS_NORMAL)
rb_ary_push(result, CSTR2SYM("normal"));
if (analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
rb_ary_push(result, CSTR2SYM("up_to_date"));
if (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
rb_ary_push(result, CSTR2SYM("fastforward"));
if (analysis & GIT_MERGE_ANALYSIS_UNBORN)
rb_ary_push(result, CSTR2SYM("unborn"));
return result;
}
|
#merge_base(oid1, oid2, ...) ⇒ Object #merge_base(ref1, ref2, ...) ⇒ Object #merge_base(commit1, commit2, ...) ⇒ Object
Find a merge base, given two or more commits or oids. Returns nil if a merge base is not found.
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 |
# File 'ext/rugged/rugged_repo.c', line 794
static VALUE rb_git_repo_merge_base(VALUE self, VALUE rb_args)
{
int error = GIT_OK, i;
git_repository *repo;
git_oid base, *input_array = xmalloc(sizeof(git_oid) * RARRAY_LEN(rb_args));
int len = (int)RARRAY_LEN(rb_args);
if (len < 2)
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", len);
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
for (i = 0; !error && i < len; ++i) {
error = rugged_oid_get(&input_array[i], repo, rb_ary_entry(rb_args, i));
}
if (error) {
xfree(input_array);
rugged_exception_check(error);
}
error = git_merge_base_many(&base, repo, len, input_array);
xfree(input_array);
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
return rugged_create_oid(&base);
}
|
#merge_bases(oid1, oid2, ...) ⇒ Array #merge_bases(ref1, ref2, ...) ⇒ Array #merge_bases(commit1, commit2, ...) ⇒ Array
Find all merge bases, given two or more commits or oids. Returns an empty array if no merge bases are found.
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
# File 'ext/rugged/rugged_repo.c', line 835
static VALUE rb_git_repo_merge_bases(VALUE self, VALUE rb_args)
{
int error = GIT_OK;
size_t i, len = (size_t)RARRAY_LEN(rb_args);
git_repository *repo;
git_oidarray bases = {NULL, 0};
git_oid *input_array;
VALUE rb_bases;
if (len < 2)
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2+)", RARRAY_LEN(rb_args));
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
input_array = xmalloc(sizeof(git_oid) * len);
for (i = 0; !error && i < len; ++i) {
error = rugged_oid_get(&input_array[i], repo, rb_ary_entry(rb_args, i));
}
if (error) {
xfree(input_array);
rugged_exception_check(error);
}
error = git_merge_bases_many(&bases, repo, len, input_array);
xfree(input_array);
if (error != GIT_ENOTFOUND)
rugged_exception_check(error);
rb_bases = rb_ary_new2(bases.count);
for (i = 0; i < bases.count; ++i) {
rb_ary_push(rb_bases, rugged_create_oid(&bases.ids[i]));
}
git_oidarray_free(&bases);
return rb_bases;
}
|
#merge_commits(our_commit, their_commit, options = {}) ⇒ Object
Merges the two given commits, returning a Rugged::Index that reflects the result of the merge.
our_commit and their_commit can either be Rugged::Commit objects,
or OIDs resolving to the former.
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'ext/rugged/rugged_repo.c', line 1079
static VALUE rb_git_repo_merge_commits(int argc, VALUE *argv, VALUE self)
{
VALUE rb_our_commit, rb_their_commit, rb_options;
git_commit *our_commit, *their_commit;
git_index *index;
git_repository *repo;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
int error;
rb_scan_args(argc, argv, "20:", &rb_our_commit, &rb_their_commit, &rb_options);
if (TYPE(rb_our_commit) == T_STRING) {
rb_our_commit = rugged_object_rev_parse(self, rb_our_commit, 1);
}
if (!rb_obj_is_kind_of(rb_our_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
if (TYPE(rb_their_commit) == T_STRING) {
rb_their_commit = rugged_object_rev_parse(self, rb_their_commit, 1);
}
if (!rb_obj_is_kind_of(rb_their_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
if (!NIL_P(rb_options)) {
Check_Type(rb_options, T_HASH);
rugged_parse_merge_options(&opts, rb_options);
}
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
TypedData_Get_Struct(rb_our_commit, git_commit, &rugged_object_type, our_commit);
TypedData_Get_Struct(rb_their_commit, git_commit, &rugged_object_type, their_commit);
error = git_merge_commits(&index, repo, our_commit, their_commit, &opts);
if (error == GIT_EMERGECONFLICT)
return Qnil;
rugged_exception_check(error);
return rugged_index_new(rb_cRuggedIndex, self, index);
}
|
#namespace ⇒ String
Returns the active namespace for the repository.
1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 |
# File 'ext/rugged/rugged_repo.c', line 1957
static VALUE rb_git_repo_get_namespace(VALUE self)
{
git_repository *repo;
const char *namespace;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
namespace = git_repository_get_namespace(repo);
return namespace ? rb_str_new_utf8(namespace) : Qnil;
}
|
#namespace=(new_namespace) ⇒ Object
Sets the active namespace for the repository. If set to nil, no namespace will be active.
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 |
# File 'ext/rugged/rugged_repo.c', line 1933
static VALUE rb_git_repo_set_namespace(VALUE self, VALUE rb_namespace)
{
git_repository *repo;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
if (!NIL_P(rb_namespace)) {
Check_Type(rb_namespace, T_STRING);
error = git_repository_set_namespace(repo, StringValueCStr(rb_namespace));
} else {
error = git_repository_set_namespace(repo, NULL);
}
rugged_exception_check(error);
return Qnil;
}
|
#path ⇒ Object
Return the full, normalized path to this repository. For non-bare repositories,
this is the path of the actual .git folder, not the working directory.
repo.path #=> "/home/foo/workthing/.git"
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 |
# File 'ext/rugged/rugged_repo.c', line 1558
static VALUE rb_git_repo_path(VALUE self)
{
git_repository *repo;
const char *path;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
path = git_repository_path(repo);
return path ? rb_str_new_utf8(path) : Qnil;
}
|
#path_ignored?(path) ⇒ Boolean
Return whether a path is ignored or not.
2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 |
# File 'ext/rugged/rugged_repo.c', line 2513
static VALUE rb_git_repo_is_path_ignored(VALUE self, VALUE rb_path) {
git_repository *repo;
const char *path;
int error;
int ignored;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
path = StringValueCStr(rb_path);
error = git_ignore_path_is_ignored(&ignored, repo, path);
rugged_exception_check(error);
return ignored ? Qtrue : Qfalse;
}
|
#push(remote_or_url, *args, **kwargs) ⇒ Object
Push a list of refspecs to the given remote.
refspecs - A list of refspecs that should be pushed to the remote.
Returns a hash containing the pushed refspecs as keys and
any error messages or nil as values.
266 267 268 269 270 271 272 |
# File 'lib/rugged/repository.rb', line 266 def push(remote_or_url, *args, **kwargs) unless remote_or_url.kind_of? Remote remote_or_url = remotes[remote_or_url] || remotes.create_anonymous(remote_or_url) end remote_or_url.push(*args, **kwargs) end |
#read(oid) ⇒ String
Read and return the raw data of the object identified by the given oid.
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 |
# File 'ext/rugged/rugged_repo.c', line 1166
static VALUE rb_git_repo_read(VALUE self, VALUE hex)
{
git_repository *repo;
git_oid oid;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
Check_Type(hex, T_STRING);
error = git_oid_fromstr(&oid, StringValueCStr(hex));
rugged_exception_check(error);
return rugged_raw_read(repo, &oid);
}
|
#read_header(oid) ⇒ Hash
Read and return the header information in +repo+'s ODB
for the object identified by the given oid.
Returns a Hash object with the following key/value pairs:
:type ::
A Symbol denoting the object's type. Possible values are:
+:tree+, +:blob+, +:commit+ or +:tag+.
:len ::
A Number representing the object's length, in bytes.
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 |
# File 'ext/rugged/rugged_repo.c', line 1196
static VALUE rb_git_repo_read_header(VALUE self, VALUE hex)
{
git_repository *repo;
git_oid oid;
git_odb *odb;
git_otype type;
size_t len;
VALUE rb_hash;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
Check_Type(hex, T_STRING);
error = git_oid_fromstr(&oid, StringValueCStr(hex));
rugged_exception_check(error);
error = git_repository_odb(&odb, repo);
rugged_exception_check(error);
error = git_odb_read_header(&len, &type, odb, &oid);
git_odb_free(odb);
rugged_exception_check(error);
rb_hash = rb_hash_new();
rb_hash_aset(rb_hash, CSTR2SYM("type"), CSTR2SYM(git_object_type2string(type)));
rb_hash_aset(rb_hash, CSTR2SYM("len"), INT2FIX(len));
return rb_hash;
}
|
#ref(ref_name) ⇒ Object
Look up a single reference by name.
Example:
repo.ref 'refs/heads/master'
# => #<Rugged::Reference:2199125780 {name: "refs/heads/master",
target: "25b5d3b40c4eadda8098172b26c68cf151109799"}>
Returns a Rugged::Reference.
173 174 175 |
# File 'lib/rugged/repository.rb', line 173 def ref(ref_name) references[ref_name] end |
#ref_names(glob = nil) ⇒ Object
185 186 187 |
# File 'lib/rugged/repository.rb', line 185 def ref_names(glob = nil) references.each_name(glob) end |
#references ⇒ Object
181 182 183 |
# File 'lib/rugged/repository.rb', line 181 def references @references ||= ReferenceCollection.new(self) end |
#refs(glob = nil) ⇒ Object
177 178 179 |
# File 'lib/rugged/repository.rb', line 177 def refs(glob = nil) references.each(glob) end |
#remotes ⇒ Object
All the remotes in the repository.
Returns a Rugged::RemoteCollection containing all the Rugged::Remote objects in the repository.
200 201 202 |
# File 'lib/rugged/repository.rb', line 200 def remotes @remotes ||= RemoteCollection.new(self) end |
#reset(target, reset_type) ⇒ nil
Sets the current head to the specified commit oid and optionally resets the index and working tree to match.
target: Rugged::Commit, Rugged::Tag or rev that resolves to a commit or tag objectreset_type::soft,:mixedor:hard
[:soft]
the head will be moved to the commit.
[:mixed]
will trigger a :soft reset, plus the index will be replaced
with the content of the commit tree.
[:hard]
will trigger a :mixed reset and the working directory will be
replaced with the content of the index. (Untracked and ignored files
will be left alone)
Examples:
repo.reset('origin/master', :hard) #=> nil
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 |
# File 'ext/rugged/rugged_repo.c', line 1839
static VALUE rb_git_repo_reset(VALUE self, VALUE rb_target, VALUE rb_reset_type)
{
git_repository *repo;
int reset_type;
git_object *target = NULL;
int error;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
reset_type = parse_reset_type(rb_reset_type);
target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
error = git_reset(repo, target, reset_type, NULL);
git_object_free(target);
rugged_exception_check(error);
return Qnil;
}
|
#reset_path(pathspecs, target = nil) ⇒ nil
Updates entries in the index from the target commit tree, matching
the given pathspecs.
Passing a nil target will result in removing
entries in the index matching the provided pathspecs.
pathspecs: list of pathspecs to operate on (+String+ orArrayofStringobjects)- +target+(optional): Rugged::Commit, Rugged::Tag or rev that resolves to a commit or tag object.
Examples:
reset_path(File.join('subdir','file.txt'), '441034f860c1d5d90e4188d11ae0d325176869a8') #=> nil
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 |
# File 'ext/rugged/rugged_repo.c', line 1876
static VALUE rb_git_repo_reset_path(int argc, VALUE *argv, VALUE self)
{
git_repository *repo;
git_object *target = NULL;
git_strarray pathspecs;
VALUE rb_target, rb_paths;
int error = 0;
pathspecs.strings = NULL;
pathspecs.count = 0;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
rb_scan_args(argc, argv, "11", &rb_paths, &rb_target);
rugged_rb_ary_to_strarray(rb_paths, &pathspecs);
if (!NIL_P(rb_target))
target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
error = git_reset_default(repo, target, &pathspecs);
xfree(pathspecs.strings);
git_object_free(target);
rugged_exception_check(error);
return Qnil;
}
|
#rev_parse(spec) ⇒ Object
Look up an object by a revision string.
Returns one of the four classes that inherit from Rugged::Object.
153 154 155 |
# File 'lib/rugged/repository.rb', line 153 def rev_parse(spec) Rugged::Object.rev_parse(self, spec) end |
#rev_parse_oid(spec) ⇒ Object
Look up an object by a revision string.
Returns the oid of the matched object as a String
160 161 162 |
# File 'lib/rugged/repository.rb', line 160 def rev_parse_oid(spec) Rugged::Object.rev_parse_oid(self, spec) end |
#revert_commit(revert_commit, our_commit, options = {}) ⇒ Object
Reverts the given commit against the given "our" commit, producing an index that reflects the result of the revert.
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 |
# File 'ext/rugged/rugged_repo.c', line 957
static VALUE rb_git_repo_revert_commit(int argc, VALUE *argv, VALUE self)
{
VALUE rb_revert_commit, rb_our_commit, rb_options;
git_commit *revert_commit, *our_commit;
git_index *index;
git_repository *repo;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
unsigned int mainline = 0;
int error;
rb_scan_args(argc, argv, "20:", &rb_revert_commit, &rb_our_commit, &rb_options);
if (TYPE(rb_revert_commit) == T_STRING)
rb_revert_commit = rugged_object_rev_parse(self, rb_revert_commit, 1);
if (TYPE(rb_our_commit) == T_STRING)
rb_our_commit = rugged_object_rev_parse(self, rb_our_commit, 1);
if (!rb_obj_is_kind_of(rb_revert_commit, rb_cRuggedCommit) ||
!rb_obj_is_kind_of(rb_our_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
if (!NIL_P(rb_options)) {
VALUE rb_mainline;
Check_Type(rb_options, T_HASH);
rugged_parse_merge_options(&opts, rb_options);
rb_mainline = rb_hash_aref(rb_options, CSTR2SYM("mainline"));
if (!NIL_P(rb_mainline)) {
Check_Type(rb_mainline, T_FIXNUM);
mainline = FIX2UINT(rb_mainline);
}
}
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
TypedData_Get_Struct(rb_revert_commit, git_commit, &rugged_object_type, revert_commit);
TypedData_Get_Struct(rb_our_commit, git_commit, &rugged_object_type, our_commit);
error = git_revert_commit(&index, repo, revert_commit, our_commit, mainline, &opts);
if (error == GIT_EMERGECONFLICT)
return Qnil;
rugged_exception_check(error);
return rugged_index_new(rb_cRuggedIndex, self, index);
}
|
#shallow? ⇒ Boolean
Return whether a repository is a shallow clone or not. A shallow clone has a truncated history and can not be cloned or fetched from, nor can be pushed from nor into it.
1464 1465 1466 1467 |
# File 'ext/rugged/rugged_repo.c', line 1464
static VALUE rb_git_repo_is_shallow(VALUE self)
{
RB_GIT_REPO_GETTER(is_shallow);
}
|
#status(file = nil, &block) ⇒ Object
call-seq:
repo.status { |file, status_data| block }
repo.status(path) -> status_data
Returns the status for one or more files in the working directory
of the repository. This is equivalent to the git status command.
The returned status_data is always an array containing one or more
status flags as Ruby symbols. Possible flags are:
:index_new: the file is new in the index:index_modified: the file has been modified in the index:index_deleted: the file has been deleted from the index:worktree_new: the file is new in the working directory:worktree_modified: the file has been modified in the working directory:worktree_deleted: the file has been deleted from the working directory
If a block is given, status information will be gathered for every
single file on the working dir. The block will be called with the
status data for each file.
repo.status { |file, status_data| puts "#{file} has status: #{status_data.inspect}" }
results in, for example:
src/diff.c has status: [:index_new, :worktree_new]
README has status: [:worktree_modified]
If a path is given instead, the function will return the status_data for
the file pointed to by path, or raise an exception if the path doesn't exist.
path must be relative to the repository's working directory.
repo.status('src/diff.c') #=> [:index_new, :worktree_new]
91 92 93 94 95 96 97 |
# File 'lib/rugged/repository.rb', line 91 def status(file = nil, &block) if file file_status file else each_status(&block) end end |
#submodules ⇒ Object
All the submodules in the repository
Returns a SubmoduleCollection containing Rugged::Submodule objects
214 215 216 |
# File 'lib/rugged/repository.rb', line 214 def submodules @submodules ||= SubmoduleCollection.new(self) end |
#tags ⇒ Object
All the tags in the repository.
Returns a TagCollection containing all the tags.
192 193 194 |
# File 'lib/rugged/repository.rb', line 192 def @tags ||= TagCollection.new(self) end |
#walk(from, sorting = Rugged::SORT_DATE, &block) ⇒ Object
Walks over a set of commits using Rugged::Walker.
from - The String SHA1 to push onto Walker to begin our walk. sorting - The sorting order of the commits, as defined in the README. block - A block that we pass into walker#each.
Returns nothing if called with a block, otherwise returns an instance of Enumerable::Enumerator containing Rugged::Commit objects.
136 137 138 139 140 141 |
# File 'lib/rugged/repository.rb', line 136 def walk(from, sorting=Rugged::SORT_DATE, &block) walker = Rugged::Walker.new(self) walker.sorting(sorting) walker.push(from) walker.each(&block) end |
#workdir ⇒ nil
Return the working directory for this repository, or nil if
the repository is bare.
repo1. #=> false
repo1.workdir #=> "/home/foo/workthing/"
repo2. #=> true
repo2.workdir #=> nil
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 |
# File 'ext/rugged/rugged_repo.c', line 1582
static VALUE rb_git_repo_workdir(VALUE self)
{
git_repository *repo;
const char *workdir;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
workdir = git_repository_workdir(repo);
return workdir ? rb_str_new_utf8(workdir) : Qnil;
}
|
#workdir=(path) ⇒ Object
Sets the working directory of repo to path. All internal
operations on repo that affect the working directory will
instead use path.
The workdir can be set on bare repositories to temporarily
turn them into normal repositories.
repo. #=> true
repo.workdir = "/tmp/workdir"
repo. #=> false
repo.checkout
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
# File 'ext/rugged/rugged_repo.c', line 1609
static VALUE rb_git_repo_set_workdir(VALUE self, VALUE rb_workdir)
{
git_repository *repo;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
Check_Type(rb_workdir, T_STRING);
rugged_exception_check(
git_repository_set_workdir(repo, StringValueCStr(rb_workdir), 0)
);
return Qnil;
}
|
#write(buffer, type) ⇒ Object
Write the data contained in the buffer string as a raw object of the
given type into the repository's object database.
type can be either :tag, :commit, :tree or :blob.
Returns the newly created object's oid.
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 |
# File 'ext/rugged/rugged_repo.c', line 1403
static VALUE rb_git_repo_write(VALUE self, VALUE rb_buffer, VALUE rub_type)
{
git_repository *repo;
git_odb_stream *stream;
git_odb *odb;
git_oid oid;
int error;
git_otype type;
TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
Check_Type(rb_buffer, T_STRING);
error = git_repository_odb(&odb, repo);
rugged_exception_check(error);
type = rugged_otype_get(rub_type);
error = git_odb_open_wstream(&stream, odb, RSTRING_LEN(rb_buffer), type);
git_odb_free(odb);
rugged_exception_check(error);
error = git_odb_stream_write(stream, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
if (!error)
error = git_odb_stream_finalize_write(&oid, stream);
git_odb_stream_free(stream);
rugged_exception_check(error);
return rugged_create_oid(&oid);
}
|