Git submodule fials if branch not present
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 408
- Avg merge
- 2d 57m
- Merged PRs (30d)
- 7
Description
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')
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pygit2/submodules.py at the Submodule.branch property and inspect how C.git_submodule_branch returns an unset branch. Verify the behavior for a submodule without a configured branch and confirm that accessing the property no longer raises the reported NULL cdata RuntimeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100