MCPcopy
hub / github.com/kptdev/kpt / Diff

Method Diff

internal/util/diff/diff.go:268–302  ·  view source on GitHub ↗
(pkgs ...string)

Source from the content-addressed store, hash-verified

266}
267
268func (d *defaultPkgDiffer) Diff(pkgs ...string) error {
269 for _, pkg := range pkgs {
270 if err := d.prepareForDiff(pkg); err != nil {
271 return err
272 }
273 }
274 var args []string
275 if d.DiffToolOpts != "" {
276 args = strings.Split(d.DiffToolOpts, " ")
277 args = append(args, pkgs...)
278 } else {
279 args = pkgs
280 }
281 cmd := exec.Command(d.DiffTool, args...)
282 cmd.Stdout = d.Output
283 cmd.Stderr = d.Output
284
285 if d.Debug {
286 fmt.Fprintf(d.Output, "%s\n", strings.Join(cmd.Args, " "))
287 }
288 err := cmd.Run()
289 if err != nil {
290 exitErr, ok := err.(*exec.ExitError)
291 if ok && exitErr.ExitCode() == 1 {
292 // diff tool will exit with return code 1 if there are differences
293 // between two dirs. This suppresses those errors.
294 err = nil
295 } else if ok {
296 // An error occurred but was not one of the excluded ones
297 // Attempt to display help information to assist with resolving
298 fmt.Printf(exitCodeDiffWarning, d.DiffTool, d.DiffType)
299 }
300 }
301 return err
302}
303
304// prepareForDiff removes metadata such as .git and Kptfile from a staged package
305// to exclude them from diffing.

Callers

nothing calls this directly

Calls 3

prepareForDiffMethod · 0.95
CommandMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected