Title: git_submodule_update does not clone and throws assertion · Issue #4149 · libgit2/libgit2 · GitHub
Open Graph Title: git_submodule_update does not clone and throws assertion · Issue #4149 · libgit2/libgit2
X Title: git_submodule_update does not clone and throws assertion · Issue #4149 · libgit2/libgit2
Description: 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 ex...
Open Graph Description: 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/ad...
X Description: 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 clon...
Opengraph URL: https://github.com/libgit2/libgit2/issues/4149
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"git_submodule_update does not clone and throws assertion","articleBody":"Hi all,\r\n\r\nLibgit2 crashes (throws assertion) during the `git_submodule_update` function.\r\nIt 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.\r\n\r\n\r\n\r\n### Reproduction steps\r\n\r\nFirst a script to setup the environment and then the actual code.\r\n\r\n#### script to setup the environment\r\nsetup script, first the submodule which should be later added and then the parent directory.\r\nThe submodule is set up in `/tmp`, because I want absolute paths.\r\n`setup.sh`:\r\n```\r\n#!/bin/bash\r\n\r\n# remove previous fixtures\r\n# commented to not delete any stuff if you just copy and pasted it.\r\n#rm -rf /tmp/sm_test\r\n#rm -rf parent\r\npushd .\r\n\r\n# setup submodule\r\nmkdir /tmp/sm_test \u0026\u0026 cd /tmp/sm_test\r\ngit init .\r\ntouch sm_file\r\ngit add sm_file\r\ngit commit -m \"initial commit in submodule\"\r\ncd ..\r\n\r\npopd\r\npushd .\r\n\r\n\r\n# setup parent repository\r\nmkdir parent \u0026\u0026 cd parent\r\ngit init .\r\ntouch parent_file\r\ngit add parent_file\r\ngit commit -m \"initial commit in parent\"\r\n\r\npopd\r\n```\r\n\r\n#### minimal code for the bug\r\n`bug.c`:\r\n```\r\n#include \u003cgit2.h\u003e\r\n\r\n#include \u003cassert.h\u003e\r\n#include \u003cstdio.h\u003e\r\n\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n git_submodule* sm = NULL;\r\n git_repository* parent = NULL;\r\n int result = 0;\r\n\r\n git_libgit2_init();\r\n result = git_repository_open(\u0026parent, \"parent\");\r\n assert(!result);\r\n\r\n result = git_submodule_add_setup(\u0026sm, parent, \"file:///tmp/sm_test\", \"sm_test\", 0);\r\n assert(!result);\r\n\r\n result = git_submodule_update(sm, 1, NULL);\r\n assert(!result);\r\n\r\n result = git_submodule_add_finalize(sm);\r\n assert(!result);\r\n git_submodule_free(sm);\r\n git_repository_free(parent);\r\n git_libgit2_shutdown();\r\n return 0;\r\n}\r\n```\r\n\r\nThen just compile and run the whole stuff:\r\n`gcc bug.c -o bug -lgit2 \u0026\u0026 ./setup.sh \u0026\u0026 ./bug`\r\n\r\n### Expected behavior\r\nThe submodule should be cloned correctly and libgit2 shouldn't crash.\r\n`parent/sm_test` should contain the cloned repository.\r\n\r\n### Actual behavior\r\nThe program crashes with the following \r\n```\r\nbug: /home/user/build/libgit2/src/object.c:122: git_object_lookup_prefix: Assertion `repo \u0026\u0026 object_out \u0026\u0026 id' failed.\r\n```\r\n(id is zero)\r\n\r\n\r\n### Version of libgit2 (release number or SHA1)\r\nHEAD is at `ba2bc4911d99e20f1060bb6767edab94fd5d97a6`\r\n\r\n\r\n### Operating system(s) tested\r\n```\r\n$ uname -a\r\nLinux arch_virt_pci_test 4.8.13-1-ARCH #1 SMP PREEMPT Fri Dec 9 07:24:34 CET 2016 x86_64 GNU/Linux\r\n```\r\n\r\n### Further information\r\n#### Backtrace\r\n```\r\n#0 0x00007ffff773a04f in raise () from /usr/lib/libc.so.6\r\n#1 0x00007ffff773b47a in abort () from /usr/lib/libc.so.6\r\n#2 0x00007ffff7732ea7 in __assert_fail_base () from /usr/lib/libc.so.6\r\n#3 0x00007ffff7732f52 in __assert_fail () from /usr/lib/libc.so.6\r\n#4 0x00007ffff7b1c095 in git_object_lookup_prefix (object_out=0x7fffffffdbd0, repo=0x72a0b0, id=0x0, len=40, type=GIT_OBJ_COMMIT)\r\n at /home/andre/build/libgit2/src/object.c:122\r\n#5 0x00007ffff7b1c29e in git_object_lookup (object_out=0x7fffffffdbd0, repo=0x72a0b0, id=0x0, type=GIT_OBJ_COMMIT)\r\n at /home/andre/build/libgit2/src/object.c:198\r\n#6 0x00007ffff7b66a22 in git_submodule_update (sm=0x72ab70, init=1, _update_options=0x0) at /home/andre/build/libgit2/src/submodule.c:1224\r\n#7 0x000000000040093c in main (argc=1, argv=0x7fffffffdd28) at bug.c:20\r\n\r\n```\r\n\r\nLinks to the corresponding lines:\r\n`git_object_lookup_prefix @ src/object.c:122`: [Link](https://github.com/libgit2/libgit2/blob/ba2bc4911d99e20f1060bb6767edab94fd5d97a6/src/object.c#L122)\r\n`git_object_lookup @ src/object.c:198`: [Link](https://github.com/libgit2/libgit2/blob/ba2bc4911d99e20f1060bb6767edab94fd5d97a6/src/object.c#L198)\r\n`git_submodule_update @ src/submodule.c:1224`: [Link](https://github.com/libgit2/libgit2/blob/ba2bc4911d99e20f1060bb6767edab94fd5d97a6/src/submodule.c#L1224)\r\n\r\n#### Directory contents after bug\r\n```\r\n$ ls parent/\r\nparent_file sm_test\r\n$ cat parent/.gitmodules\r\n[submodule \"sm_test\"]\r\n\tpath = sm_test\r\n\turl = file:///tmp/sm_test\r\n$ ls parent/sm_test/\r\n$ ls /tmp/sm_test/\r\nsm_file\r\n```\r\n\r\nSo, the directory is created (per add_setup), but the index is not cloned.\r\n\r\nIf you need further information, please ask.\r\n\r\nCheers,\r\nAndre","author":{"url":"https://github.com/Spotlight0xff","@type":"Person","name":"Spotlight0xff"},"datePublished":"2017-03-02T15:34:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/4149/libgit2/issues/4149"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:184400ef-67fe-c13f-9320-0e372b1cb383 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A5DE:1F68DB:5D6172B:7D95823:6A5DEDFE |
| html-safe-nonce | bb8b026609fcca5380eb5daf49454f6eec84d1dca3f421a2da0b1f3adc24326b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNURFOjFGNjhEQjo1RDYxNzJCOjdEOTU4MjM6NkE1REVERkUiLCJ2aXNpdG9yX2lkIjoiNTE4ODExMTIxODc3NjA3NTc3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e8cef4be4a5e7390fb83fb64d3a7751656c1b1c50f3064022104d73d7c8c4f45 |
| hovercard-subject-tag | issue:211426581 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/libgit2/libgit2/4149/issue_layout |
| twitter:image | https://opengraph.githubassets.com/31a1c8db9a3562ab007a687e87d42c31773e0fd39e13de1023a82f3d2085befe/libgit2/libgit2/issues/4149 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/31a1c8db9a3562ab007a687e87d42c31773e0fd39e13de1023a82f3d2085befe/libgit2/libgit2/issues/4149 |
| og:image:alt | 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/ad... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Spotlight0xff |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8e8f322dc74b1a8d5bafb296008dbb96bb4a0bc6ee2d6f30844ab111697c520d |
| turbo-cache-control | no-preview |
| go-import | github.com/libgit2/libgit2 git https://github.com/libgit2/libgit2.git |
| octolytics-dimension-user_id | 394745 |
| octolytics-dimension-user_login | libgit2 |
| octolytics-dimension-repository_id | 901662 |
| octolytics-dimension-repository_nwo | libgit2/libgit2 |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 901662 |
| octolytics-dimension-repository_network_root_nwo | libgit2/libgit2 |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7ae00b343090b49d0d18b8184187f51a39ed917c |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width