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

Hook support #4620

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Hook support #4620

wants to merge 4 commits into from

Conversation

tiennou
Copy link
Contributor

@tiennou tiennou commented Apr 11, 2018

This is a heavily redacted version of #3824, since it's been 2 years in the making and much has changed (like nice commit headers). Most of the design comes from the discussion there, so you might want to take a look.

The plan is to have a low-level API for hook execution (because as a library, we don't want to go anywhere near fork/exec/the Windows way), so we can instead ping "userspace" that we expect them to execute something with carefully prepared arguments. On top of that comes a somewhat higher-level API so that users should just need to call a single function with some of their current working objects and we'll translate those to one of those low-level "pings".

Note that's there a feature/hooks-wip branch, which is even more WIP than this one, where I'm adding easy-to-use helpers for the various hooks.

EDIT Tentative support plan :

  • applypatch-msg, pre-applypatch, post-applypatch: no git-am.
  • pre-commit, prepare-commit-msg, commit-msg, post-commit: our "commit workflow" doesn't match git.
  • post-checkout: the "normal checkout" looks like a "no matching workflow" too, as our checkout doesn't work on references, but directly on HEAD/index/tree. The "clone checkout" looks ok though.
  • post-merge: no git-pull.
  • pre-push: looks ok-ish.
  • pre-receive, update, post-receive, post-update, push-to-checkout: no git-receive-pack.
  • pre-auto-gc: no git-gc.
  • post-rewrite: looks ok-ish.

@tiennou tiennou mentioned this pull request Apr 11, 2018
@tiennou
Copy link
Contributor Author

tiennou commented Apr 11, 2018

Editor's note : I should really have those .h files reversed.

Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tiennou for being persistent with hook support.

Do you have an overview of hooks other than pre-rebase, whether we can properly implement them with semantics matching git's?

src/repository.c Outdated Show resolved Hide resolved
tests/hook/execute.c Outdated Show resolved Hide resolved
src/repository.c Show resolved Hide resolved
src/hook.c Outdated Show resolved Hide resolved
src/hook.c Outdated Show resolved Hide resolved
src/hook.c Outdated Show resolved Hide resolved
tests/hook/enumerate.c Outdated Show resolved Hide resolved
tests/hook/enumerate.c Outdated Show resolved Hide resolved
tests/hook/call.c Outdated Show resolved Hide resolved
@@ -718,6 +719,11 @@ int git_rebase_init(
branch = head_branch;
}

if (!inmemory && upstream) {
if ((error = git_hook_call_pre_rebase(repo, upstream, (head_ref == NULL ? branch : NULL))) < 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to check for < 0 here? Usually, return codes from exec'd programs are always positive in the range from 0 to 255, where non-zero positive values denote an error. So in case the callback simply exec's the hook and returns its value, we will not detect that error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm defaulting to the libgit2 convention. Right now the expectation is that the executor will bubble a GIT_* error, not the underlying exec return value.

@tiennou
Copy link
Contributor Author

tiennou commented May 18, 2018

There's context about what can be matched to our API/workflow/implementation-level here, which I've moved in this PR's summary.

Also, someone recently asked about merge drivers in OCGit libgit2/objective-git#656, and this made me wonder about that exec support…

@tiennou tiennou force-pushed the feature/hooks branch 2 times, most recently from 7bfe136 to 4632523 Compare June 3, 2018 23:40
@tiennou
Copy link
Contributor Author

tiennou commented Jun 3, 2018

Review comments handled. Note that I've moved the WIP commit hook support in, but it's really WIP. If someone has a better idea for wrapping prepare-commit-msg (and it's variable 5 arguments + command line flags + some repo state) that does not entails having 5 different functions, I'm 👂…

About this :

Do we really want to check for < 0 here? Usually, return codes from exec'd programs are always positive in the range from 0 to 255, where non-zero positive values denote an error. So in case the callback simply exec's the hook and returns its value, we will not detect that error.

It all depends on how I specify the valid return codes from the executor. My preference goes to keeping the libgit2 convention, which would make the executor responsible of not breaking us by returning positive error codes.

@tiennou
Copy link
Contributor Author

tiennou commented Jun 3, 2018

Note that I've swapped functions around, so the low-level execution is in git2/sys/hook.h and the easy-to-use stuff in git2/hook.h.

Editor's note: document that git_hook_execute's arguments must be NULL-terminated 😜.

@tiennou tiennou force-pushed the feature/hooks branch 3 times, most recently from b62ad25 to 2d6b7d6 Compare June 10, 2019 19:39
@tiennou
Copy link
Contributor Author

tiennou commented Jun 10, 2019

Rebased, and updated. I've closed all review comments that seemed to have been resolved, and thus I'm dropping the WIP from it, as I feel it's a sufficient first step to merit inclusion, on the off-chance that it's acceptable to not have all current hook "helpers" wired yet.

@tiennou tiennou changed the title [WIP] Hook support Hook support Jun 10, 2019
@ruant
Copy link

ruant commented Oct 31, 2019

Can we have this now?

@GXGOW
Copy link

GXGOW commented Feb 5, 2020

Is there any status update on this pull request?

@pks-t
Copy link
Member

pks-t commented Feb 5, 2020 via email

@extrawurst
Copy link

Now that 1.0 shipped, can we consider this PR? That would be amazing 🤞

@extrawurst
Copy link

Also wondering what keeps us from considering this now post-1.0

@ArekPiekarz
Copy link

I am also very interested in being able to support precommit hooks in my application using libgit2 (Rust version to be specific). What is the state of work on them?

@Whirlwind
Copy link

From 2018 to 2021, I can't wait. ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants