-
Notifications
You must be signed in to change notification settings - Fork 292
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 includeif not available inside container #2084
Comments
@brettmillerb Are the included files accessible from the container, though? |
Not natively, they'd need to be copied into the container. I think I had a look at the time to see if there was a COPY for the .gitconfig but couldn't find how the logic was derived between global, repo config copy. |
Please do not copy this kind of stuff, you may end up baking an image with sensitive information inside it. I use this in {
"mounts": ["source=${localEnv:HOME}${localEnv:USERPROFILE}/.config/git,target=/root/.config/git,type=bind,consistency=cached,readonly"],
} The |
If I have to remember to set a mount in the devcontainer.json then it kind of negates the reasons I'm using
I generally only use local docker containers for developing projects rather than using SSH etc
Not sure what you mean by copy-local settings? I mainly use includeif so I don't forget to set my user and email config on repos so if the only option was to set something on a per repo basis e.g. devcontainer.json then I'll just stick to using git cli in an external terminal rather than the vscode integrations. Appreciate this isn't everyone's usecase buts it's definitely a limitation |
I don't think so. Since you would have to reconfigure your per-repo settings on every clone, rather than once upstream per repo (and only for repos that should support both VS code dev containers and conditional Git config).
What you called repo specific settings.
A bit more integrated would be to use a local terminal in a second Visual Studio Code window. |
My robust, standard solution for this is to alter the conditional to only require a subdirectory that marks it as a Git hosting service/instance, instead of forcing it the be under the home directory.
I think VS Code should not apply additional logic to fix up path references in the Git config, and I believe this issue can be closed based on e.g. my solution. @brettmillerb, can you confirm to @chrmarti? |
@sanmai-NL I've just ended up not using the git functionality inside of vscode and use local terminal to interact with git. I can try and test this at some point to see if it's a better workflow. |
I'm currently stuck on this very issue. I want to use the VSCode devcontainer support to offer developers a comfortable way of setting up the environment., extensions, etc. after they cloned the repository. It works for trivial single user git configs but if an advanced multi user git config is encountered with usage of The whole problem and missing support seems to be rooted even deeper than VSCode itself, since there is no way to export the currently active git configuration of a directory. This leaves the following options, all not desirable:
Is there any less annoying solution or workaround available for this issue? 🤔 |
You could use a dotfiles repository to bring in your own |
@DC4JG What doesn't work for you about the solution I outlined? |
@sanmai-NL I tried your conditional include without the explicit home path for the repository and config file but it made no difference for me. It still won't copy/set the included gitconfig file into the devcontainer. I don't have a path issue inside the container but that container creation not respects/fixes the active includes and breaks the config once inside it. Rough explanation of my test setup:
It takes It successfully sets the conditionals when checked in the My goal is to not force any specific setup or required configurations upon the container user but if possible just take whatever they configured for git and is actually active/valid in the folder of the repository like
This would greatly unify the developer environments, make onboarding much easier, keep the native operating system clutter free, enable easy unification of e.g. formatter, linting and other extensions configs and many other things which normally tend to cost a lot of time and effort to setup and slightly differ afterwards between people like person A installed X then Y but person B installed Y before X. If this whole process is encapsulated once, it can even be moved to remote servers/cloud if local machine resources become a limiting factor in the future.
|
A workaround that seems to work is adding the below code to
The JSON fragment with quote escaping would be
It works only for |
In my case the following error is occurring:
VSCode expects a directory not a file. If I delete the file and create the directory then |
Hi ! Same problem here, i'm using |
Hi, same issue. Since the "included" git config files are not bond to the container, the Two possibilities?
Sorry I can only suggest... I don't code in javascript or typescript. |
Update: To handle whitespacce characters in the workspace path or workspace folder name, Inspired by @codemedic's solution, here is a workaround to make the process a little more generic: In {
"initializeCommand": "git config -l > \"${localWorkspaceFolder}\"/.devcontainer/.gitconfig.all && git config --local -l > \"${localWorkspaceFolder}\"/.devcontainer/.gitconfig.local",
"postAttachCommand": "cd \"${containerWorkspaceFolder}\"/.devcontainer && /bin/bash ./attach.sh"
} Create file #!/bin/bash
LOCAL_GITCONFIG="./.gitconfig.local"
ALL_GITCONFIG="./.gitconfig.all"
if [[ -f "$LOCAL_GITCONFIG" && -f "$ALL_GITCONFIG" ]]; then
while IFS= read -r line
do
if ! grep -Fxq "$line" $LOCAL_GITCONFIG
then
key=$(echo $line | cut -d '=' -f 1)
value=$(echo $line | cut -d '=' -f 2-)
git config --file ~/.gitconfig "$key" "$value"
fi
done < $ALL_GITCONFIG
rm -rf "$LOCAL_GITCONFIG" "$ALL_GITCONFIG"
fi The code above adds all git config that is nonlocal to Note: This workaround only passes the git config into devcontainer. If your git config needs other files (e.g., need IdentityFile to specify the correct SSH key (see #5207)), other workarounds are required. |
On Mac OS, if you want to use the gitconfig environment (using ssh authentication + signed commit) specified by includeIf in the devcontainer environment, you can do it as follows.
This may be a late post, but I hope it helps someone. |
Here's a variant of @yongkanm's solution that I am using in my setups. Posting it here in case it can help others. Add the following lines to {
"initializeCommand": "git config -l --global --include > \"${localWorkspaceFolder}\"/.gitconfig.global",
"postAttachCommand": "while IFS='=' read -r key value; do git config --global \"$key\" \"$value\"; done < \"${containerWorkspaceFolder}\"/.gitconfig.global; rm -f \"${containerWorkspaceFolder}\"/.gitconfig.global"
} Explanation:
Tested on MacOS host with Linux-based devcontainer. |
Is this supposed to work on Windows as well or is it Linux/macOS only? Trying to start a dev container with those lines simply fails:
I also tried fixing the quote mark and changed it to use back slashes instead, but it didn't help:
Trying to run
|
@azutmp , good point! This was only tested on a MacOS host. I've now edited the previous post to indicate that. It seems from your error that the initializeCommand needs to be tweaked to run on Windows, but I don't know how. :-( |
Bumping into this as well. devcontainer is already building We probably want to ignore some config entries like credential helpers which are OS-specific. |
The error stems from having a file path in the command, since cmd.exe is interpreting the path separator as a argument flag to cmd.exe. Note the spec specifies that in devcontainer.json: {
// ...
"initializeCommand": {
"extractGitGlobals": "git config -l --global --include > .gitconfig.global",
"extractGitLocals": "git config -l --local --include > .gitconfig.local"
},
"postAttachCommand": "/bin/bash .devcontainer/post-attach.sh", In #!/bin/bash
set -eu
# Re-configures git global and local configuration with includes
# https://github.com/microsoft/vscode-remote-release/issues/2084
for conf in .gitconfig.global .gitconfig.local; do
if [ -f $conf ]; then
echo "*** Parsing ${conf##.gitconfig.} Git configuration export"
while IFS='=' read -r key value; do
case "$key" in
user.name | user.email | user.signingkey | commit.gpgsign)
echo "Set Git config ${key}=${value}"
git config --global "$key" "$value"
;;
esac
done <"$conf"
rm -f "$conf"
fi
done The
This is tested on both Windows and MacOS. |
VSCode Version:
Version: 1.41.0-insider
Commit: 599c076d91be1374cf51004cec610f3bcaf4c9cd
Date: 2019-11-22T07:19:06.796Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
Local OS Version:
OS: Darwin x64 18.7.0
Remote OS Version:
Debian 9 (mcr.microsoft.com/powershell)
Remote Extension/Connection Type: Docker
Steps to Reproduce:
Local .gitconfig contains
git config --list --show-origin
Local
Devcontainer
Seen #1811 but didn't think it was the same thing.
The text was updated successfully, but these errors were encountered: