libgit2 / libgit2/pygit2

checking to see if diffFile is a submodule.

Open
#838 0 comments 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

Is there a way to check to see if a diffFile is a submodule?

The repo that I'm getting my diff deltas from is bare so there's no working directory for Repository.lookup_submodule(path) or Repository.listall_submodules() to work with.

The main issue is when I try to get an added file via something like:

new_file = git_repo[delta.new_file.id]

I get the following key error.

Traceback (most recent call last):
  File "/Users/user/project/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/Users/user/project/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/user/project/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/user/project/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/user/project/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/user/project/repos/views.py", line 105, in get
    new_file = git_repo[delta.new_file.id]
  File "/Users/user/project/venv/lib/python3.7/site-packages/pygit2/repository.py", line 121, in __getitem__
    raise KeyError(key)
KeyError: ffeef8955335d0ec95f23c2fd75821672cf14bb9

If it's a submodule I don't need the contents. I just need to know that it's a submodule. Is there a general way to do this?

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 by reading the handling around delta.new_file.id and the Repository.lookup_submodule(path) and Repository.listall_submodules() APIs, especially for bare repositories. Check how a diff entry identifies a submodule without loading its contents. Done means documenting or exposing a reliable way to distinguish submodule entries before indexing the repository.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.