Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ Reference_name__get__(Reference *self)
return to_path(git_reference_name(self->reference));
}

PyDoc_STRVAR(Reference_shorthand__doc__, "The shorthand \"human-readable\" name of the reference.");

PyObject *
Reference_shorthand__get__(Reference *self)
{
CHECK_REFERENCE(self);
return to_path(git_reference_shorthand(self->reference));
}

PyDoc_STRVAR(Reference_type__doc__,
"Type, either GIT_REF_OID or GIT_REF_SYMBOLIC.");
Expand Down Expand Up @@ -432,6 +440,7 @@ PyMethodDef Reference_methods[] = {

PyGetSetDef Reference_getseters[] = {
GETTER(Reference, name),
GETTER(Reference, shorthand),
GETSET(Reference, target),
GETTER(Reference, type),
{NULL}
Expand Down
5 changes: 5 additions & 0 deletions test/test_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def test_set_target(self):
reference.target = 'refs/heads/i18n'
self.assertEqual(reference.target, 'refs/heads/i18n')

def test_get_shorthand(self):
reference = self.repo.lookup_reference('refs/heads/master')
self.assertEqual(reference.shorthand, 'master')
reference = self.repo.create_reference('refs/remotes/origin/master', LAST_COMMIT)
self.assertEqual(reference.shorthand, 'origin/master')

def test_delete(self):
repo = self.repo
Expand Down