VS Code multi-root workspace with one top level git repo

Viewed 2042

I am working on a project that requires multiple Google Cloud Functions. Each Cloud Function has its own virtualenv because each has its own Python dependencies. All the Cloud Functions are related so I've added each folder containing the Cloud Function code to a single (multi-root) VSCode workspace. I want to put the code of all the cloud functions in the same Git repo since they are related and work together. So, my .git folder is at the top of my multi-root workspace. My folder structure looks like this:

.
├── .git
├── .gitignore
├── .pylintrc
├── .pytest_cache
├── .vscode
│   └── settings.json
├── func-a
│   ├── .vscode
│   │   ├── launch.json
│   │   └── settings.json
│   ├── main.py
│   ├── requirements.txt
│   ├── schema.json
│   └── service-account.json
├── project.code-workspace
└── func-b
    ├── .pytest_cache
    ├── .vscode
    │   ├── launch.json
    │   └── settings.json
    ├── main.py
    ├── requirements.txt
    ├── service-account.json
    └── test_local.py

My issue is that I am unable to see (and therefore edit) the .gitignore file in VS Code because VS Code doesn't let you add individual files to a workspace (only folders). If instead I try to add the entire fold (that contains func-a and func-b) to the workspace, then I run into the issue of not being able to set different interpreters (virtualenvs) for each Cloud Function and instead VS Code seems to force me to use the same Python interpreter for the entire workspace.

Is there a better way to do what I'm trying to do?

1 Answers

You could simply define two workspaces, one for each projects, each one checked out in their own Git working tree using git sparse-checkout (or the more classic .git/info/sparse-checkout):

The idea is to sparsely checkout the repo with:

  • the .gitignore and any other file you need
  • only the func-x folder you want

You can then define a VSCode workspace for that first sparse checkout.

Repeat the process for the second project.

Related