Skip to content

git_submodule_foreach() fails for certain submodules names #6580

@jeroen

Description

@jeroen

For certain repos git_submodule_foreach seems to not work without any reason or error.

I can't narrow down what causes this; it happens for .gitmodules, for example certain names with a dot icw/ shallow = true. Below an example.

Reproduction steps

For example this program:

#include <string.h>
#include <stdio.h>
#include <git2.h>

static int submodule_count(git_submodule *submod, const char *name, void *payload){
  int *count = payload;
  printf("Found submodule %s\n", git_submodule_name(submod));
  *count = (*count) + 1;
  return 0;
}

int main(int argc, char *argv[]) {
  git_repository *repo = NULL;
  git_libgit2_init();
  int err = git_repository_open(&repo, ".");
  if(err){
    const git_error *info = giterr_last();
    printf("Failure in git_repository_open: %s\n", info->message);
    return 1;
  }
  int n = 0;
  git_submodule_foreach(repo, submodule_count, &n);
  printf("This function has %d submodules\n", n);
  return 0;
}

Alternatively you can use the libgit2 example app: libgit2/examples/a.out status --list-submodules on that same repo.

Expected behavior

We iterate over the submodules.

Actual behavior

No submodules are listed.

Version of libgit2 (release number or SHA1)

1.6.4

Operating system(s) tested

MacOS, Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions