1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
diff.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"bytes"
"fmt"
"log"
"github.com/pmezard/go-difflib/difflib"
)
var cmdDiff = &Command{
Name: "diff",
Short: "shows the diff between current and previously saved set of dependencies",
Long: `
Shows the difference, in a unified diff format, between the
current set of dependencies and those generated on a
previous 'go save' execution.
`,
Run: runDiff,
OnlyInGOPATH: true,
}
func runDiff(cmd *Command, args []string) {
gold, err := loadDefaultGodepsFile()
if err != nil {
log.Fatalln(err)
}
pkgs := []string{"."}
dot, err := LoadPackages(pkgs...)
if err != nil {
log.Fatalln(err)
}
gnew := &Godeps{
ImportPath: dot[0].ImportPath,
GoVersion: gold.GoVersion,
}
err = gnew.fill(dot, dot[0].ImportPath)
if err != nil {
log.Fatalln(err)
}
diff, err := diffStr(&gold, gnew)
if err != nil {
log.Fatalln(err)
}
fmt.Println(diff)
}
// diffStr returns a unified diff string of two Godeps.
func diffStr(a, b *Godeps) (string, error) {
var ab, bb bytes.Buffer
_, err := a.writeTo(&ab)
if err != nil {
log.Fatalln(err)
}
_, err = b.writeTo(&bb)
if err != nil {
log.Fatalln(err)
}
diff := difflib.UnifiedDiff{
A: difflib.SplitLines(ab.String()),
B: difflib.SplitLines(bb.String()),
FromFile: b.file(),
ToFile: "$GOPATH",
Context: 10,
}
return difflib.GetUnifiedDiffString(diff)
}
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v1.14.0

搜索帮助