Answer a question

It seems like Visual Studio Code and it's dev containers copy the .gitconfig upon creation. As I have to manage different identities I've quite an extensive .gitconfig, which load other configuration files conditionally. For example:

[includeIf "gitdir:~/Workspace/github.com/"]
    path = .gitconfig-github.com

Of course Visual Studio Code doesn't copy them and even if it wouldn't work as the conditional doesn't apply because it will detect the wrong directory.

Anyhow, is it somehow possible to run git config --get user.name and git config --get user.email outside of the container within the working directory and set it to the devcontainer upon creation?


Update

The problem is it's not possible to retrieve the return values from commands within a docker-compose.yml or Dockerfile to hand it over to the container right?

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        VARIANT: 14
        GIT_USERNAME: ${git config --get user.name}
        GIT_USERMAIL: ${git config --get user.email}
    volumes:
      - ..:/workspace:cached
    command: sleep infinity

Something like this wouldn't work. Is there a workaround?

Answers

As illustrated by:

  • commit 1641597 (Update docker-compose.yml files to mount .gitconfig)
  • commit 3ad0b8b (Remove .gitconfig mount now that its copied)

You would need to modify/patch the container-templates/docker-compose/.devcontainer/docker-compose.yml and others containers/xxx/.devcontainer/docker-compose.yml in order to add any instruction automatically executed by VSCode whencreating a new container.

That path would include a way to select the right config/identity to use in order to modify the mounted .gitconfig accordingly.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