@@ -3,8 +3,10 @@ package proxycommands
33import (
44 "encoding/base64"
55 "fmt"
6+ "github.com/mitchellh/go-homedir"
67 "io/ioutil"
78 "os"
9+ "path/filepath"
810 "strings"
911
1012 "github.com/loft-sh/devspace/helper/util/stderrlog"
@@ -24,6 +26,8 @@ type ConfigureCmd struct {
2426 PrivateKey string
2527 WorkingDir string
2628
29+ GitCredentials bool
30+
2731 Commands []string
2832}
2933
@@ -41,6 +45,7 @@ func NewConfigureCmd() *cobra.Command {
4145 configureCmd .Flags ().StringVar (& cmd .PrivateKey , "private-key" , "" , "Private key to use" )
4246 configureCmd .Flags ().StringVar (& cmd .WorkingDir , "working-dir" , "" , "Working dir to use" )
4347 configureCmd .Flags ().StringSliceVar (& cmd .Commands , "commands" , []string {}, "Commands to overwrite" )
48+ configureCmd .Flags ().BoolVar (& cmd .GitCredentials , "git-credentials" , false , "If git credentials should get configured" )
4449 return configureCmd
4550}
4651
@@ -118,6 +123,24 @@ func (cmd *ConfigureCmd) Run(_ *cobra.Command, _ []string) error {
118123 }
119124 }
120125
126+ // now configure git credentials
127+ if cmd .GitCredentials {
128+ homeDir , err := homedir .Dir ()
129+ if err != nil {
130+ return err
131+ }
132+
133+ gitConfigPath := filepath .Join (homeDir , ".gitconfig" )
134+ out , err = ioutil .ReadFile (gitConfigPath )
135+ if err != nil || ! strings .Contains (string (out ), "helper = \" /tmp/devspacehelper proxy-commands git-credentials\" " ) {
136+ content := string (out ) + "\n " + "[credential]" + "\n " + " helper = \" /tmp/devspacehelper proxy-commands git-credentials\" \n "
137+ err = ioutil .WriteFile (gitConfigPath , []byte (content ), 0644 )
138+ if err != nil {
139+ return errors .Wrap (err , "write git config" )
140+ }
141+ }
142+ }
143+
121144 // print working dir to stdout
122145 fmt .Print (workingDir )
123146 return nil
0 commit comments