fix submodule lookup in bare repos
git_submodule_lookup does not work without a working tree [1], so the current approach fails to recognize any submodules in bare repos. Instead, notice that $ git ls-tree HEAD lists any submodules as commit objects regardless of a working tree. This is the only instance commit object is used in a tree, so we will use this to check for submodules. [1]: https://github.com/libgit2/libgit2/pull/4305/files
1 files changed, 2 insertions(+), 3 deletions(-) | |||
---|---|---|---|
M | stagit.c | +2 | -3 |
1@@ -976,7 +976,6 @@ int
2 writefilestree(FILE *fp, git_tree *tree, const char *path)
3 {
4 const git_tree_entry *entry = NULL;
5- git_submodule *module = NULL;
6 git_object *obj = NULL;
7 git_off_t filesize;
8 const char *entryname;
9@@ -1029,11 +1028,11 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
10 fprintf(fp, "%juB", (uintmax_t)filesize);
11 fputs("</td></tr>\n", fp);
12 git_object_free(obj);
13- } else if (!git_submodule_lookup(&module, repo, entryname)) {
14+ } else if (git_tree_entry_type(entry) == GIT_OBJ_COMMIT) {
15+ /* commit object in tree is a submodule */
16 fprintf(fp, "<tr><td>m---------</td><td><a href=\"%sfile/.gitmodules.html\">",
17 relpath);
18 xmlencode(fp, entrypath, strlen(entrypath));
19- git_submodule_free(module);
20 fputs("</a></td><td class=\"num\" align=\"right\"></td></tr>\n", fp);
21 }
22 }