-
-
Notifications
You must be signed in to change notification settings - Fork 680
proper pre-push hook implementation #2811
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
base: master
Are you sure you want to change the base?
Conversation
|
I can confirm the issue appears to be gone when building from this branch. I am not that familiar with Rust development, so let me share the steps I followed to ensure I am not missing anything:
|
The way you did it works, if you wanna use this custom build in a few more places to test, simply run |
Excellent, that will get me through the last work day of the year. Thank you for solving the issue so quickly. Have a great end of the year. |
Branch case now uses the same destination ref logic as the push path: it honors `push.default=upstream` (when not deleting) via `branch_push_destination_ref`, so the `<remote-ref>` field matches the refspec Git would use.
ce17490 to
6998e42
Compare
|
@extrawurst I’ll try and have a look later this week! (I want to set up a proper repository with |
|
I started reviewing this PR, but since it’s a lot of new code and I’m not deeply familiar with hooks, it might take a while. :-) I can confirm, though, that the error message mentioned in the bug report is gone. Instead, |
cruessler
left a comment
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.
As far as I can tell, things are looking good! My understanding is that this PR adds proper passing of arguments and stdin to pre-push hook calls, to be more in line with what git does.
The changes in hooks.rs look good, but I haven’t been able to review them as detailed as the ones in lib.rs as this is an area I’m less familiar with.
Some of my comments are repetitive, e. g. ones to the effect of “Can this comment be removed”. I hope that’s more helpful than just a general “Some of the comments could potentially be removed”.
| pub const fn is_ok(&self) -> bool { | ||
| matches!(self, Self::Ok { .. }) | ||
| match self { | ||
| Self::Run(response) => response.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.
What about calling response.is_successful() and !response.is_successful() below? Otherwise, can HookRunResponse::is_successful be deleted?
| } | ||
|
|
||
| impl PrePushRef { | ||
| #[must_use] |
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.
Why is this #[must_use]?
| oid.map_or_else(|| "0".repeat(40), |id| id.to_string()) | ||
| } | ||
|
|
||
| #[must_use] |
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.
Why is this #[must_use]?
| } | ||
|
|
||
| fn format_oid(oid: Option<Oid>) -> String { | ||
| oid.map_or_else(|| "0".repeat(40), |id| id.to_string()) |
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 about adding a comment explaining the else branch? (I now know why it’s this way, but I only know because I read the docs: https://git-scm.com/docs/githooks#_pre_push.)
| } = result | ||
| else { | ||
| let HookResult::Run(response) = result else { | ||
| unreachable!("run_hook should've failed"); |
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.
This message is not accurate anymore as the alternative to HookResult::Run is HookResult::NoHookFound. Other tests don’t have a message, so that’s also an option.
| ) | ||
| .unwrap(); | ||
|
|
||
| // Hook should succeed |
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 this comment be removed?
| .unwrap(); | ||
|
|
||
| // Hook should succeed | ||
| assert!(res.is_ok()); |
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.
Similar to other tests. I feel like assert_eq!(response.stdout, "…") would make this test’s intent more clear.
| hook, | ||
| ); | ||
|
|
||
| // Try to push master branch |
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 this comment be removed?
| ) | ||
| .unwrap(); | ||
|
|
||
| // Hook should reject |
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 this comment be removed?
| fn test_pre_push_hook_rejects_based_on_stdin() { | ||
| let (_td, repo) = repo_init().unwrap(); | ||
|
|
||
| // Create a hook that rejects pushes to master branch |
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 this comment be removed?
closes #2809