Skip to content

Commit a033bb3

Browse files
committed
add raw_branch_name to pygit2.Branch
1 parent d2d6374 commit a033bb3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/branch.c

+18
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ Branch_branch_name__get__(Branch *self)
149149
return Error_set(err);
150150
}
151151

152+
PyDoc_STRVAR(Branch_raw_branch_name__doc__,
153+
"The name of the local or remote branch (bytes).");
154+
155+
PyObject *
156+
Branch_raw_branch_name__get__(Branch *self)
157+
{
158+
int err;
159+
const char *c_name;
160+
161+
CHECK_REFERENCE(self);
162+
163+
err = git_branch_name(&c_name, self->reference);
164+
if (err == GIT_OK)
165+
return PyBytes_FromString(c_name);
166+
else
167+
return Error_set(err);
168+
}
152169

153170
PyDoc_STRVAR(Branch_remote_name__doc__,
154171
"The name of the remote set to be the upstream of this branch.");
@@ -263,6 +280,7 @@ PyMethodDef Branch_methods[] = {
263280

264281
PyGetSetDef Branch_getseters[] = {
265282
GETTER(Branch, branch_name),
283+
GETTER(Branch, raw_branch_name),
266284
GETTER(Branch, remote_name),
267285
GETSET(Branch, upstream),
268286
GETTER(Branch, upstream_name),

test/test_branch.py

+2
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ def test_branch_name(self):
111111
branch = self.repo.branches.get('master')
112112
assert branch.branch_name == 'master'
113113
assert branch.name == 'refs/heads/master'
114+
assert branch.raw_branch_name == branch.branch_name.encode('utf-8')
114115

115116
branch = self.repo.branches.get('i18n')
116117
assert branch.branch_name == 'i18n'
117118
assert branch.name == 'refs/heads/i18n'
119+
assert branch.raw_branch_name == branch.branch_name.encode('utf-8')
118120

119121
def test_with_commit(self):
120122
branches = self.repo.branches.with_commit(EXCLUSIVE_MASTER_COMMIT)

0 commit comments

Comments
 (0)