Class: Rugged::Branch
- Defined in:
- lib/rugged/branch.rb,
ext/rugged/rugged_branch.c
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#head? ⇒ Boolean
Returns
true
if the branch is pointed at byHEAD
,false
otherwise. -
#name ⇒ String
Returns the name of
branch
. -
#remote ⇒ Object
Get the remote the branch belongs to.
-
#remote_name ⇒ String
Get the name of the remote the branch belongs to.
-
#upstream ⇒ Object
Returns the remote tracking branch, or
nil
if the branch is remote or has no tracking branch. -
#upstream=(branch) ⇒ Object
Set the upstream configuration for a given local branch.
Methods inherited from Reference
#branch?, #canonical_name, #inspect, #log, #log?, #peel, #remote?, #resolve, #tag?, #target, #target_id, #type, valid_name?
Instance Method Details
#==(other) ⇒ Object
8 9 10 11 |
# File 'lib/rugged/branch.rb', line 8 def ==(other) other.instance_of?(Rugged::Branch) && other.canonical_name == self.canonical_name end |
#head? ⇒ Boolean
Returns true
if the branch is pointed at by HEAD
, false
otherwise.
27 28 29 30 31 32 |
# File 'ext/rugged/rugged_branch.c', line 27
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;
}
|
#name ⇒ String
Returns the name of branch
.
See Rugged::Reference#canonical_name if you need the fully qualified name of the underlying reference.
43 44 45 46 47 48 49 50 51 52 |
# File 'ext/rugged/rugged_branch.c', line 43
static VALUE rb_git_branch_name(VALUE self)
{
git_reference *branch;
const char *branch_name;
Data_Get_Struct(self, git_reference, branch);
rugged_exception_check(git_branch_name(&branch_name, branch));
return rb_str_new_utf8(branch_name);
}
|
#remote ⇒ Object
Get the remote the branch belongs to.
If the branch is remote returns the remote it belongs to. In case of local branch, it returns the remote of the branch it tracks or nil if there is no tracking branch.
19 20 21 22 |
# File 'lib/rugged/branch.rb', line 19 def remote remote_name = self.remote_name @owner.remotes[remote_name] if remote_name end |
#remote_name ⇒ String
Get the name of the remote the branch belongs to.
If branch
is a remote branch, the name of the remote it belongs to is returned. If branch
is a tracking branch, the name of the remote of the tracked branch is returned.
Otherwise, nil
is returned.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'ext/rugged/rugged_branch.c', line 84
static VALUE rb_git_branch_remote_name(VALUE self)
{
git_reference *branch, *remote_ref;
int error = 0;
Data_Get_Struct(self, git_reference, branch);
if (git_reference_is_remote(branch)) {
remote_ref = branch;
} else {
error = git_branch_upstream(&remote_ref, branch);
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
}
return rb_git_branch__remote_name(
rugged_owner(self),
git_reference_name(remote_ref));
}
|
#upstream ⇒ Object
Returns the remote tracking branch, or nil
if the branch is remote or has no tracking branch.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'ext/rugged/rugged_branch.c', line 114
static VALUE rb_git_branch_upstream(VALUE self)
{
git_reference *branch, *upstream_branch;
int error;
Data_Get_Struct(self, git_reference, branch);
if (git_reference_is_remote(branch))
return Qnil;
error = git_branch_upstream(&upstream_branch, branch);
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
return rugged_branch_new(rugged_owner(self), upstream_branch);
}
|
#upstream=(branch) ⇒ Object
Set the upstream configuration for a given local branch.
Takes a local or remote Rugged::Branch instance or a Rugged::Reference pointing to a branch.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'ext/rugged/rugged_branch.c', line 143
static VALUE rb_git_branch_set_upstream(VALUE self, VALUE rb_branch)
{
git_reference *branch, *target_branch;
const char *target_branch_name;
Data_Get_Struct(self, git_reference, branch);
if (!NIL_P(rb_branch)) {
if (!rb_obj_is_kind_of(rb_branch, rb_cRuggedReference))
rb_raise(rb_eTypeError, "Expecting a Rugged::Reference instance");
Data_Get_Struct(rb_branch, git_reference, target_branch);
rugged_exception_check(
git_branch_name(&target_branch_name, target_branch)
);
} else {
target_branch_name = NULL;
}
rugged_exception_check(
git_branch_set_upstream(branch, target_branch_name)
);
return rb_branch;
}
|