#605

diff: support -r and -q for directories, -U N, -w and -B

Openasafyishopened 14d ago

What are you trying to do?

Compare two directory trees, e.g. a snapshot against a working copy, with diff -ru before after. That's the usual way people and agents review a change, but just-bash's diff only takes files:

$ diff -ru /a /b
diff: invalid option -- 'r'
$ diff -q /a /b
diff: /a: No such file or directory
$ diff -U0 /a/x.txt /b/x.txt
diff: invalid option -- 'U'

-w and -B are rejected the same way. Repro: new Bash({ files: { "/a/x.txt": "1\n", "/b/x.txt": "2\n", "/a/y.txt": "y\n" } }), on just-bash 3.6.0.

Proposed behavior

Match GNU diff:

  • -r/--recursive walks both trees and prints Only in DIR: NAME for entries that exist on one side only.
  • -q works for directories too.
  • -U N/--unified=N sets the amount of context.
  • -w, -b and -B ignore whitespace and blank-line changes.

For the example above:

$ diff -ru /a /b
diff -ru /a/x.txt /b/x.txt
--- /a/x.txt
+++ /b/x.txt
@@ -1 +1 @@
-1
+2
Only in /a: y.txt
$ diff -q /a /b
Files /a/x.txt and /b/x.txt differ
Only in /a: y.txt

Exit status 0 means same, 1 means different, and 2 means trouble. Today an invalid option exits 1, which reads as "files differ".

Alternatives

Looping over find output and diffing file by file. That loses the Only in lines and gets long quickly.

Additional context

Node 26 on macOS. Main (9ab0e0d) has no changes to diff since 3.6.0.

Activity

0

No activity yet.