-
Notifications
You must be signed in to change notification settings - Fork 280
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
Adding Signature History Support #505
Conversation
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.
Thanks for the pull request, @benbernard!
Overall this looks good–I've left some comments inline.
To answer your higher-level questions:
- Let's keep the signature in
.git/config
for now since it provides backwards compatibility (user's existing signatures will continue to work without issue). We'll remove it in a future version. - By tests for the "configuration stuff" I assume you mean some of the signing logic in the
Configuration
class? We didn't have any unit tests, no. We were relying on this integration spec to test hook signing. If you add an appropriate test there we will be happy, but would of course love to have some unit tests if you're up for it. - See 2.
- Logical or atomic commits are ideal, so stick with what you're currently doing. Ideally we have commits that don't fail on their own (so you can
git bisect
), but this isn't rigorously followed all the time in this repository.
@@ -37,6 +39,22 @@ def plugin_directory | |||
File.join(Overcommit::Utils.repo_root, @hash['plugin_directory'] || '.git-hooks') | |||
end | |||
|
|||
# Returns absolute path to directoy for the history of signatures |
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.
directoy -> directory
|
||
def signature_history | ||
if @hash['signature_directory'] | ||
@hash['signature_history'].to_i |
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.
Can you elaborate on why setting the signature history is dependent on whether the signature_directory
configuration option is set? It seems like we should respect signature_history
regardless.
# likely to be used, and will be read sooner | ||
signatures = [] | ||
if has_history_file | ||
signatures = (File.readlines history_file).first(@config.signature_history - 1) |
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.
The parentheses here seem odd. Let's just do:
File.readlines(history_file).first(@config.signature_history - 1)
end | ||
end | ||
|
||
def signature_in_history_file(signature) |
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.
Let's end this with ?
for consistency with other boolean-returning methods.
Same with has_history_file
below.
|
||
found = false | ||
File.open(history_file, 'r') do |fh| | ||
# Process the header |
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.
What is this comment referring to?
line.chomp | ||
|
||
if line == signature | ||
found = true |
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.
Could simply return true
here and then false
at the end of this method since there doesn't seem to be a strong need for the found
variable.
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.
Ah, I realize you might have done this because of the block, perhaps for readability. Keep it if you like.
def signature_directory | ||
File.join(Overcommit::Utils.repo_root, | ||
'.git', | ||
@hash['signature_directory'] || 'overcommit-signatures') |
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.
Can you elaborate on why allowing this to be customized is useful? I'm fearful of an overzealous user changing this to a directory of files which are tracked by their Git repository because it can be "helpful" to others in storing previous signatures. Of course this is problematic since now an attacker can modify said files.
I anticipate this is a highly-unlikely scenario, but I would prefer to stick to the YAGNI principle unless there's a solid reason to allow this to be customized. Curious to hear your thoughts here.
Any change of an update here? I'd love to see this functionality. |
Haven't had a chance to get back to this, all the comments make sense, just haven't had a chance to make tests |
Totally understand – just showing my interest! Thanks for working on this! |
I'm not using overcommit anymore (haven't in years, i'm going to close this PR, if anyone wants to take this over the line, feel free |
This is in reference to #300
I am very inexperienced with ruby, so I've probably done some strange / wrong things here, would love your feedback on anything like that.
I also haven't written tests yet. I wanted to get this up here and gather any feedback on the approach, and I have a couple of questions
Obviously, not ready to merge, and just looking for feedback here.