@@ -678,6 +678,16 @@ func (m *Manager) BootstrapInstance(name string) error {
678678 wslProjectRoot := toWslPath (projectRoot )
679679 wslProjectDest := "/home/admin/" + projectName
680680
681+ // Read Git config from Windows host to automatically configure Git in WSL.
682+ // This prevents "Please tell me who you are" errors on first git commit.
683+ var gitUserName , gitUserEmail string
684+ if nameOutput , err := exec .Command ("git" , "config" , "--global" , "user.name" ).Output (); err == nil {
685+ gitUserName = strings .TrimSpace (string (nameOutput ))
686+ }
687+ if emailOutput , err := exec .Command ("git" , "config" , "--global" , "user.email" ).Output (); err == nil {
688+ gitUserEmail = strings .TrimSpace (string (emailOutput ))
689+ }
690+
681691 // Run apt-get update + install in a single shell command to minimize
682692 // the number of wsl.exe invocations. Then install Ansible via pip using
683693 // Trellis's requirements.txt. We read from the DrvFS source since the
@@ -742,6 +752,16 @@ WSLCONF
742752mkdir -p /home/admin/.ssh
743753chmod 700 /home/admin/.ssh
744754chown admin:admin /home/admin/.ssh
755+
756+ # Configure Git identity from Windows host settings
757+ if [ -n "GIT_USER_NAME_PLACEHOLDER" ]; then
758+ echo "Configuring Git user.name: GIT_USER_NAME_PLACEHOLDER"
759+ sudo -u admin git config --global user.name "GIT_USER_NAME_PLACEHOLDER"
760+ fi
761+ if [ -n "GIT_USER_EMAIL_PLACEHOLDER" ]; then
762+ echo "Configuring Git user.email: GIT_USER_EMAIL_PLACEHOLDER"
763+ sudo -u admin git config --global user.email "GIT_USER_EMAIL_PLACEHOLDER"
764+ fi
745765`
746766
747767 // Copy the ENTIRE project (trellis/ + site/ + .git/) from Windows into
@@ -835,6 +855,21 @@ chown admin:admin /home/admin/.ssh
835855 )
836856 }
837857
858+ // Inject Git configuration from Windows host
859+ if gitUserName != "" {
860+ m .ui .Info (fmt .Sprintf ("Configuring Git user.name: %s" , gitUserName ))
861+ bootstrapScript = strings .ReplaceAll (bootstrapScript , "GIT_USER_NAME_PLACEHOLDER" , gitUserName )
862+ } else {
863+ bootstrapScript = strings .ReplaceAll (bootstrapScript , "GIT_USER_NAME_PLACEHOLDER" , "" )
864+ }
865+
866+ if gitUserEmail != "" {
867+ m .ui .Info (fmt .Sprintf ("Configuring Git user.email: %s" , gitUserEmail ))
868+ bootstrapScript = strings .ReplaceAll (bootstrapScript , "GIT_USER_EMAIL_PLACEHOLDER" , gitUserEmail )
869+ } else {
870+ bootstrapScript = strings .ReplaceAll (bootstrapScript , "GIT_USER_EMAIL_PLACEHOLDER" , "" )
871+ }
872+
838873 err := command .WithOptions (
839874 command .WithTermOutput (),
840875 ).Cmd ("wsl" , []string {"-d" , distro , "--" , "bash" , "-c" , bootstrapScript }).Run ()
0 commit comments