Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative git submodules are not indexed #576

Closed
NN--- opened this issue Feb 16, 2020 · 7 comments · Fixed by #587
Closed

Relative git submodules are not indexed #576

NN--- opened this issue Feb 16, 2020 · 7 comments · Fixed by #587

Comments

@NN---
Copy link

NN--- commented Feb 16, 2020

Given git submodule with relative path:

.gitmodules

[submodule "a"]
   path = a
   url = ../a

SourceLink produces a warning and doesn't index files.

It doesn't produce a warning when a full URL is specified.

[submodule "a"]
   path = a
   url = htttp://github.com/company/a
@tmat
Copy link
Member

tmat commented Feb 16, 2020

What warning is reported?

This scenario is covered by test GetSourceRoots_RelativeSubmodulePaths.

@NN---
Copy link
Author

NN--- commented Feb 17, 2020

packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Repository 'c:\project\a.git' has no 
remote.
[c:\project\x\x.vcxproj]

packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Repository 'c:\project\b' has no remote.
[c:\project\x\x.vcxproj]

@tmat
Copy link
Member

tmat commented Feb 17, 2020

Can you share the structure of all the repositories involved? That is the content of their .git directories (just the files directly in those directories), the .gitmodules file and their locations on disk?
Alternatively, steps to reproduce.

@NN---
Copy link
Author

NN--- commented Feb 18, 2020

Check this repository: https://github.com/NN---/sourcelinkmain

git clone https://github.com/NN---/sourcelinkmain sourcelinkmain
cd sourcelinkmain
git submodule update
nuget restore sourcelinkmain.sln
devenv sourcelinkmain.sln /build
1>C:\sourcelinkmain\packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Repository 'C:\Projects\tests\sourcelinka.git' has no remote.
1>C:\sourcelinkmain\packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Repository 'C:\Projects\tests\sourcelinkb' has no remote.

@Zastai
Copy link

Zastai commented Feb 20, 2020

I have the same issue.

Given

  • a project (Foo) cloned in E:\Sources\Foo
  • a submodule (Bar) in a subdirectory "xyzzy" (so X:\Sources\Foo\xyzzy)
  • .git/config containing
    [core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    [remote "origin"]
    url = https://github.com/User/Foo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
    remote = origin
    merge = refs/heads/master
    [submodule "xyzzy"]
    url = https://github.com/User/Bar.git
    active = true
    
  • .git/HEAD containing ref: refs/heads/master
  • .git/refs/heads/master containing 3c7de8936de5825fe868591907962c6b59a9a429
  • xyzzy/.git containing gitdir: ../.git/modules/xyzzy
  • .git/modules/xyzzy/config containing
    [core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    worktree = ../../../xyzzy
    [remote "origin"]
    url = https://github.com/User/Bar.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
    remote = origin
    merge = refs/heads/master
    
  • .git/modules/xyzzy/HEAD containing ref: refs/heads/master
  • .git/modules/xyzzy/refs/heads/master containing 03fa592c00fc729c86d7ecb046e25d0895523771

I get multiple cases of

...\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Repository 'E:\Sources\Bar.git' has no remote.

Using MSBuild binlog, the first reference to this nonexistent path (E:\Sources\Bar.git) I see is:

Microsoft.Build.Tasks.Git.LocateRepository
    Assembly = ...\microsoft.build.tasks.git\1.0.0\build\..\tools\netcoreapp2.0\Microsoft.Build.Tasks.Git.dll
    Parameters
        Path = E:\Sources\Foo\src
    Warnings
        ...\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): Repository 'E:\Sources\Bar.git' has no remote. [E:\Sources\Foo\src\Foo.csproj]
    OutputProperties
        _GitRepositoryId = E:\Sources\Foo\.git
        ScmRepositoryUrl = https://github.com/User/Foo.git
        SourceRevisionId = 3c7de8936de5825fe868591907962c6b59a9a429
    OutputItems
        SourceRoot
            E:\Sources\Foo\
                RevisionId = 3c7de8936de5825fe868591907962c6b59a9a429
                ScmRepositoryUrl = https://github.com/User/Foo.git
                SourceControl = git
            E:\Sources\Foo\xyzzy\
                ContainingRoot = E:\Sources\Foo\
                NestedRoot = xyzzy/
                RevisionId = 03fa592c00fc729c86d7ecb046e25d0895523771
                ScmRepositoryUrl = file:///E:/Sources/Bar.git
                SourceControl = git

So this task seems to have no problem finding the source roots and the commit hashes, but computing the RepositoryUrl for submodules goes wrong.

(At first glance, it seems to be correctly appending Bar.git, just to the wrong path (the parent of the local source dir instead of the parent of the repository url.)

@Zastai
Copy link

Zastai commented Feb 22, 2020

Relevant file I omitted: .gitmodules:

[submodule "build"]
	path = build
	url = ../Bar.git
	branch = master

@Zastai
Copy link

Zastai commented Feb 22, 2020

Looks like GitRepository gets and reports ../Bar.git as url.
So either that's wrong and should already be resolved, or GitOperations is doing the wrong thing when it is making it absolute.

Note: in my tree at least, .git/modules/xyzzy/config contains a remote name for the branch listed in .gitmodules, and that remote has a full URL, so I am not sure why the code does not follow that path (which would be close to how the main dir is handled anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@tmat @NN--- @Zastai and others