Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

git_submodule_update does not clone and throws assertion #4149

Copy link
Copy link
@Spotlight0xff

Description

@Spotlight0xff
Issue body actions

Hi all,

Libgit2 crashes (throws assertion) during the git_submodule_update function.
It may very well be that I don't use it correctly, as the documentation is not entirely exact in how to clone/add a submodule and I haven't found any examples either.

Reproduction steps

First a script to setup the environment and then the actual code.

script to setup the environment

setup script, first the submodule which should be later added and then the parent directory.
The submodule is set up in /tmp, because I want absolute paths.
setup.sh:

#!/bin/bash

# remove previous fixtures
# commented to not delete any stuff if you just copy and pasted it.
#rm -rf /tmp/sm_test
#rm -rf parent
pushd .

# setup submodule
mkdir /tmp/sm_test && cd /tmp/sm_test
git init .
touch sm_file
git add sm_file
git commit -m "initial commit in submodule"
cd ..

popd
pushd .


# setup parent repository
mkdir parent && cd parent
git init .
touch parent_file
git add parent_file
git commit -m "initial commit in parent"

popd

minimal code for the bug

bug.c:

#include <git2.h>

#include <assert.h>
#include <stdio.h>


int main(int argc, char *argv[])
{
  git_submodule* sm = NULL;
  git_repository* parent = NULL;
  int result = 0;

  git_libgit2_init();
  result = git_repository_open(&parent, "parent");
  assert(!result);

  result = git_submodule_add_setup(&sm, parent, "file:///tmp/sm_test", "sm_test", 0);
  assert(!result);

  result = git_submodule_update(sm, 1, NULL);
  assert(!result);

  result = git_submodule_add_finalize(sm);
  assert(!result);
  git_submodule_free(sm);
  git_repository_free(parent);
  git_libgit2_shutdown();
  return 0;
}

Then just compile and run the whole stuff:
gcc bug.c -o bug -lgit2 && ./setup.sh && ./bug

Expected behavior

The submodule should be cloned correctly and libgit2 shouldn't crash.
parent/sm_test should contain the cloned repository.

Actual behavior

The program crashes with the following

bug: /home/user/build/libgit2/src/object.c:122: git_object_lookup_prefix: Assertion `repo && object_out && id' failed.

(id is zero)

Version of libgit2 (release number or SHA1)

HEAD is at ba2bc4911d99e20f1060bb6767edab94fd5d97a6

Operating system(s) tested

$ uname -a
Linux arch_virt_pci_test 4.8.13-1-ARCH #1 SMP PREEMPT Fri Dec 9 07:24:34 CET 2016 x86_64 GNU/Linux

Further information

Backtrace

#0  0x00007ffff773a04f in raise () from /usr/lib/libc.so.6
#1  0x00007ffff773b47a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff7732ea7 in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007ffff7732f52 in __assert_fail () from /usr/lib/libc.so.6
#4  0x00007ffff7b1c095 in git_object_lookup_prefix (object_out=0x7fffffffdbd0, repo=0x72a0b0, id=0x0, len=40, type=GIT_OBJ_COMMIT)
    at /home/andre/build/libgit2/src/object.c:122
#5  0x00007ffff7b1c29e in git_object_lookup (object_out=0x7fffffffdbd0, repo=0x72a0b0, id=0x0, type=GIT_OBJ_COMMIT)
    at /home/andre/build/libgit2/src/object.c:198
#6  0x00007ffff7b66a22 in git_submodule_update (sm=0x72ab70, init=1, _update_options=0x0) at /home/andre/build/libgit2/src/submodule.c:1224
#7  0x000000000040093c in main (argc=1, argv=0x7fffffffdd28) at bug.c:20

Links to the corresponding lines:
git_object_lookup_prefix @ src/object.c:122: Link
git_object_lookup @ src/object.c:198: Link
git_submodule_update @ src/submodule.c:1224: Link

Directory contents after bug

$ ls parent/
parent_file sm_test
$ cat parent/.gitmodules
[submodule "sm_test"]
	path = sm_test
	url = file:///tmp/sm_test
$ ls parent/sm_test/
$ ls /tmp/sm_test/
sm_file

So, the directory is created (per add_setup), but the index is not cloned.

If you need further information, please ask.

Cheers,
Andre

Reactions are currently unavailable

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.