diff --git a/changelog/unreleased/issue-2508 b/changelog/unreleased/issue-2508 index 5adaddd9a..d0292d002 100644 --- a/changelog/unreleased/issue-2508 +++ b/changelog/unreleased/issue-2508 @@ -1,8 +1,11 @@ -Enhancement: Support JSON output for diff +Enhancement: Support JSON output and quiet mode for diff We've added support for getting machine-readable output for snapshot diff, just pass the flag `--json` for `restic diff` and restic will output a JSON-encoded diff stats and change list. +Passing the `--quiet` flag to the `diff` command will only print the summary +and suppress the detailed output. + https://github.com/restic/restic/issues/2508 -https://github.com/restic/restic/pull/3592 \ No newline at end of file +https://github.com/restic/restic/pull/3592 diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 960fbc7e7..30aaa3225 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -2011,19 +2011,26 @@ func TestDiff(t *testing.T) { testRunBackup(t, "", []string{datadir}, opts, env.gopts) _, secondSnapshotID := lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts)) + // quiet suppresses the diff output except for the summary + env.gopts.Quiet = false _, err := testRunDiffOutput(env.gopts, "", secondSnapshotID) rtest.Assert(t, err != nil, "expected error on invalid snapshot id") out, err := testRunDiffOutput(env.gopts, firstSnapshotID, secondSnapshotID) - if err != nil { - t.Fatalf("expected no error from diff for test repository, got %v", err) - } + rtest.OK(t, err) for _, pattern := range diffOutputRegexPatterns { r, err := regexp.Compile(pattern) rtest.Assert(t, err == nil, "failed to compile regexp %v", pattern) rtest.Assert(t, r.MatchString(out), "expected pattern %v in output, got\n%v", pattern, out) } + + // check quiet output + env.gopts.Quiet = true + outQuiet, err := testRunDiffOutput(env.gopts, firstSnapshotID, secondSnapshotID) + rtest.OK(t, err) + + rtest.Assert(t, len(outQuiet) < len(out), "expected shorter output on quiet mode %v vs. %v", len(outQuiet), len(out)) } type writeToOnly struct {