Skip to content

Commit

Permalink
Repository: allow retrieving the default signature
Browse files Browse the repository at this point in the history
Make it easier to grab the default signature for a repository by adding
a getter at the Repository level.
  • Loading branch information
carlosmn committed Jan 19, 2014
1 parent dcc9051 commit bf26aaf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "branch.h"
#include "blame.h"
#include "mergeresult.h"
#include "signature.h"
#include <git2/odb_backend.h>

extern PyObject *GitError;
Expand Down Expand Up @@ -1324,6 +1325,19 @@ Repository_remotes__get__(Repository *self)
return (PyObject*) py_list;
}

PyDoc_STRVAR(Repository_default_signature__doc__, "Return the signature according to the repository's configuration");

PyObject *
Repository_default_signature__get__(Repository *self)
{
git_signature *sig;
int err;

if ((err = git_signature_default(&sig, self->repo)) < 0)
return Error_set(err);

return build_signature((Object*) self, sig, "utf-8");
}

PyDoc_STRVAR(Repository_checkout_head__doc__,
"checkout_head(strategy)\n"
Expand Down Expand Up @@ -1633,6 +1647,7 @@ PyGetSetDef Repository_getseters[] = {
GETTER(Repository, config),
GETTER(Repository, workdir),
GETTER(Repository, remotes),
GETTER(Repository, default_signature),
{NULL}
};

Expand Down
10 changes: 10 additions & 0 deletions test/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ def test_merge_already_something_in_index(self):
self.repo.index.add('inindex.txt')
self.assertRaises(pygit2.GitError, self.repo.merge, branch_oid)

class RepositorySignatureTest(utils.RepoTestCase):

def test_default_signature(self):
config = self.repo.config
config['user.name'] = 'Random J Hacker'
config['user.email'] ='[email protected]'

sig = self.repo.default_signature
self.assertEqual('Random J Hacker', sig.name)
self.assertEqual('[email protected]', sig.email)

class NewRepositoryTest(utils.NoRepoTestCase):

Expand Down

0 comments on commit bf26aaf

Please sign in to comment.