config: check a remote exists when creating a new one

This commit is contained in:
Nick Craig-Wood
2019-11-05 12:39:33 +00:00
parent 3f7af64316
commit 049ff1f269
2 changed files with 29 additions and 10 deletions
+7 -2
View File
@@ -1084,12 +1084,17 @@ func fsOption() *fs.Option {
return o
}
// NewRemoteName asks the user for a name for a remote
// NewRemoteName asks the user for a name for a new remote
func NewRemoteName() (name string) {
for {
fmt.Printf("name> ")
name = ReadLine()
err := fspath.CheckConfigName(name)
_, err := getConfigData().GetSection(name)
if err == nil {
fmt.Printf("Remote %q already exists.\n", name)
continue
}
err = fspath.CheckConfigName(name)
switch {
case name == "":
fmt.Printf("Can't use empty name.\n")