Skip to content

Commit cef3164

Browse files
Implement invert for :replace (#1480)
Inversion is needed for composition. Since we can't restore the original string of a replacement, the invert ist :nop See: #1476 Change: invert-replace
1 parent 6d1a832 commit cef3164

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

josh-core/src/filter/opt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ pub fn invert(filter: Filter) -> JoshResult<Filter> {
496496
Op::Prefix(path) => Some(Op::Subdir(path)),
497497
Op::Glob(pattern) => Some(Op::Glob(pattern)),
498498
Op::Rev(_) => Some(Op::Nop),
499+
Op::RegexReplace(_) => Some(Op::Nop),
499500
_ => None,
500501
};
501502

tests/filter/replace.t

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,20 @@
7272
+++ b/subdir/hw.txt
7373
@@ -0,0 +1 @@
7474
+hello moon
75+
76+
$ josh-filter --update refs/heads/filtered ':[xdir=:/subdir,:replace("hello":"bye","(?m)^(?P<l>.+)$":"$l!")]'
77+
$ git diff ${EMPTY_TREE}..refs/heads/filtered
78+
diff --git a/hw.txt b/hw.txt
79+
new file mode 100644
80+
index 0000000..9836695
81+
--- /dev/null
82+
+++ b/hw.txt
83+
@@ -0,0 +1 @@
84+
+bye world!
85+
diff --git a/xdir/hw.txt b/xdir/hw.txt
86+
new file mode 100644
87+
index 0000000..1b95c6e
88+
--- /dev/null
89+
+++ b/xdir/hw.txt
90+
@@ -0,0 +1 @@
91+
+hello moon

0 commit comments

Comments
 (0)