Skip to content

Commit db91340

Browse files
committed
Don't raise RuntimeError if git_submodule_url returns NULL
1 parent 7bed9d2 commit db91340

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pygit2/submodules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .enums import SubmoduleIgnore, SubmoduleStatus
3232
from .errors import check_error
3333
from .ffi import ffi, C
34-
from .utils import to_bytes
34+
from .utils import to_bytes, maybe_string
3535

3636
# Need BaseRepository for type hints, but don't let it cause a circular dependency
3737
if TYPE_CHECKING:
@@ -129,10 +129,10 @@ def path(self):
129129
return ffi.string(path).decode('utf-8')
130130

131131
@property
132-
def url(self):
132+
def url(self) -> Union[str, None]:
133133
"""URL of the submodule."""
134134
url = C.git_submodule_url(self._subm)
135-
return ffi.string(url).decode('utf-8')
135+
return maybe_string(url)
136136

137137
@property
138138
def branch(self):

test/test_submodule.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ def test_url(repo):
106106
assert SUBM_URL == s.url
107107

108108

109+
def test_missing_url(repo):
110+
# Remove "url" from .gitmodules
111+
with open(Path(repo.workdir, '.gitmodules'), 'wt') as f:
112+
f.write('[submodule "TestGitRepository"]\n')
113+
f.write('\tpath = TestGitRepository\n')
114+
s = repo.submodules[SUBM_PATH]
115+
assert not s.url
116+
117+
109118
@utils.requires_network
110119
def test_init_and_update(repo):
111120
subrepo_file_path = Path(repo.workdir) / SUBM_PATH / 'master.txt'

0 commit comments

Comments
 (0)