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 not copied to remote container #6810

Closed
liby opened this issue Jun 10, 2022 · 23 comments
Closed

.gitconfig not copied to remote container #6810

liby opened this issue Jun 10, 2022 · 23 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers verified Verification succeeded

Comments

@liby
Copy link

liby commented Jun 10, 2022

  • VSCode Version: 1.68.0
  • Local OS Version: macOS 12.4 (21F79)
  • Remote OS Version: Debian GNU/Linux 11 (bullseye)
  • Remote Extension/Connection Type: Containers
  • Logs: issue.log

Steps to Reproduce:

  1. Run inside a devcontainer
  2. git commit
  3. See the error: Make sure you configure your 'user.name' and 'user.email' in git

Does this issue occur when you try this locally?: Yes
Does this issue occur when you try this locally and all extensions are disabled?: Yes

@github-actions github-actions bot added the containers Issue in vscode-remote containers label Jun 10, 2022
@chrmarti
Copy link
Contributor

The says /home/node/.gitconfig already exists. We don't overwrite an existing .gitconfig. Can you remove that from your image?

@chrmarti chrmarti self-assigned this Jun 13, 2022
@chrmarti chrmarti added the info-needed Issue requires more information from poster label Jun 13, 2022
@liby
Copy link
Author

liby commented Jun 14, 2022

The says /home/node/.gitconfig already exists. We don't overwrite an existing .gitconfig. Can you remove that from your image?

I tested it, and the issue only occurred in the vscode repp.

More specifically:

  1. Open VSCode
  2. Press Ctrl/Cmd + Shift + P or F1 and select Remote-Containers: Clone Repository in Container Volume....
  3. Type https://github.com/microsoft/vscode (or a branch or PR URL) in the input box and press Enter.
  4. Remote-Containers: Show Container Log
    ...
    [3068 ms] Start: Run in container: # Test for /root/.gitconfig and git
    [3071 ms] 
    [3071 ms] 
    [3071 ms] Start: Run in container: # Copy /Users/bryan/.gitconfig to /root/.gitconfig
    ...
    [23273 ms] Start: Run in container: # Test for /home/node/.gitconfig and git
    [23277 ms] /home/node/.gitconfig exists
    [23277 ms] 
    [23277 ms] Exit code 1
    [23278 ms] Start: Run in container: command -v git >/dev/null 2>&1 && git config --global --replace-all credential.helper '!f() { /home/node/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f/node /tmp/vscode-remote-containers-4608efb023447d45b285bd29824f35c020bcf312.js $*; }; f' || true
    [23282 ms]
    ...
    

It seems that what settings did VSCode make for the image? I am a rookie in this respect.

@chrmarti chrmarti added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Jun 14, 2022
@chrmarti
Copy link
Contributor

We need to check why the file is there and if we can remove it from that particular image.

@liby
Copy link
Author

liby commented Jun 14, 2022

We need to check why the file is there and if we can remove it from that particular image.

OK, keep me posted.

@Interpause
Copy link

I found that using postCreateCommand in devcontainer.json to configure git (for example git config --global --add safe.directory /workspace) will create .gitconfig before Remote Containers copies over the local .gitconfig, thereby preventing it from copying. Maybe some other people might be running into this issue because of that? Perhaps a warning can be put in the documentation.

@cirvladimir
Copy link

cirvladimir commented Nov 10, 2022

I had the same issue.

One work-around is to add this to devcontainer.json:

"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}"

This seems to both have the host ~/.gitconfig copied over and the workspace directory added to git safe.directory.

I think it would be useful if the vs code remote extension automatically added the workspaceFolder to safe.directory ~/.gitconfig in the container. Can we have that?

@joaomoreno
Copy link
Member

Isolated the issue: #7628

@thumperward
Copy link

Confirmed that this (now) happens when using postCreateCommand on Windows. A typical example for me is "postCreateCommand": "pre-commit install". I'm certain this used to work, but now it breaks things, as postCreateCommand is generating a (blank) .gitconfig before it runs.

Using postAttachCommand fixes things: this has probably always been the correct directive, but all examples and documentation suggest postCreateCommand. This really ought to be highlighted as it hoses devcontainers on Windows.

@ChristopherCapito
Copy link

Confirmed that this (now) happens when using postCreateCommand on Windows. A typical example for me is "postCreateCommand": "pre-commit install". I'm certain this used to work, but now it breaks things, as postCreateCommand is generating a (blank) .gitconfig before it runs.

Using postAttachCommand fixes things: this has probably always been the correct directive, but all examples and documentation suggest postCreateCommand. This really ought to be highlighted as it hoses devcontainers on Windows.

Confirming this works. I was looking for exactly this issue. I was using a postCreateCommand to add the workspace as a safe directory as explained a few posts above.

Please either add this to the containers by default or highlight the issue in the documentation.

@chrmarti
Copy link
Contributor

The local .gitconfig is copied to the container only after postCreateCommand ran. If there already is a .gitconfig in the container by that time, it is left unchanged except for the credential helper which we add.

@chrmarti chrmarti added the info-needed Issue requires more information from poster label Mar 21, 2023
@JayDouglass
Copy link

