Commit 181e8b1
committed
Use .gitignore as part of the excluded file list
When using Bandit to scan projects based on Git source control,
it would be benefitual to ignore files based on the patterns
in the .gitignore file.
Today, Bandit has some default excludes that get overridden if
a user passes in other excludes. This is a bit confusing to the
end user. But it also serves a purpose similar to .gitignore in
that the paths excluded by default are typically included in a
.gitignore.
This change makes use of an existing dependency of GitPython to
process a .gitignore file. Note, it will only check for .gitignore
files in top-level directories specified on the Bandit command
line as targets. It does not recursive look for .gitignore files.
This is done for a couple reasons. Firstly as recursive searching for
.gitignore files and loading via GitPython would be complex to
add to Bandit existing file discovery. Secondly, the performance
of Bandit might suffer greatly if GitPython is used recursively.
The GitPython is a wrapper around calling various git commands.
So there is a dependency that the user has Git installed. There
are also limitations to argument sizes on operating systems
which this code has newly introduced to ensure the command doesn't
fail.
Signed-off-by: Eric Brown <[email protected]>1 parent 8fa5788 commit 181e8b1
3 files changed
+67
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
| 344 | + | |
344 | 345 | | |
345 | 346 | | |
346 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
200 | 250 | | |
201 | 251 | | |
202 | 252 | | |
| |||
224 | 274 | | |
225 | 275 | | |
226 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
227 | 287 | | |
228 | 288 | | |
229 | 289 | | |
230 | 290 | | |
231 | 291 | | |
232 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
233 | 296 | | |
234 | 297 | | |
235 | 298 | | |
| |||
238 | 301 | | |
239 | 302 | | |
240 | 303 | | |
241 | | - | |
242 | 304 | | |
243 | 305 | | |
244 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
0 commit comments