libgit2 / libgit2/pygit2

RuntimeError if submodule has no branch

Open
#952 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.