Skip to content

set meaningful defaults for git in post-create - #2

Open
marc-hanheide wants to merge 1 commit into
mainfrom
git_default_config
Open

marc-hanheide wants to merge 1 commit into
mainfrom
git_default_config

Conversation

@marc-hanheide

Copy link
Copy Markdown

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
Copy Markdown
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

cooperj commented Jan 29, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
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