git - git shortlog -s -n -e --no-merges output [] 在 go test 但主函数中的调用是正常输出
问题描述
这是作者结构
type Author struct {
Name string
Email string
CommitNumber int
}
// get all authors
func GetAllAuthor() []Author {
args := []string{"shortlog", "-s", "-n", "-e", "--no-merges"}
var authors []Author
info := utils.MustExecRtOut(Cmd, args...)
lines := strings.Split(info, "\n")
for _, line := range lines {
if len(strings.TrimSpace(line)) > 0 {
author := GetAuthor(line)
authors = append(authors, author)
}
}
return authors
}
// get information about an author
func GetAuthor(line string) Author {
authorInfo := strings.Fields(strings.TrimSpace(line))
emailIndex := len(authorInfo) - 1
email := strings.TrimSpace(authorInfo[emailIndex])
email = utils.SubString(email, 1, len(email)-1)
author := strings.Join(authorInfo[1:emailIndex], " ")
number, err := strconv.Atoi(authorInfo[0])
if err != nil {
fmt.Printf("%s parse commit number %s error!\n", line, authorInfo[0])
}
return Author{
Name: author,
Email: email,
CommitNumber: number,
}
}
当我调用GetAllAuthor
测试函数时,输出是一个空数组
[]
但是当我在main函数中调试或调用时,输出可以像这样正常
[{Joeeeeeeey 123@xx.com 169} {托尼 123@xx.com 62}]
解决方案
如果在命令行上没有传递修订,并且标准输入不是终端或没有当前分支,
git shortlog
则将输出从标准输入读取的日志摘要,而不参考当前存储库。
您没有向我们展示utils.MustExecRtOut
,但我们可能会猜测它提供了一个不是终端的标准输入。如果是这种情况,您将必须提供至少一个起始版本,例如分支名称。
或者,git shortlog
在您遇到不希望的行为的情况下,您可能在没有当前分支名称的情况下运行。这也将通过传递分支名称来解决。
推荐阅读
- gradle - IntelliJ IDEA 2018.2,Gradle 4.9,类路径中未引用外部库
- python - 使用 Python 进程进行多处理
- javascript - Javascript - 如果对象的所有属性都为空,则将其设置为空
- python - 在 python 3.7 中导入 opencv 版本 3.4.2.17
- react-admin - 如何在 SimpleForm 上使用 asyncValidation 显示错误消息?
- javascript - 从 java 脚本调用 php 文件删除函数
- java - 从 CSV 文件中读取 NULL 值
- angular - Angular HttpClient 流式获取请求或有后端触发请求?
- facebook-graph-api - 通过 Android SDK 从 Facebook Graph API 获取公共事件
- three.js - Three.js Quaternion.slerp() 比 Vector3.lerpVectors() 慢