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

Detect git repositories under ignored paths #41565

Open
yajo opened this issue Jan 13, 2018 · 17 comments
Open

Detect git repositories under ignored paths #41565

yajo opened this issue Jan 13, 2018 · 17 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@yajo
Copy link

yajo commented Jan 13, 2018

This is a feature request.

I work in several projects, mostly Docker-related, where I need to edit code inside git repositories that are ignored inside the main one.

Example file tree:

main-repo/
  .git/
  .gitignore # <-- Here we ignore the `external_sources` folder
  src/
    [files]
  external_sources/
    extra1/
      .git/
      [files]
    extra2/
      .git/
      [files]

The reasoning behind this is an aggregated Docker project that includes sources from many unrelated places. Developing means mounting local code, changing it, and pushing code to all repos (the main one and the ones under external_sources, where we mainly need to open PRs for that), but deploying to production means building a different Docker image where we download and merge external code instead of copying it from localhost.

Boilerplate apart, the feature request is to be able to find those subrepositories, even if they are untracked from the main one, and let the user use the full SCM interface (diffs, SCM section...) on them.

Right now, the diffs do not show because you are editing ignored code, and the SCM does not show these folders for the same reason.

I gues that now that multi-root workspaces are in, this shouldn't be so hard to achieve...

Thanks!

@vscodebot vscodebot bot added the git GIT issues label Jan 13, 2018
@joaomoreno
Copy link
Member

What happens if you create a workspace and add the root folder and those extra1 and extra2 folders to it?

@joaomoreno joaomoreno added the info-needed Issue requires more information from poster label Jan 18, 2018
@yajo
Copy link
Author

yajo commented Jan 18, 2018

No git features work, no matter if you edit the file from within the main folder or others.

@joaomoreno joaomoreno removed the info-needed Issue requires more information from poster label Jan 24, 2018
@joaomoreno joaomoreno added this to the Backlog milestone Jan 24, 2018
@joaomoreno joaomoreno added the bug Issue identified by VS Code Team member as probable bug label Jan 24, 2018
@jrtashjian
Copy link

jrtashjian commented Jan 30, 2018

I ran into this exact issue when setting up root folders in a workspace. The only work around right now is to not use workspaces and instead open each of the other root directories into their own window update the order of the paths in the workspace config file so that the sub-folders are listed before the root folder. It seems as though vscode doesn't separate the .gitignore for each root folder.

Take the following folder structure for reproducing the issue:

project-folder/
    .git/
    .gitignore
    sub-folder-one/
    sub-folder-two/
        sub-sub-folder-one/
            .git/
            .gitignore
        sub-sub-folder-one/
            .git/
            .gitignore

The project-folder/.gitignore file contains the following line:

