vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

Improve configuration of dev container .gitconfig

Open chrmarti opened this issue 4 years ago • 23 comments

Thank you for responding @chrmarti, I appreciate you discussing this even if you didn't necessarily agree with it.

I really appreciate the tip regarding devcontainer.json. That is non-obvious but it works great!

I still question why the local configuration is imported by default, but with a working shippable setting to disable that behaviour, I'm good.

I'm now running the following shell script as my postCreateCommand:

git config --global core.editor "code --wait"
git config --global diff.tool vscode
git config --global difftool.vscode.cmd "code --wait --diff \$LOCAL \$REMOTE"
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd "code --wait \$MERGED"
yarn install

Maybe in the future this extension would consider setting more than just credential.helper by default; "text editor sets itself as text editor" seems like fair game in terms of behaviour, and would probably improve ease of use for most folks. It would also overwrite any incompatible imported settings.

Originally posted by @aaronadamsCA in https://github.com/microsoft/vscode-remote-release/issues/4603#issuecomment-792959197

chrmarti avatar Mar 09 '21 07:03 chrmarti

I may have misunderstood, but +100 to not overwriting the container user's .gitconfig as a default. As far as I can tell, this was the same beef as with #4603. Silently overwriting a bunch of stuff on behalf of the user by default is not only disrespectful, but it's hard to debug. Please either turn it off by default or make it stupid simple to detect and disable without requiring protracted investigations by end users.

posita avatar Feb 15 '22 15:02 posita

.gitconfig is only copied into the container when there is no .gitconfig in the container yet. The credential.helper is then overwritten with a helper that forwards the credentials from the host. Both can be controlled through user settings.

chrmarti avatar Feb 22 '22 09:02 chrmarti

Which user settings? Link?

posita avatar Feb 22 '22 14:02 posita

image

chrmarti avatar Feb 22 '22 14:02 chrmarti

Hmmm…my existing .gitconfig (from my container user's home directory which is mounted from a named volume) is updated every time I rebuild the container. (I don't publish my dotfiles in a repository.)

And yet:

Screen Shot 2022-02-22 at 09 24 23 Screen Shot 2022-02-22 at 09 24 30

Not sure if this is getting off-topic for the original issue, though.

posita avatar Feb 22 '22 15:02 posita

Check the Remote tab. That will store the setting in your container's home folder. (Or disconnect from the remote and the setting will be under the User tab.)

chrmarti avatar Feb 23 '22 06:02 chrmarti

Nothing under the remote tab either:

Screen Shot 2022-02-23 at 08 05 26 Screen Shot 2022-02-23 at 08 05 32 Screen Shot 2022-02-23 at 08 06 36 Screen Shot 2022-02-23 at 08 06 46

Or do I not understand what you mean by "Remote Tab"?

posita avatar Feb 23 '22 14:02 posita

image

thank you kind sir

aidan-melen avatar Feb 24 '22 03:02 aidan-melen

Still not seeing this. @aidan-melen, how did you get there?

posita avatar Feb 24 '22 08:02 posita

@posita If searching settings for "git config" gives you no results, something's up with your environment well beyond the topic of this issue. A clean install of VS Code should return at least 4 results for that search term just from built-in extensions.

aaronadamsCA avatar Feb 28 '22 10:02 aaronadamsCA

Okay, I reinstalled and now have those settings. Git Credential Helper Config Location only appears in Remote -Containers, though, not User. When I set it to global and restart my container, my container user's ~/.gitconfig still gets modified, though. Not sure if that's a separate bug, but it's certainly not honoring the settting.

posita avatar Feb 28 '22 19:02 posita

I remember finding that copyGitConfig only worked for me when I put it into my devcontainer.json file, like this:

{
  "settings": {
    "remote.containers.copyGitConfig": false
  }
}

It's possible gitCredentialHelperConfigLocation has the same limitation, I'm not sure.

aaronadamsCA avatar Mar 02 '22 16:03 aaronadamsCA

I tried that. It's not honored. This does not appear to have any effect:

{
  "settings": {
    "remote.containers.gitCredentialHelperConfigLocation": "global"
  }
}

I have verified that the setting does propagate to ~/.vscode-server/data/Machine/settings.json on the container side.

posita avatar Mar 05 '22 16:03 posita

Note that "remote.containers.gitCredentialHelperConfigLocation": "global" is the default and copies the .gitconfig to the user's home folder. global and system are Git's terminology for the gitconfig's location.

chrmarti avatar Mar 07 '22 10:03 chrmarti

I see #6124 (git email/name is not copied) if I run git config --global ... in the postCreateCommand script like @chrmarti do.

moander avatar Mar 26 '23 01:03 moander

The .gitconfig is not copied if one already exists in the container.

The copying is done after postCreateCommand and any dotfiles install script run, so if postCreateCommand or the dotfiles installs script create a .gitconfig in the container (e.g., as part of git config --global ...), the local .gitconfig will not be copied.

chrmarti avatar Apr 04 '23 12:04 chrmarti

There must be a way to avoid modifying the user's .gitconfig file, right? :thinking:

teohhanhui avatar May 13 '24 21:05 teohhanhui

@teohhanhui See this user setting: Image

chrmarti avatar May 14 '24 07:05 chrmarti

@chrmarti That's on by default, and it's talking about copying the host's .gitconfig into the container, no? How does that relate to modifying the host's .gitconfig?

teohhanhui avatar May 14 '24 11:05 teohhanhui

@teohhanhui Which modification are you referring to?

chrmarti avatar May 15 '24 08:05 chrmarti

@chrmarti Correct me if I'm wrong, but from what I've observed the extension adds its own credential helper to ~/.gitconfig, which causes lots of problems, especially when it fails to clean up after itself.

Also, it does chown as well...

It'd really be preferable for the extension to only modify the project's .git/config in the case of credential helpers.

teohhanhui avatar May 15 '24 08:05 teohhanhui

@teohhanhui It sounds like you have your local home folder mounted in the container. You could change the following user setting to system (there is no project at the moment): Image

chrmarti avatar May 15 '24 08:05 chrmarti

It sounds like you have your local home folder mounted in the container.

Yes, it's a very common setup. I'm using distrobox, but toolbox does the same as well.

teohhanhui avatar May 15 '24 08:05 teohhanhui

https://github.com/microsoft/vscode-remote-release/issues/4632#issuecomment-1495924470

The .gitconfig is not copied if one already exists in the container.

The copying is done after postCreateCommand and any dotfiles install script run, so if postCreateCommand or the dotfiles installs script create a .gitconfig in the container (e.g., as part of git config --global ...), the local .gitconfig will not be copied.

Is this documented anywhere? This is the only place I've been able to find this information and think it would be very valuable to have in the documentation as it would have saved me a bunch of time trying to figure out why my .gitconfig wasn't being copied into the container.

branic avatar Jul 31 '24 17:07 branic