Skip to content

Commit

Permalink
Support vanilla diff recursive flag (#436)
Browse files Browse the repository at this point in the history
* Support vanilla diff recursive flag

* Adjust the regex patterns and explanation

* Simplify recursive regex and add comment
  • Loading branch information
brewsfab authored Jun 18, 2022
1 parent 8670353 commit 6a301bb
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ Use `-u` with `diff` for unified output, and pipe the output to `diff-so-fancy`:
diff -u file_a file_b | diff-so-fancy
```

It also supports the recursive mode of diff with `-r` or `--recursive` as **first argument**

```shell
diff -r -u folder_a folder_b | diff-so-fancy
```

```shell
diff --recursive -u folder_a folder_b | diff-so-fancy
```
## Options

### markEmptyLines
Expand Down
6 changes: 3 additions & 3 deletions diff-so-fancy
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ sub do_dsf_stuff {
#########################
# Look for the filename #
#########################
# $4 $5
} elsif ($line =~ /^${ansi_color_regex}diff (-r|--git|--cc) (.*?)(\e| b\/|$)/) {
# $4 $5
} elsif ($line =~ /^${ansi_color_regex}diff (-r|--recursive|--git|--cc) (.*?)(\e| b\/|$)/) {

# Mercurial looks like: diff -r 82e55d328c8c hello.c
if ($4 eq "-r") {
if ($4 eq "-r" || $4 eq "--recursive") {
$is_mercurial = 1;
$meta_color = get_config_color("meta");
# Git looks like: diff --git a/diff-so-fancy b/diff-so-fancy
Expand Down
24 changes: 24 additions & 0 deletions test/diff-so-fancy.bats
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,27 @@ teardown_file() {
assert_line --index 1 --partial "modified: doc/manual.xml.head"
assert_line --index 3 --partial "@ doc/manual.xml.head:8355 @"
}

@test "recursive vanilla diff -r -bu as Mercurial" {
output=$( load_fixture "recursive_default_as_mercurial" | $diff_so_fancy )
run printf "%s" "$output"

assert_line --index 1 --partial "renamed:"
assert_line --index 3 --partial "@ language/app.py:4 @"
assert_line --index 19 --partial "renamed:"
assert_line --index 21 --partial "@ language/__init__.py:1 @"
assert_line --index 25 --partial "renamed:"
assert_line --index 27 --partial "@ language/README.md:1 @"
}

@test "recursive vanilla diff --recursive -u as Mercurial" {
output=$( load_fixture "recursive_longhand_as_mercurial" | $diff_so_fancy )
run printf "%s" "$output"

assert_line --index 1 --partial "renamed:"
assert_line --index 3 --partial "@ language/app.py:4 @"
assert_line --index 19 --partial "renamed:"
assert_line --index 21 --partial "@ language/__init__.py:1 @"
assert_line --index 25 --partial "renamed:"
assert_line --index 27 --partial "@ language/README.md:1 @"
}
38 changes: 38 additions & 0 deletions test/fixtures/recursive_default_as_mercurial.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff -r -bu core/app.py language/app.py
--- core/app.py 2022-06-08 13:42:10.658920131 +0900
+++ language/app.py 2022-06-08 12:07:22.773069512 +0900
@@ -1,13 +1,13 @@
-from flask import Flask, abort
-from . import CORE_MODULES
+from flask import Flask
+from . import SECTION

app = Flask(__name__)

-@app.route('/<name>')
+@app.route(f'/{SECTION}/<name>')
def index(name):
- if name in CORE_MODULES:
- return "Welcome to the documentation for the core module"
- abort(404)
+ return f"Welcome to the documentation for {name}"

+if __name__ == "__main__":
+ app.run(host="0.0.0.0",port=3000)


diff -r -bu core/__init__.py language/__init__.py
--- core/__init__.py 2022-06-08 12:16:35.203331282 +0900
+++ language/__init__.py 2022-06-08 12:03:32.464264288 +0900
@@ -1 +1 @@
-CORE_MODULES=['base','utils','status']
+SECTION="language"
diff -r -bu core/README.md language/README.md
--- core/README.md 2022-06-08 13:52:56.962174912 +0900
+++ language/README.md 2022-06-08 13:52:39.498090643 +0900
@@ -1,4 +1,4 @@
-# Core
+# Language

## Installation

38 changes: 38 additions & 0 deletions test/fixtures/recursive_longhand_as_mercurial.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff --recursive -u core/app.py language/app.py
--- core/app.py 2022-06-08 13:42:10.658920131 +0900
+++ language/app.py 2022-06-08 12:07:22.773069512 +0900
@@ -1,13 +1,13 @@
-from flask import Flask, abort
-from . import CORE_MODULES
+from flask import Flask
+from . import SECTION

app = Flask(__name__)

-@app.route('/<name>')
+@app.route(f'/{SECTION}/<name>')
def index(name):
- if name in CORE_MODULES:
- return "Welcome to the documentation for the core module"
- abort(404)
+ return f"Welcome to the documentation for {name}"

+if __name__ == "__main__":
+ app.run(host="0.0.0.0",port=3000)


diff --recursive -u core/__init__.py language/__init__.py
--- core/__init__.py 2022-06-08 12:16:35.203331282 +0900
+++ language/__init__.py 2022-06-08 12:03:32.464264288 +0900
@@ -1 +1 @@
-CORE_MODULES=['base','utils','status']
+SECTION="language"
diff --recursive -u core/README.md language/README.md
--- core/README.md 2022-06-08 13:52:56.962174912 +0900
+++ language/README.md 2022-06-08 13:52:39.498090643 +0900
@@ -1,4 +1,4 @@
-# Core
+# Language

## Installation

0 comments on commit 6a301bb

Please sign in to comment.