Skip to content

Git submodule fials if branch not present #1361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Imantsg opened this issue Apr 10, 2025 · 0 comments
Open

Git submodule fials if branch not present #1361

Imantsg opened this issue Apr 10, 2025 · 0 comments

Comments

@Imantsg
Copy link

Imantsg commented Apr 10, 2025

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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant