Skip to content

Commit c32ee0c

Browse files
committed
Now discover_repository returns None if repo not found
Issue #531
1 parent 3cc439c commit c32ee0c

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

CHANGELOG.rst

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
0.27.1 (unreleased)
2+
-------------------------
3+
4+
Breaking changes:
5+
6+
- Now ``discover_repository`` returns ``None`` if repository not found, instead
7+
of raising ``KeyError``
8+
`#531 <https://github.com/libgit2/pygit2/issues/531>`_
9+
10+
Other changes:
11+
12+
- New ``DiffLine.raw_content``
13+
`#610 <https://github.com/libgit2/pygit2/issues/610>`_
14+
15+
- Automatize wheels upload to pypi
16+
`#563 <https://github.com/libgit2/pygit2/issues/563>`_
17+
18+
119
0.27.0 (2018-03-30)
220
-------------------------
321

src/pygit2.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extern PyTypeObject WorktreeType;
7373
PyDoc_STRVAR(discover_repository__doc__,
7474
"discover_repository(path[, across_fs[, ceiling_dirs]]) -> str\n"
7575
"\n"
76-
"Look for a git repository and return its path.");
76+
"Look for a git repository and return its path. If not found returns None.");
7777

7878
PyObject *
7979
discover_repository(PyObject *self, PyObject *args)
@@ -90,6 +90,8 @@ discover_repository(PyObject *self, PyObject *args)
9090

9191
memset(&repo_path, 0, sizeof(git_buf));
9292
err = git_repository_discover(&repo_path, path, across_fs, ceiling_dirs);
93+
if (err == GIT_ENOTFOUND)
94+
Py_RETURN_NONE;
9395
if (err < 0)
9496
return Error_set_str(err, path);
9597

test/test_attributes.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,14 @@
2525
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2626
# Boston, MA 02110-1301, USA.
2727

28-
# Import from the future
28+
# The future
2929
from __future__ import absolute_import
3030
from __future__ import unicode_literals, print_function
3131

32-
# Import from the Standard Library
33-
import binascii
34-
import unittest
35-
import tempfile
36-
import os
37-
from os.path import join, realpath
38-
import sys
32+
# Standard Library
33+
from os.path import join
3934

40-
# Import from pygit2
41-
from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
42-
from pygit2 import init_repository, clone_repository, discover_repository
43-
from pygit2 import Oid, Reference, hashfile
44-
import pygit2
35+
# pygit2
4536
from . import utils
4637

4738
try:

test/test_repository.py

+3
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ def test_discover_repo(self):
511511
os.makedirs(subdir)
512512
self.assertEqual(repo.path, discover_repository(subdir))
513513

514+
def test_discover_repo_not_found(self):
515+
self.assertIsNone(discover_repository(tempfile.tempdir))
516+
514517

515518
class EmptyRepositoryTest(utils.EmptyRepoTestCase):
516519

0 commit comments

Comments
 (0)