/sub-folder-two/*

Steps to reproduce when adding the subfolder to the workspace:

  1. Open up Visual Studio Code.
  2. Click "Add Folder to Workspace..." from the "File" menu.
  3. Add project-folder/
  4. Click "Add Folder to Workspace..." from the "File" menu again.
  5. Add project-folder/sub-folder-two/sub-sub-folder-one/
  6. Make a change within the project-folder/ and you'll see the change reflected in the Source Control sidebar.
  7. Make a change within the project-folder/sub-folder-two/sub-sub-folder-one/ and you won't see any changes in the Source Control sidebar.

Steps to reproduce when adding the root to the workspace:

This resolves the issue

  1. Open up Visual Studio Code.
  2. Click "Add Folder to Workspace..." from the "File" menu again.
  3. Add project-folder/sub-folder-two/sub-sub-folder-one/
  4. Click "Add Folder to Workspace..." from the "File" menu.
  5. Make a change within the project-folder/sub-folder-two/sub-sub-folder-one and you'll see the change reflected in the Source Control sidebar.
  6. Add project-folder/
  7. Make a change within the project-folder/ and you'll see the change reflected in the Source Control sidebar.

In this process the changes to the sub-folder are still reflected in the Source Control sidebar and both Git repos are listed under "Source Control Providers."

The order of the added directories matters.

I'm not sure if this is intendend functionality but this is what my investigation has pointed out.

This doesn't work

{
    "folders": [
        {
            "path": "./"
        },
        {
            "path": "./sub-folder-two/sub-sub-folder-one"
        }
    ],
    "settings": {}
}

This works

{
    "folders": [
        {
            "path": "./sub-folder-two/sub-sub-folder-one"
        },
        {
            "path": "./"
        }
    ],
    "settings": {}
}

I'm not sure what the absolute solution should be but setting modifying the order of the paths in the workspace config file is my current solution.

Hope this helps!

Edit: Changed the solution in the top paragraph. Testing and debugging while writing up the issue is always fun haha.

@yajo
Copy link
Author

yajo commented Feb 1, 2018

Interesting... In any case I guess when sub-gits exist in a project, those should get detected automatically, without the need of adding them to workspace, etc.

@jcezarms
Copy link

I'm currently working on a project that's directly affected by this.
Sadly, @jrtashjian's solution almost meets my needs - it works, but most of my build & test related extensions need to have the main repo as first root folder.

@joaomoreno joaomoreno added the help wanted Issues identified as good community contribution opportunities label Jun 8, 2018
@boydcl
Copy link

boydcl commented Aug 9, 2018

+1

Dropped in to give this issue a little push. I'm waiting for a solution as @jrtashjian's workaround works but is not convenient in my situation.

@ashwinmenkudle
Copy link

+1

@jshall
Copy link

jshall commented Apr 16, 2019

I though listing the sub-folder in git.scanRepositories from #56504 should solve this, but .gitignore overrides even that.

@Morgy93
Copy link

Morgy93 commented Apr 21, 2020

Any update on this? I sadly cannot rely on the workaround because many extensions expect the root folder to be the first folder in the workspace.

@tomjn
Copy link

tomjn commented Jul 17, 2020

I can confirm this is also an issue when you open a folder that is inside a git ignored folder. So to take the OPs example, if I open a brand new project and open external_sources in VSCode, it still gets ignored even though the gitignore isn't in the project. The same is true if I use a subfolder.

@danloughmiller
Copy link

Also affected by this, if a folder is ignored by the root .gitignore then it doesn't show up in source control even if it has it's own git repo.

@JeffersonBledsoe
Copy link

Just ran into this issue too. A common workflow when using the dependency/ package management tool zc.buildout is to have dependencies which are being developed as part of a 'parent' project checked out into a src directory which is ignored from git. This bug causes the dependency being developed to be excluded from VS Code's git GUI.

@ablankenship10
Copy link

Same issue here. Even opening the external_sources directory in a separate window as the root folder, its still going up a level to pull the parent .gitignore. My expectation would be to not be looking at anything above the selected open directory for the window.

@ice7mayu
Copy link

I may have a workaround here hope it's helpful.

  1. Launch vscode and open your main-repo. In the file explore you’ll see both external_sources/extra1 and external_sources/extra2 are greyed out since they are ignored in your main-repo.
  2. Open Source Control in the side bar you can only see your main-repo there.
  3. Under SOURCE CONTROL REPOSITORIES right click main-repo opens a context menu then select Close Repository. Now you won't see any repo in the Source Control view.
  4. Open Command Palette (cmd+shit+p) and search for Git: Open Repository choose your external_sources/extra1 sub repo. You will see both extra1 and main-repo are opened in the Source Control view.
  5. Repeat step3 and step4 if you want to add more sub repos along with your main-repo.

Tip: The Source Control view won't append any sub-repo if you don't close the main-repo first which is a bummer.

@thomastong0718
Copy link

This works. Thank you!

@lszomoru
Copy link
Member

In the September 2022 release we have added support for detecting nested git repositories. I believe that this should address the feature request described in this issue. I will go ahead and optimistically close this issue as resolved but in case the newly added feature does not address your needs please feel free to reopen the issue. Thanks!

@tomjn
Copy link

tomjn commented Dec 13, 2022

@lszomoru no this hasn't been resolved, and I suspect that there are actually 2 things here being conflated with each other depending on who has commented.

See this comment:

Same issue here. Even opening the external_sources directory in a separate window as the root folder, its still going up a level to pull the parent .gitignore. My expectation would be to not be looking at anything above the selected open directory for the window.

If i have an ignored folder, and that folder contains projects, when I open those projects, all files and folders are grayed out because of a parent folder that is outside the project.

For example:

Screenshot 2022-12-13 at 22 45 19

There is a folder several levels up that cannot be seen in VSCode and is not a part of the workspace that is under a git ignore for a repo that is also not a part of the workspace, therefore everything is grayed out.

Note this does not happen if the folder opened is the top level of a git repo.

@lszomoru lszomoru reopened this Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests