Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Nov 15, 2017
1 parent 0dc28c3 commit 663210c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sshconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Add(path string, host *HostConfig) error {
cfg, aliasMap := ParseConfig(path)
isGlobal := host.Aliases == "*"
// Alias should not exist. except "*" because it always existing
if !isGlobal {
if !isGlobal || (isGlobal && len(aliasMap["*"].Nodes) > 0) {
if err := CheckAlias(aliasMap, false, host.Aliases); err != nil {
return err
}
Expand Down Expand Up @@ -142,11 +142,16 @@ func Add(path string, host *HostConfig) error {
if err != nil {
return nil
}
patterns := []*ssh_config.Pattern{pattern}
newHost := &ssh_config.Host{
Patterns: []*ssh_config.Pattern{pattern},
Patterns: patterns,
Nodes: nodes,
}
cfg.Hosts = append(cfg.Hosts, newHost)
if !isGlobal {
cfg.Hosts = append(cfg.Hosts, newHost)
} else {
*aliasMap["*"] = *newHost
}
return ioutil.WriteFile(path, []byte(cfg.String()), 0644)
}

Expand Down

0 comments on commit 663210c

Please # to comment.