RuntimeError if submodule has no branch
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 408
- Avg merge
- 2d 57m
- Merged PRs (30d)
- 7
Description
If a submodule has been added without the --branch option, accessing the Submodule.branch property raises a RuntimeError:
❯❯❯ git init
Initialized empty Git repository in /tmp/gregoire/tmp.R3p5f9ZTwD/.git/
❯❯❯ git submodule add https://github.com/libgit2/pygit2.git pygit2 --branch=master
[...]
❯❯❯ python3 -c 'import pygit2; print(pygit2.Repository(".").lookup_submodule("pygit2").branch)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/gregoire/.local/lib/python3.7/site-packages/pygit2/submodule.py", line 80, in branch
return ffi.string(branch).decode('utf-8')
RuntimeError: cannot use string() on <cdata 'char *' NULL>
It works fine if --branch is added to git submodule add:
❯❯❯ git init
Initialized empty Git repository in /tmp/gregoire/tmp.R3p5f9ZTwD/.git/
❯❯❯ git submodule add https://github.com/libgit2/pygit2.git pygit2
[...]
❯❯❯ python3 -c 'import pygit2; print(pygit2.Repository(".").lookup_submodule("pygit2").branch)'
master
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 at the Submodule.branch property in pygit2/submodule.py, corresponding to the failing line shown in the report, and reproduce the case with a submodule added without --branch. Add regression coverage for that case and verify that accessing branch no longer raises the NULL cdata RuntimeError while matching the intended API behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100