尝试从golang创建git分支的“退出状态128”

时间:2019-03-25 01:27:10

标签: git go git-flow

我正在尝试从golang创建一个“功能分支”。以下代码不起作用:

reader := bufio.NewReader(os.Stdin)
fmt.Print(color.RedString("New feature description: "))
featureName, _ := reader.ReadString('\n')
featureName = strings.ReplaceAll(featureName, " ", "-")
featureBranchName := "feature/" + featureName
cmdStartBranch := "git"
arguments := []string{"checkout", "-b", featureBranchName}
if _, err := exec.Command(cmdStartBranch, arguments...).Output(); err != nil {
    fmt.Println(color.RedString(err.Error()))
    os.Exit(1)
}

但是对featureBranchName进行硬编码会起作用:

cmdStartBranch := "git"
arguments := []string{"checkout", "-b", "feature/ciaone-proprio"}
if _, err := exec.Command(cmdStartBranch, arguments...).Output(); err != nil {
    fmt.Println(color.RedString(err.Error()))
    os.Exit(1)
}

1 个答案:

答案 0 :(得分:1)

ReadString('\n')返回定界符'\ n',您需要将其删除。

featureName, err := reader.ReadString('\n')
if err == nil {
    n := len(featureName)
    featureName = featureName[:n-1]
}

...