Class: Rugged::Branch
- Inherits:
-
RuggedReference
- Object
- RuggedReference
- 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.
Instance Method Details
#==(other) ⇒ Object
3 4 5 6 |
# File 'lib/rugged/branch.rb', line 3 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.
44 45 46 47 48 49 |
# File 'ext/rugged/rugged_branch.c', line 44
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.
60 61 62 63 64 65 66 67 68 69 |
# File 'ext/rugged/rugged_branch.c', line 60
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.
14 15 16 17 |
# File 'lib/rugged/branch.rb', line 14 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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'ext/rugged/rugged_branch.c', line 101
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.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'ext/rugged/rugged_branch.c', line 131
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.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/rugged/rugged_branch.c', line 160
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;
}
|