pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

Git submodule fials if branch not present

Open Imantsg opened this issue 9 months ago • 0 comments

In case if I want to check if branch was provided to submodule and it is not provided I got error

  if sm.branch:
      name = f"{sm.branch}/{sm.name}"
  else:
      name = f"{sm.name}"

File "/app/venv/lib/python3.11/site-packages/pygit2/submodules.py", line 148, in branch return ffi.string(branch).decode('utf-8') ^^^^^^^^^^^^^^^^^^ RuntimeError: cannot use string() on <cdata 'char *' NULL>

It looks like there is missing check if branch is actually set

class Submodule: ...

@property
def branch(self):
    """Branch that is to be tracked by the submodule."""
    branch = C.git_submodule_branch(self._subm)
    return ffi.string(branch).decode('utf-8')

I think it should be like this

@property
def branch(self):
    """Branch that is to be tracked by the submodule."""
    branch = C.git_submodule_branch(self._subm)
    if branch:
        return ffi.string(branch).decode('utf-8')

Imantsg avatar Apr 10 '25 10:04 Imantsg