-
Notifications
You must be signed in to change notification settings - Fork 279
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
modified_files
and modified_lines_in_file
on CommitMsg
#727
Conversation
Thanks for the PR, @Quintasan. Supportive of the general direction. Looking over this quickly, I don't have an obvious explanation for the failing tests, but my guess would be we'd probably have an easier time extracting the shared logic into a module that we I'm also OK having the tests be duplicated rather than using shared examples. There are often subtle differences between hooks and I don't think DRY tests in this context would be worth it, even if right now we expect the same behavior. Appreciate you proposing this general direction. If we can extract the environment setup/cleanup logic into a module and get the tests passing that way, I'd be comfortable merging. By extracting into a module, perhaps we could finally (separate from this PR, of course) consider implementing a mechanism that doesn't use the stash (see #238). |
Great, I hope to have something you can work with in the upcoming week |
This way, if another hook context needs this behavior it can be included using Overcommit::HookContext::Helpers::StashUnstashedChanges.
Methods for determining which files were modified and on which lines can be imported into hook context with Overcommit::HookContext::Helpers::FileModifications.
@sds It turns out I couldn't wait this much to work on this. I wasn't sure where to put the extracted modules so I went with Another thing I thought of was to rename WDYT? |
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.
Overall looks good. Some minor comments to address and then we'll happily merge. Thanks!
|
||
# Restores the file modification times for all modified files to make it | ||
# appear like they never changed. | ||
def restore_modified_times |
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 have just one module that defines everything rather than splitting up into a separate module for stashing changes and handling file modification time. I don't see the value in separating them as they are both necessary to provide the functionality desired. Let me know if I'm misunderstanding the intent.
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.
@sds the intention here was to provide a way to reuse methods related to file modifications without assuming that the workflow will always be 'we must hide unstaged changes for the hook context'.
Thanks! |
@Quintasan I'm seeing a warning once this commit is added. Can you have a look?
|
Thank you for adding this functionality and taking it through to completion, @Quintasan. Released in 0.56.0. |
As I promised – I did try my hand and I employed the dumbest approach that's almost not copy & paste*
Big problem
It's 2 in the morning so I'm probably cognitively impaired enough to not be able to figure out why
rspec spec/overcommit/hook_context/commit_msg_spec.rb:636:705:764
are failing.All those fails have amending in common so I suspect this is due to calling
amendment?
not from theOvercommit::HookContext::CommitMsg
hook context but from theOvercommit::HookContext::PreCommit
context which I created usingOvercommit::HookContext::PreCommit.new(@config, @args, @input)
but I am unable to pinpoint why would it behave differently.Good points
Overcommit::HookContext::PreCommit
so in the future you'd have to modify only thatBad points
store_modified_times
is copypastarestore_modified_times
is copypastamodified_lines_in_file
is quite close to being copypastaFixing 1, 2, 3 would require some changes in the
PreCommit
hook context but I didn't want to throw a huge PR right away without asking first.@sds Please let me know if this looks reasonable or I need another approach.
Closes #726