Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

benbernard
Copy link

@benbernard benbernard commented Aug 10, 2017

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

  1. Should I remove the .git/config based stuff all together? I considered doing this, but decided not to in the thought that keeping it in place meant that I could basically guarantee that we weren't affecting performance very much.
  2. I couldn't find any tests for the configuration stuff, which seems to have been duplicated from hook_signer (well one was duplicated from the other at least). Did I just miss those? I assume I should write some if they don't already exist
  3. Feedback on writing tests? I was thinking: Check that if you sign a new signature and then return to an old signature, that it doesn't think the configuration has changed. I wasn't necessarily going to peak into the files for the tests, but rather just test the class interface.
  4. What is your commit / merging style? I normally commit a lot, but am happy to squash down to one commit if that is what you folks want

Obviously, not ready to merge, and just looking for feedback here.

Copy link
Owner

@sds sds left a 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:

  1. 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.
  2. 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.
  3. See 2.
  4. 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
Copy link
Owner

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
Copy link
Owner

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)
Copy link
Owner

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)
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Owner

@sds sds Aug 14, 2017

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')
Copy link
Owner

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.

@proinsias
Copy link
Contributor

Any change of an update here? I'd love to see this functionality.

@benbernard
Copy link
Author

Haven't had a chance to get back to this, all the comments make sense, just haven't had a chance to make tests

@proinsias
Copy link
Contributor

Totally understand – just showing my interest! Thanks for working on this!

@benbernard
Copy link
Author

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

@benbernard benbernard closed this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants