libgit2 / libgit2/libgit2sharp

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

オープン
#1,683 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Debian 9 コンテナーと dotnet build src を使って、issue 本文にあるネストされたサブモジュールのケースを再現し、Microsoft.Build.Tasks.Git.targets の 20 行目と、リンク先の行付近にある libgit2 の repository.c の find_repo 実装を調べます。サブモジュールの .git ファイルがある場合とない場合でリポジトリの検出を比較します。ビルドが警告なしでネストされたリポジトリを検出し、既存のリポジトリのケースも引き続き動作すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, git
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。