-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix pre-commit ignoring untracked files #352
Conversation
This commit is admirably simple but hurts my brain to think about it. A few questions/requests/comments...
This is perhaps a bit expansive for a unit test, but can you validate the following scenario? date | shasum > file-a.txt
date | shasum > file-b.txt
git add file-a.txt
tartufo pre-commit We expect that a finding will be generated for file-a.txt, but not for file-b.txt. I worry that the change as proposed at this point will flag both files. |
Hey Scott, I will add that comment you requested. That's a good idea. As for the rest, I have a test case that I have shared elsewhere, which I will paste below. For clarification, this does not scan all files in the repo. Because of the recent addition of Test Case
|
The lightbulb goes on...
This was totally non-obvious to me. Can you extend your comment to include this bit by way of explanation regarding why the chosen flags are present? Otherwise, I'm happy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'm expecting to see that those URLs will trigger entropy findings that will need to be added to pyproject.toml lol...
@jwilbur-godaddy can you cherry-pick 78b27ee from the tartufo repo into your branch? This should fix the issues I noted earlier in my review. |
* Reformat with black; fixes failed CI test * Add signature; silences alert on long URLs in comments
I fully agree with this, and personally I wouldn't see it favorably this gets merged (even if it seems to solve a problem, I still think there is a code-smell here). At the very least, there is a terminology problem. A new file being staged/cached IS NOT UNTRACKED.
Now let us try with a new file being committed:
Maybe the confusion is coming from |
Okay, so do you just want me to change the comment? What are you asking for? |
Can we get additional reviews on this? Would love to get this merged and have a release |
Do we have a unit test we can run against the existing main branch that fails to detect something in the index that is untracked, and that with these new flags it passes, and do we have a unit test that demonstrates that with the flags that untracked files not in the index are NOT scanned? I see the steps to reproduce above, but we should codify those in tests to validate the change we are making. |
This also needs a changelog entry per the PR template |
Can we test the negative case also? i.e. That this change doesn't cause untracked files not staged to the index to be scanned? |
I've got to agree with Jeremiah on this one. I really like this solution, and its elegance, but I definitely think we want that other test just to be extra careful and cautious. Looking at the test you already wrote, it looks like it should even be a decently simple one to add! |
@jgowdy @tarkatronic I don't understand how this section of code does not deliver what you are asking for: |
Ah ha. I had missed that part. Can you split that out to a separate unit test so that the two conditions are tested (and can potentially fail) on their own? |
One other thing, it looks like |
repo.index.add("tests/data/config/" + file_name) | ||
repo.index.write() # This actually writes the index to disk. Without it, the tracked file is not actually staged. | ||
result = runner.invoke(cli.main, ["--entropy-sensitivity", "1", "pre-commit"]) | ||
self.assertNotEqual(result.exit_code, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally realized what struck me as odd here. An exit code of 0
would indicate a successful scan with no issues found. So what I'm not sure about here is, how does this verify that the file was scanned? Since you're writing a sha256 digest to the file, that should get flagged for entropy, though I notice you modify the entropy sensitivity. Shouldn't we be letting it fail, and checking for an exit code greater than 0? Or even better maybe capture json output from the command and ensure that the filename in question is in the output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you miss the assertNotEqual
? I am checking that the return code is not zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops haha yes I did, sorry. ☕ has clearly not kicked in yet!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! Thanks for all the work and putting up with us through the process @jwilbur-godaddy!
@jgowdy can you take another look and make sure your concerns are covered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black still doesn't seem happy, but my concerns about tests are satisfied. Can we fix the black linting and then we're g2g
Done! Thank you, all! |
Just a heads up, I am starting paternity leave tomorrow, so I will not be able to follow up on this after today. I also do not have write access to this repo, so I will not be able to merge this in. |
To help us get this pull request reviewed and merged quickly, please be sure to include the following items:
PR Type
What kind of change does this PR introduce?
Backward Compatibility
Is this change backward compatible with the most recently released version? Does it introduce changes which might change the user experience in any way? Does it alter the API in any way?
Issue Linking
closes #331
What's new?
HEAD
.