class Rugged::Branch

Public Instance Methods

==(other) click to toggle source
# File lib/rugged/branch.rb, line 8
def ==(other)
  other.instance_of?(Rugged::Branch) &&
    other.canonical_name == self.canonical_name
end
head? → true or false click to toggle source

Returns true if the branch is pointed at by HEAD, false otherwise.

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 click to toggle source

Returns the name of branch.

See Rugged::Reference#canonical_name if you need the fully qualified name of the underlying reference.

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() click to toggle source

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.

# 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 click to toggle source

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.

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 → branch click to toggle source

Returns the remote tracking branch, or nil if the branch is remote or has no tracking branch.

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 click to toggle source

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.

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;
}