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

set meaningful defaults for git in post-create #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marc-hanheide
Copy link

This pull request introduces a new function to the .devcontainer/post-create.sh script for setting global Git configuration options if they do not already exist. Additionally, it includes several calls to this new function to set specific Git configurations.

This is to overcome some user challenges, where git cannot commit because a user.name and user.email is not set in ~/.gitconfig. VSCode copies these settings from the host, if they are configured there, or the user has properly set up VSCode already, then it is also correctly set in the container. However, if they don't set it (newbie user), then this sets them to defaults that work.

It also configures the container user's git to handle the CRLF/ LF issue of compatibility between Linux and Windows. This should work, but I don't have Windows to test it.

Enhancements to .devcontainer/post-create.sh:

  • Added add_git_config_if_not_exist function to check and set global Git configuration options if they are not already set.
  • Configured several Git settings using the new add_git_config_if_not_exist function:
    • core.autocrlf set to input
    • core.safecrlf set to warn
    • pull.rebase set to false
    • user.name set to Anonymous L-CAS DevContainer User
    • user.email set to noreply@lcas.lincoln.ac.uk
    • init.defaultBranch set to main

@marc-hanheide
Copy link
Author

@cooperj, could you possibly test this on Windows to see if it works in principle? Just want to make sure I don't destroy anyone's experience.

@cooperj
Copy link

cooperj commented Jan 29, 2025

Tested on a lab pc, and it has reported back an error.

[15143 ms] postStartCommand failed with exit code 127. Skipping any further user-provided commands.
[15146 ms] Error: Command failed: /bin/sh -c /opt/entrypoint.sh /bin/true; .devcontainer/post-create.sh
[15146 ms]     at G7 (c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js:235:130)
[15147 ms]     at async tm (c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js:227:4483)
[15147 ms]     at async b7 (c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js:227:4000)
[15147 ms]     at async em (c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js:227:3192)
[15147 ms]     at async GrA (c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js:666:2752)
[15147 ms]     at async LrA (c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js:665:8554)
[15147 ms]     at async c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js:482:1190
[15179 ms] Exit code 1
[15179 ms] Command failed: C:\Users\Student\AppData\Local\Programs\Microsoft VS Code\Code.exe c:\Users\Student\.vscode\extensions\ms-vscode-remote.remote-containers-0.394.0\dist\spec-node\devContainersSpecCLI.js run-user-commands --user-data-folder c:\Users\Student\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-b1894210-d687-431f-a99e-953fd0badebb1738162661034 --workspace-folder c:\Users\Student\Desktop\cmp3103-ws --id-label devcontainer.local_folder=c:\Users\Student\Desktop\cmp3103-ws --id-label devcontainer.config_file=c:\Users\Student\Desktop\cmp3103-ws\.devcontainer\devcontainer.json --container-id 4e26ef79182e9d3e8b47fa9d60e251c9657850b1bbf6c2427dec0f99ccc334ce --log-level debug --log-format json --config c:\Users\Student\Desktop\cmp3103-ws\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --skip-non-blocking-commands false --prebuild false --stop-for-personalization false --remote-env REMOTE_CONTAINERS_IPC=/tmp/vscode-remote-containers-ipc-67b93423-88e7-46a2-9a62-ccc2082b490c.sock --remote-env REMOTE_CONTAINERS=true --mount-workspace-git-root --terminal-columns 217 --terminal-rows 35 --dotfiles-target-path ~/dotfiles

And then when running the script with cd .devcontainer bash post-create.sh I get back the following error:

ros@4e26ef79182e:/workspaces/cmp3103-ws/.devcontainer$ bash post-create.sh 
post-create.sh: line 2: $'\r': command not found
: invalid optionline 3: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
post-create.sh: line 4: $'\r': command not found
post-create.sh: line 5: $'\r': command not found
post-create.sh: line 6: syntax error near unexpected token `$'{\r''
'ost-create.sh: line 6: `function add_config_if_not_exist {

@marc-hanheide
Copy link
Author

bloody line endings... can you try fixing them (redo the line endings on windows) and commit? them I'll try again on my end, @cooperj ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants