libgit2 / libgit2/libgit2sharp

Submodule project nested in submodule gives "Unable to locate repository ..."

未关闭
#1,683 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
C#
星标
3.5k
派生
925
PR 合并指标
30 天内没有已合并 PR

描述

Back link to https://github.com/dotnet/sourcelink/issues/276#issuecomment-489463618

repro, running this in a docker debian 9 (netcore sdk 2.2.203) container:

#idempotent script
rm -rf ~/repo ~/submodule

# setup dirs and submodule project 
mkdir -p ~/submodule/subdir && cd ~/submodule && git init && cd subdir && dotnet new classlib

# do submodule commit
git config user.email "you@example.com" && git config user.name "Your Name" && git add . && git commit -m "Initial commit"

#creat repo project 
mkdir -p ~/repo/src && cd ~/repo && git init && git submodule add ~/submodule submodule && cd src && dotnet new classlib && dotnet add reference ../submodule/subdir/subdir.csproj && cd -

# Add Directory.Build.props with SourceLink reference, so submodule will get it too.
echo -e '<Project>\n   <ItemGroup>\n     <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All" />\n   </ItemGroup>\n</Project>' > Directory.Build.props

dotnet build src

This is an strace capturing opens around when the target warns that it cannot locate the directory:

[pid  1280] open("/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/tools/netcoreapp2.0/Microsoft.Build.Tasks.Git.Operations.dll", O_RDONLY) = 119
[pid  1284] open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 120
[pid  1280] open("/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/tools/netcoreapp2.0/LibGit2Sharp.dll", O_RDONLY) = 120
[pid  1280] open("/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/build/../tools/netcoreapp2.0/runtimes/debian.9-x64/native/libgit2-a904fc6.so", O_RDONLY|O_CLOEXEC) = 118
[pid  1280] open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 118
[pid  1280] open("/usr/lib/x86_64-linux-gnu/libssl.so.1.1", O_RDONLY|O_CLOEXEC) = 118
[pid  1280] open("/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1", O_RDONLY|O_CLOEXEC) = 118
[pid  1284] open("/root/.dotnet/corefx/cryptography/x509stores/my", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 118
[pid  1284] open("/root/.dotnet/corefx/cryptography/x509stores/my/2A56A5C2C6A932EAA4B04ACB89C0B77D933D53F2.pfx", O_RDONLY) = 123
[pid  1280] open("/dev/urandom", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 124
[pid  1280] open("/usr/lib/ssl/cert.pem", O_RDONLY) = -1 ENOENT (No such file or directory)
/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/build/Microsoft.Build.Tasks.Git.targets(20,5): warning : Unable to locate repository containing directory '/repo/submodule/src'. [/repo/submodule/src/submodule.csproj]

This on the other hand is an strace around that same point after you run:

echo "gitdir: ../../.git/modules/submodule" > /repo/submodule/subdir/.git

[pid  1402] open("/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/tools/netcoreapp2.0/Microsoft.Build.Tasks.Git.dll", O_RDONLY) = 117
[pid  1402] open("/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/tools/netcoreapp2.0/Microsoft.Build.Tasks.Git.Operations.dll", O_RDONLY) = 108
[pid  1402] open("/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/tools/netcoreapp2.0/LibGit2Sharp.dll", O_RDONLY) = 119
[pid  1402] open("/root/.nuget/packages/microsoft.build.tasks.git/1.0.0-beta2-18618-05/build/../tools/netcoreapp2.0/runtimes/debian.9-x64/native/libgit2-a904fc6.so", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/usr/lib/x86_64-linux-gnu/libssl.so.1.1", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/dev/urandom", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 121
[pid  1402] open("/usr/lib/ssl/cert.pem", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid  1402] open("/repo/submodule/subdir/.git", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/HEAD", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/refs/heads/master", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/objects/pack/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/objects/1d/ecf60232961da48db8871270ab97b1acab642b", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121
[pid  1402] open("/repo/.git/modules/submodule/config", O_RDONLY|O_CLOEXEC) = 121

Notice the [pid 1402] open("/repo/submodule/subdir/.git", O_RDONLY|O_CLOEXEC) = 121 which is then followed by a lot of good opens to the actual git directory.

I fear something is going wrong in libgit2, possibly in find_repo https://github.com/libgit2/libgit2/blob/v0.28.1/src/repository.c#L472

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 Debian 9 容器和 dotnet build src 重现 issue 正文中的嵌套子模块情况,然后检查第 20 行的 Microsoft.Build.Tasks.Git.targets,以及链接行附近 libgit2 的 repository.c 中 find_repo 的实现。比较存在和不存在子模块 .git 文件时的仓库发现情况;当构建能够在没有警告的情况下找到嵌套仓库,并且现有仓库的情况仍能正常工作时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, git
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。