@@ -25,6 +25,7 @@ import (
25
25
"github.com/coder/coder/cli/config"
26
26
"github.com/coder/coder/cli/deployment"
27
27
"github.com/coder/coder/coderd"
28
+ "github.com/coder/coder/coderd/gitauth"
28
29
"github.com/coder/coder/codersdk"
29
30
)
30
31
@@ -109,12 +110,31 @@ func AGPL() []*cobra.Command {
109
110
}
110
111
111
112
func Root (subcommands []* cobra.Command ) * cobra.Command {
113
+ // The GIT_ASKPASS environment variable must point at
114
+ // a binary with no arguments. To prevent writing
115
+ // cross-platform scripts to invoke the Coder binary
116
+ // with a `gitaskpass` subcommand, we override the entrypoint
117
+ // to check if the command was invoked.
118
+ isGitAskpass := false
119
+
112
120
cmd := & cobra.Command {
113
121
Use : "coder" ,
114
122
SilenceErrors : true ,
115
123
SilenceUsage : true ,
116
124
Long : `Coder — A tool for provisioning self-hosted development environments with Terraform.
117
- ` ,
125
+ ` , Args : func (cmd * cobra.Command , args []string ) error {
126
+ if gitauth .CheckCommand (args , os .Environ ()) {
127
+ isGitAskpass = true
128
+ return nil
129
+ }
130
+ return cobra .NoArgs (cmd , args )
131
+ },
132
+ RunE : func (cmd * cobra.Command , args []string ) error {
133
+ if isGitAskpass {
134
+ return gitAskpass ().RunE (cmd , args )
135
+ }
136
+ return cmd .Help ()
137
+ },
118
138
PersistentPreRun : func (cmd * cobra.Command , args []string ) {
119
139
if cliflag .IsSetBool (cmd , varNoVersionCheck ) &&
120
140
cliflag .IsSetBool (cmd , varNoFeatureWarning ) {
@@ -134,6 +154,9 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
134
154
if cmd .Name () == "login" || cmd .Name () == "server" || cmd .Name () == "agent" || cmd .Name () == "gitssh" {
135
155
return
136
156
}
157
+ if isGitAskpass {
158
+ return
159
+ }
137
160
138
161
client , err := CreateClient (cmd )
139
162
// If we are unable to create a client, presumably the subcommand will fail as well
0 commit comments