Confirmed that this (now) happens when using postCreateCommand on Windows. A typical example for me is "postCreateCommand": "pre-commit install". I'm certain this used to work, but now it breaks things, as postCreateCommand is generating a (blank) .gitconfig before it runs.
Using postAttachCommand fixes things: this has probably always been the correct directive, but all examples and documentation suggest postCreateCommand. This really ought to be highlighted as it hoses devcontainers on Windows.

Confirming this works. I was looking for exactly this issue. I was using a postCreateCommand to add the workspace as a safe directory as explained a few posts above.

Please either add this to the containers by default or highlight the issue in the documentation.

Confirmed, "postCreateCommand": "git config --global --add safe.directory /workspaces" doesn't work, you still get the warning.

I had to use postAttachCommand instead:
"postAttachCommand": "git config --global --add safe.directory /workspaces"

@mmghv
Copy link

mmghv commented Apr 8, 2023

For me I'm using WSL2 on Windows, .gitconfig was not copied from Windows, I found out it copies it from the base Linux distro for WSL2 so I had the add the settings there so it get copied to every devcontainer I build, Shouldn't it be copied from Windows?

@ggirard07
Copy link

Same issue here, by simply uncommenting the default content from node image "postCreateCommand": "yarn install",

@D1no
Copy link

D1no commented Aug 9, 2023

Running into the same issue when adding git-lfs feature during the vscode open folder in remote container set-up phase. Very annoying and I don't remember having issues like these in the past... 😕

I.e. need LFS support in a data science container

	// devcontainer.json
	"features": {
		// ...
		"ghcr.io/devcontainers/features/git-lfs:1": {},
		// ...
	},

For now installing git lfs manually via postCreateCommand

	// devcontainer.json
	// ...
	// Use 'postCreateCommand' to run commands after the container is created.

	// Installing git lfs support manually via postCreateCommand to get around this bug
	// https://github.com/microsoft/vscode-remote-release/issues/6810#issuecomment-1672300822
	"postCreateCommand": "sudo apt update && sudo apt install git-lfs",
	// ...

@Yacobolo
Copy link

Yacobolo commented Aug 10, 2023

Can confirm postCreateCommand breaks the gitconfig. Good i found this forum.
Chris Ayers from microsoft uses:
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
https://youtu.be/HV7LJ_LUZ5A?t=892 at 14:53

@tomerh2001
Copy link

The solution seems to be moving anything from postCreateCommand to postAttachCommand.

@D1no
Copy link

D1no commented Oct 8, 2023

I feel ya @tomerh2001 . Seems like the containers internal git setup is moves around in the life cycle through iterations. When in doubt, do it as late as possible. That said postStartCommand seems to far enough after what ever happens internally.

Life Cycle postStartCommand

A command to run after starting the container. This command is run after "postCreateCommand" and before "postAttachCommand". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell. If this is an object, each provided command will be run in parallel.

@Austriker
Copy link

I am experiencing the same issue regarding the gitconfig as @D1no and I have isolated git lfs as the culprit.

Version: 1.84.2 (user setup)
Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
Date: 2023-11-09T10:51:52.184Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.22631

Without git fls:

[user]
        name = NAME
        email = EMAIL
[credential]
        helper = "!f() { /home/django/.vscode-server/bin/ID/node /tmp/vscode-remote-containers-73b3b773-fd5c-42f0-a750-8599bf7ddaca.js git-credential-helper $*; }; f"

With git-lfs either installed with a devcontainer feature or with git lfs install in postCreateCommand

[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
[credential]
        helper = "!f() { /home/django/.vscode-server/bin/ID/node /tmp/vscode-remote-containers-4cf1ec5f-124d-4afc-89ee-d0dd5b053fc6.js git-credential-helper $*; }; f"

@chrmarti
Copy link
Contributor

When running it from postCreateCommand using sudo git lfs install --system might work around it.

@chrmarti chrmarti removed the info-needed Issue requires more information from poster label Dec 12, 2023
@Austriker
Copy link

@chrmarti for now the workaround that works: "postStartCommand": "git lfs install",

@chrmarti
Copy link
Contributor

Changed the implementation to check if the existing gitconfig in the container has only filter and safe sections and in that case we now just append the local gitconfig to the one in the container.

@alexr00 alexr00 added verified Verification succeeded and removed verified Verification succeeded labels Jan 25, 2024
@alexr00
Copy link
Member

alexr00 commented Jan 25, 2024

What's the best way to verify this? I tried with stable + installing git lfs in the Dockerfile, but I can't repro.

@alexr00 alexr00 added the verification-steps-needed Steps to verify are needed for verification label Jan 25, 2024
@chrmarti
Copy link
Contributor

Seeing it with the following config:

{
	"name": "Ubuntu",
	"image": "mcr.microsoft.com/devcontainers/base:jammy",
	"features": {
		"ghcr.io/devcontainers/features/git-lfs:1": {}
	},
	"remoteUser": "root"
}

Without the fix the ~/.gitconfig will only contain the lfs filter and the credential helper. With the fix it will also include the local gitconfig.

@chrmarti chrmarti removed the verification-steps-needed Steps to verify are needed for verification label Jan 25, 2024
@alexr00 alexr00 added the verified Verification succeeded label Jan 25, 2024
@microsoft microsoft locked and limited conversation to collaborators Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers verified Verification succeeded
Projects
None yet
Development

No branches or pull requests