Skip to content

Commit

Permalink
reference: add a shorthand property
Browse files Browse the repository at this point in the history
Add Reference.shorthand to make it simpler to present a human-readable
name for a particular reference.
  • Loading branch information
carlosmn committed Nov 2, 2013
1 parent 83f6412 commit 9da4d4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 9da4d4f

Please sign in to comment.