Skip to content

Git submodule fials if branch not present #1361

Open
@Imantsg

Description

@Imantsg

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')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions