@@ -80,7 +80,7 @@ pub(super) async fn parse_input(
80
80
// Only mentions byte-for-byte matching content inside the patch.
81
81
files
82
82
. iter ( )
83
- . filter ( |f| patch_contains ( & f. patch , & * * entry) )
83
+ . filter ( |f| patch_adds ( & f. patch , & * * entry) )
84
84
. map ( |f| PathBuf :: from ( & f. filename ) )
85
85
. collect ( )
86
86
}
@@ -157,11 +157,9 @@ pub(super) async fn handle_input(
157
157
Ok ( ( ) )
158
158
}
159
159
160
- fn patch_contains ( patch : & str , needle : & str ) -> bool {
160
+ fn patch_adds ( patch : & str , needle : & str ) -> bool {
161
161
for line in patch. lines ( ) {
162
- if ( !line. starts_with ( "+++" ) && line. starts_with ( '+' ) )
163
- || ( !line. starts_with ( "---" ) && line. starts_with ( '-' ) )
164
- {
162
+ if !line. starts_with ( "+++" ) && line. starts_with ( '+' ) {
165
163
if line. contains ( needle) {
166
164
return true ;
167
165
}
@@ -183,18 +181,29 @@ mod tests {
183
181
+hello world
184
182
context line
185
183
" ;
186
- assert ! ( patch_contains ( patch, "hello" ) ) ;
184
+ assert ! ( patch_adds ( patch, "hello" ) ) ;
187
185
}
188
186
189
187
#[ test]
190
- fn finds_removed_line ( ) {
188
+ fn finds_added_line_in_modified ( ) {
189
+ let patch = "\
190
+ --- a/file.txt
191
+ +++ b/file.txt
192
+ -hello
193
+ +hello world
194
+ " ;
195
+ assert ! ( patch_adds( patch, "hello" ) ) ;
196
+ }
197
+
198
+ #[ test]
199
+ fn ignore_removed_line ( ) {
191
200
let patch = "\
192
201
--- a/file.txt
193
202
+++ b/file.txt
194
203
-old value
195
204
+new value
196
205
" ;
197
- assert ! ( patch_contains ( patch, "old value" ) ) ;
206
+ assert ! ( !patch_adds ( patch, "old value" ) ) ;
198
207
}
199
208
200
209
#[ test]
@@ -204,7 +213,7 @@ mod tests {
204
213
+++ b/file.txt
205
214
context line
206
215
" ;
207
- assert ! ( !patch_contains ( patch, "file.txt" ) ) ; // should *not* match header
216
+ assert ! ( !patch_adds ( patch, "file.txt" ) ) ; // should *not* match header
208
217
}
209
218
210
219
#[ test]
@@ -214,6 +223,6 @@ mod tests {
214
223
+++ b/file.txt
215
224
+added line
216
225
" ;
217
- assert ! ( !patch_contains ( patch, "missing" ) ) ;
226
+ assert ! ( !patch_adds ( patch, "missing" ) ) ;
218
227
}
219
228
}
0 commit comments