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

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

Closed
HenrikStanley opened this issue Aug 2, 2022 · 4 comments
Assignees
Labels
feature-request New feature or request

Comments

@HenrikStanley
Copy link

HenrikStanley commented Aug 2, 2022

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.
@travisty-
Copy link

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.

@HenrikStanley
Copy link
Author

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.

@james-trousdale-lyb
Copy link

james-trousdale-lyb commented Oct 11, 2022

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

@chrmarti chrmarti self-assigned this Dec 5, 2022
@chrmarti chrmarti added the feature-request New feature or request label Dec 5, 2022
0x4448 added a commit to 0x4448/devcontainer-python that referenced this issue Jul 21, 2023
Setting system gitconfig is a workaround in devcontainers/cli#98
R0Wi added a commit to nextcloud/server that referenced this issue Aug 27, 2023
* postCreateCommand is executed too early
* If git config commands run in postCreate, a global .gitconfig will be created
* Copy of local .gitconfig will be skipped if .gitconfig already exists in container
* Move to later stage
* devcontainers/cli#98
* microsoft/vscode-remote-release#4855 (comment)
R0Wi added a commit to nextcloud/server that referenced this issue Sep 2, 2023
* postCreateCommand is executed too early
* If git config commands run in postCreate, a global .gitconfig will be created
* Copy of local .gitconfig will be skipped if .gitconfig already exists in container
* Move to later stage
* devcontainers/cli#98
* microsoft/vscode-remote-release#4855 (comment)
susnux pushed a commit to nextcloud/server that referenced this issue Oct 11, 2023
* postCreateCommand is executed too early
* If git config commands run in postCreate, a global .gitconfig will be created
* Copy of local .gitconfig will be skipped if .gitconfig already exists in container
* Move to later stage
* devcontainers/cli#98
* microsoft/vscode-remote-release#4855 (comment)
R0Wi added a commit to nextcloud/server that referenced this issue Oct 13, 2023
* postCreateCommand is executed too early
* If git config commands run in postCreate, a global .gitconfig will be created
* Copy of local .gitconfig will be skipped if .gitconfig already exists in container
* Move to later stage
* devcontainers/cli#98
* microsoft/vscode-remote-release#4855 (comment)

Signed-off-by: GitHub <noreply@github.com>
@chrmarti
Copy link
Contributor

Fixing with microsoft/vscode-remote-release#6810.

zak39 pushed a commit to zak39/server that referenced this issue Dec 19, 2023
* postCreateCommand is executed too early
* If git config commands run in postCreate, a global .gitconfig will be created
* Copy of local .gitconfig will be skipped if .gitconfig already exists in container
* Move to later stage
* devcontainers/cli#98
* microsoft/vscode-remote-release#4855 (comment)

Signed-off-by: GitHub <noreply@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants