Class: Rugged::Branch
- Inherits:
-
RuggedReference
- Object
- RuggedReference
- Rugged::Branch
- Defined in:
- lib/rugged/branch.rb,
ext/rugged/rugged_branch.c
Class Method Summary collapse
-
.create(repository, name, target, force = false) ⇒ Object
Create a new branch in
repository
, with the givenname
, and pointing to thetarget
. -
.each(*args) ⇒ Object
Iterate through the branches in
repository
. -
.each_name(*args) ⇒ Object
Iterate through the names of the branches in
repository
. -
.lookup(repository, name, branch_type = :local) ⇒ Object
Lookup a branch in
repository
, with the givenname
.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#canonical_name ⇒ Object
The full name of the branch, as a fully-qualified reference path.
-
#delete! ⇒ nil
Remove a branch from the repository.
-
#head? ⇒ Boolean
Returns
true
if the branch is pointed at byHEAD
,false
otherwise. -
#move(*args) ⇒ Object
Rename a branch to
new_name
. -
#name ⇒ Object
The name of the branch, without a fully-qualified reference path.
-
#rename(*args) ⇒ Object
Rename a branch to
new_name
. -
#tip ⇒ Object
The object pointed at by the tip of this branch.
Class Method Details
.create(repository, name, target, force = false) ⇒ Object
Create a new branch in repository
, with the given name
, and pointing to the target
.
name
needs to be a branch name, not an absolute reference path (e.g. development
instead of /refs/heads/development
).
target
needs to be an existing commit in the given repository
.
If force
is true
, any existing branches will be overwritten.
Returns a Rugged::Branch object with the newly created branch.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'ext/rugged/rugged_branch.c', line 71
static VALUE rb_git_branch_create(int argc, VALUE *argv, VALUE self)
{
git_reference *branch;
git_commit *target = NULL;
git_repository *repo = NULL;
int error, force = 0;
VALUE rb_repo, rb_name, rb_target, rb_force;
rb_scan_args(argc, argv, "31", &rb_repo, &rb_name, &rb_target, &rb_force);
if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo)) {
rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
}
Data_Get_Struct(rb_repo, git_repository, repo);
Check_Type(rb_name, T_STRING);
target = (git_commit *)rugged_object_get(repo, rb_target, GIT_OBJ_COMMIT);
if (!NIL_P(rb_force)) {
force = rugged_parse_bool(rb_force);
}
error = git_branch_create(&branch, repo, StringValueCStr(rb_name), target, force);
git_commit_free(target);
rugged_exception_check(error);
return rugged_branch_new(rb_repo, branch);
}
|
.each(repository, filter = :all) {|branch| ... } ⇒ Object .each(repository, filter = :all) ⇒ Object
Iterate through the branches in repository
. Iteration can be optionally filtered to yield only :local
or :remote
branches.
The given block will be called once with a Rugged::Branch
object for each branch in the repository. If no block is given, an enumerator will be returned.
262 263 264 265 |
# File 'ext/rugged/rugged_branch.c', line 262
static VALUE rb_git_branch_each(int argc, VALUE *argv, VALUE self)
{
return each_branch(argc, argv, self, 0);
}
|
.each_name(repository, filter = :all) {|branch_name| ... } ⇒ Object .each_name(repository, filter = :all) ⇒ Object
Iterate through the names of the branches in repository
. Iteration can be optionally filtered to yield only :local
or :remote
branches.
The given block will be called once with the name of each branch as a String
. If no block is given, an enumerator will be returned.
244 245 246 247 |
# File 'ext/rugged/rugged_branch.c', line 244
static VALUE rb_git_branch_each_name(int argc, VALUE *argv, VALUE self)
{
return each_branch(argc, argv, self, 1);
}
|
.lookup(repository, name, branch_type = :local) ⇒ Object
Lookup a branch in repository
, with the given name
.
name
needs to be a branch name, not an absolute reference path (e.g. development
instead of /refs/heads/development
).
branch_type
specifies whether the looked up branch is a local branch or a remote one. It defaults to looking up local branches.
Returns the looked up branch, or nil
if the branch doesn’t exist.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'ext/rugged/rugged_branch.c', line 118
static VALUE rb_git_branch_lookup(int argc, VALUE *argv, VALUE self)
{
git_reference *branch;
git_repository *repo;
VALUE rb_repo, rb_name, rb_type;
int error;
int branch_type = GIT_BRANCH_LOCAL;
rb_scan_args(argc, argv, "21", &rb_repo, &rb_name, &rb_type);
if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo)) {
rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
}
Data_Get_Struct(rb_repo, git_repository, repo);
Check_Type(rb_name, T_STRING);
if (!NIL_P(rb_type))
branch_type = parse_branch_type(rb_type);
error = git_branch_lookup(&branch, repo, StringValueCStr(rb_name), branch_type);
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
return rugged_branch_new(rb_repo, branch);
}
|
Instance Method Details
#==(other) ⇒ Object
9 10 11 12 |
# File 'lib/rugged/branch.rb', line 9 def ==(other) other.instance_of?(Rugged::Branch) && other.canonical_name == self.canonical_name end |
#canonical_name ⇒ Object
The full name of the branch, as a fully-qualified reference path.
This is the same as calling Reference#name for the reference behind the path
19 |
# File 'lib/rugged/branch.rb', line 19 alias_method 'canonical_name', 'name' |
#delete! ⇒ nil
Remove a branch from the repository. The branch object will become invalidated and won’t be able to be used for any other operations.
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'ext/rugged/rugged_branch.c', line 155
static VALUE rb_git_branch_delete(VALUE self)
{
git_reference *branch = NULL;
Data_Get_Struct(self, git_reference, branch);
rugged_exception_check(
git_branch_delete(branch)
);
return Qnil;
}
|
#head? ⇒ Boolean
Returns true
if the branch is pointed at by HEAD
, false
otherwise.
308 309 310 311 312 313 |
# File 'ext/rugged/rugged_branch.c', line 308
static VALUE rb_git_branch_head_p(VALUE self)
{
git_reference *branch;
Data_Get_Struct(self, git_reference, branch);
return git_branch_is_head(branch) ? Qtrue : Qfalse;
}
|
#move(new_name, force = false) ⇒ Object #rename(new_name, force = false) ⇒ Object
Rename a branch to new_name
.
new_name
needs to be a branch name, not an absolute reference path (e.g. development
instead of /refs/heads/development
).
If force
is true
, the branch will be renamed even if a branch with new_name
already exists.
A new Rugged::Branch object for the renamed branch will be returned.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'ext/rugged/rugged_branch.c', line 282
static VALUE rb_git_branch_move(int argc, VALUE *argv, VALUE self)
{
VALUE rb_new_branch_name, rb_force;
git_reference *old_branch = NULL, *new_branch = NULL;
int error, force = 0;
rb_scan_args(argc, argv, "11", &rb_new_branch_name, &rb_force);
Data_Get_Struct(self, git_reference, old_branch);
Check_Type(rb_new_branch_name, T_STRING);
if (!NIL_P(rb_force))
force = rugged_parse_bool(rb_force);
error = git_branch_move(&new_branch, old_branch, StringValueCStr(rb_new_branch_name), force);
rugged_exception_check(error);
return rugged_branch_new(rugged_owner(self), new_branch);
}
|
#name ⇒ Object
The name of the branch, without a fully-qualified reference path
E.g. ‘master’ instead of ‘refs/heads/master’
24 25 26 |
# File 'lib/rugged/branch.rb', line 24 def name super.gsub(%r{^(refs/heads/|refs/remotes/)}, '') end |
#move(new_name, force = false) ⇒ Object #rename(new_name, force = false) ⇒ Object
Rename a branch to new_name
.
new_name
needs to be a branch name, not an absolute reference path (e.g. development
instead of /refs/heads/development
).
If force
is true
, the branch will be renamed even if a branch with new_name
already exists.
A new Rugged::Branch object for the renamed branch will be returned.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'ext/rugged/rugged_branch.c', line 282
static VALUE rb_git_branch_move(int argc, VALUE *argv, VALUE self)
{
VALUE rb_new_branch_name, rb_force;
git_reference *old_branch = NULL, *new_branch = NULL;
int error, force = 0;
rb_scan_args(argc, argv, "11", &rb_new_branch_name, &rb_force);
Data_Get_Struct(self, git_reference, old_branch);
Check_Type(rb_new_branch_name, T_STRING);
if (!NIL_P(rb_force))
force = rugged_parse_bool(rb_force);
error = git_branch_move(&new_branch, old_branch, StringValueCStr(rb_new_branch_name), force);
rugged_exception_check(error);
return rugged_branch_new(rugged_owner(self), new_branch);
}
|
#tip ⇒ Object
The object pointed at by the tip of this branch
5 6 7 |
# File 'lib/rugged/branch.rb', line 5 def tip @owner.lookup(self.resolve.target) end |