cli icon indicating copy to clipboard operation
cli copied to clipboard

.gitconfig file copy function not working when git settings are part of the postCreateCommand

Open HenrikStanley opened this issue 3 years ago • 3 comments

VSCode Version: 1.69.1
Local OS Version: Windows 11 Pro, OS Build 22000.795
Local chip architecture: x86
Reproduces in: Remote - Containers
Name of Dev Container Definition with Issue: Custom Container Image

When using the build in function in devcontainers that copies the host systems .gitconfig file into the container, it is not possible to also edit the .gitconfig file under the postCreateCommand part of the container build process, which could be needed to change things such as the safe.directory settings.

For example, as part of the container build, I want to add the workspace folder to the copied .gitconfigs safe directory settings by having the follow in my postCreateCommand: git config --global --add safe.directory ${containerWorkspaceFolder}

However since the file at this point has not been copied into the container yet, using any git config command will create a .gitconfig file inside the container. Later in the build, a check runs that looks for an existing .gitconfig file and if it find ones, it does not copy.

Steps to Reproduce:

  1. Set Remote › Containers: Copy Git Config setting to true
  2. Set in devcontainer.json git config --global --add safe.directory ${containerWorkspaceFolder}

Suggested solutions:

  1. Run the copy of gitconfig from host before postCreateCommand.
  2. Add a setting natively in devcontainer.json or the vscode plugin to add add safe.directory at the appropriate timing after copy from host.

HenrikStanley avatar Aug 02 '22 19:08 HenrikStanley

As a workaround, I've been writing to the system gitconfig instead:

"postCreateCommand": "sudo git config --system --add safe.directory ${containerWorkspaceFolder}",

I agree that the dev container CLI should manage safe directories for the workspace internally, instead of having to explicitly add them via devcontainer.json commands or directly in a Dockerfile. When using a dev container as a development environment, this seems like the desired default behavior.

travisty- avatar Aug 15 '22 07:08 travisty-

As a workaround, I've been writing to the system gitconfig instead:

"postCreateCommand": "sudo git config --system --add safe.directory ${containerWorkspaceFolder}",

I agree that the dev container CLI should manage safe directories for the workspace internally, instead of having to explicitly add them via devcontainer.json commands or directly in a Dockerfile. When using a dev container as a development environment, this seems like the desired default behavior.

Nice idea for a work around, I can use this to help out while this request is open. But as you say, some kind of build in mechanism to control this would be immensely helpful.

HenrikStanley avatar Aug 16 '22 22:08 HenrikStanley

@HenrikStanley Does it not work to use postStartCommand instead, as detailed here?

james-trousdale-lyb avatar Oct 11 '22 17:10 james-trousdale-lyb

Fixing with https://github.com/microsoft/vscode-remote-release/issues/6810.

chrmarti avatar Dec 13 '23 08:12 chrmarti