(ctx context.Context, rep repo.Repository)
| 37 | } |
| 38 | |
| 39 | func (c *commandDiff) run(ctx context.Context, rep repo.Repository) error { |
| 40 | ent1, err := snapshotfs.FilesystemEntryFromIDWithPath(ctx, rep, c.diffFirstObjectPath, false) |
| 41 | if err != nil { |
| 42 | return errors.Wrapf(err, "error getting filesystem entry for %v", c.diffFirstObjectPath) |
| 43 | } |
| 44 | |
| 45 | ent2, err := snapshotfs.FilesystemEntryFromIDWithPath(ctx, rep, c.diffSecondObjectPath, false) |
| 46 | if err != nil { |
| 47 | return errors.Wrapf(err, "error getting filesystem entry for %v", c.diffSecondObjectPath) |
| 48 | } |
| 49 | |
| 50 | _, isDir1 := ent1.(fs.Directory) |
| 51 | _, isDir2 := ent2.(fs.Directory) |
| 52 | |
| 53 | if isDir1 != isDir2 { |
| 54 | return errors.New("arguments to diff must both be directories or both non-directories") |
| 55 | } |
| 56 | |
| 57 | d, err := diff.NewComparer(c.out.stdout(), c.diffStatsOnly) |
| 58 | if err != nil { |
| 59 | return errors.Wrap(err, "error creating comparer") |
| 60 | } |
| 61 | defer d.Close() //nolint:errcheck |
| 62 | |
| 63 | if c.diffCompareFiles { |
| 64 | parts := strings.Split(c.diffCommandCommand, " ") |
| 65 | d.DiffCommand = parts[0] |
| 66 | d.DiffArguments = parts[1:] |
| 67 | } |
| 68 | |
| 69 | if isDir1 { |
| 70 | snapshotDiffStats, err := d.Compare(ctx, ent1, ent2) |
| 71 | if err != nil { |
| 72 | return errors.Wrap(err, "error comparing directories") |
| 73 | } |
| 74 | |
| 75 | b, err := json.Marshal(snapshotDiffStats) |
| 76 | if err != nil { |
| 77 | return errors.Wrap(err, "error marshaling computed snapshot diff stats") |
| 78 | } |
| 79 | |
| 80 | fmt.Fprintf(c.out.stdout(), "%s", b) //nolint:errcheck |
| 81 | |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | return errors.New("comparing files not implemented yet") |
| 86 | } |
| 87 | |
| 88 | func defaultDiffCommand() string { |
| 89 | if isWindows() { |
nothing calls this directly
no test coverage detected