mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Print file difference like git diff
This commit is contained in:
@@ -121,17 +121,23 @@ func Diff(sourceDir, destDir string) (sets.String, error) {
|
||||
return diff, err
|
||||
}
|
||||
if !bytes.Equal(b1, b2) {
|
||||
dmp := diffmatchpatch.New()
|
||||
diffs := dmp.DiffMain(string(b1), string(b2), false)
|
||||
fmt.Println(dmp.DiffPrettyText(diffs))
|
||||
fmt.Println(PrettyFileDiff(string(b1), string(b2)))
|
||||
diff.Insert(f)
|
||||
}
|
||||
}
|
||||
|
||||
// return the differing files
|
||||
return diff, nil
|
||||
}
|
||||
|
||||
// PrettyFileDiff takes the content of two files and returns the pretty diff
|
||||
func PrettyFileDiff(s1, s2 string) string {
|
||||
dmp := diffmatchpatch.New()
|
||||
wSrc, wDst, warray := dmp.DiffLinesToRunes(s1, s2)
|
||||
diffs := dmp.DiffMainRunes(wSrc, wDst, false)
|
||||
diffs = dmp.DiffCharsToLines(diffs, warray)
|
||||
return dmp.DiffPrettyText(diffs)
|
||||
}
|
||||
|
||||
// SyncFile copies file from src file path to a dst file path by replacement
|
||||
// deletes dst file if src file doesn't exist
|
||||
func SyncFile(src, dst string) error {
|
||||
|
||||
Reference in New Issue
Block a user