Skip to content

Commit bbfa8f2

Browse files
committed
fix: Allow removing invalid Include coder entry
1 parent ec90159 commit bbfa8f2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cli/configssh.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,23 @@ func configSSH() *cobra.Command {
374374
// sshConfigAddCoderInclude checks for the coder Include statement and
375375
// returns modified = true if it was added.
376376
func sshConfigAddCoderInclude(data []byte) (modifiedData []byte, modified bool) {
377-
found := false
377+
valid := false
378378
firstHost := sshHostRe.FindIndex(data)
379379
coderInclude := sshCoderIncludedRe.FindIndex(data)
380380
if firstHost != nil && coderInclude != nil {
381381
// If the Coder Include statement exists
382382
// before a Host entry, we're good.
383-
found = coderInclude[1] < firstHost[0]
383+
valid = coderInclude[1] < firstHost[0]
384+
if !valid {
385+
// Remove invalid Include statement.
386+
d := append([]byte{}, data[:coderInclude[0]]...)
387+
d = append(d, data[coderInclude[1]:]...)
388+
data = d
389+
}
384390
} else if coderInclude != nil {
385-
found = true
391+
valid = true
386392
}
387-
if found {
393+
if valid {
388394
return data, false
389395
}
390396

0 commit comments

Comments
 (0)