Skip to content

Hook support - #4620

Open
tiennou wants to merge 4 commits into
libgit2:mainfrom
tiennou:feature/hooks
Open

Hook support#4620
tiennou wants to merge 4 commits into
libgit2:mainfrom
tiennou:feature/hooks

Conversation

@tiennou

@tiennou tiennou commented Apr 11, 2018

Copy link
Copy Markdown
Contributor

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

tiennou commented Apr 11, 2018

Copy link
Copy Markdown
Contributor Author

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

@pks-t pks-t left a comment

Copy link
Copy Markdown
Member

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?

Comment thread src/repository.c Outdated
Comment thread tests/hook/execute.c Outdated
Comment thread src/repository.c
Comment thread src/hook.c Outdated
Comment thread src/hook.c Outdated
Comment thread src/hook.c Outdated
Comment thread tests/hook/enumerate.c Outdated
Comment thread tests/hook/enumerate.c Outdated
Comment thread tests/hook/call.c Outdated
Comment thread src/rebase.c
}

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

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

tiennou commented May 18, 2018

Copy link
Copy Markdown
Contributor Author

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

tiennou commented Jun 3, 2018

Copy link
Copy Markdown
Contributor Author

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

tiennou commented Jun 3, 2018

Copy link
Copy Markdown
Contributor Author

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

tiennou commented Jun 10, 2019

Copy link
Copy Markdown
Contributor Author

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

ruant commented Oct 31, 2019

Copy link
Copy Markdown

Can we have this now?

@GXGOW

GXGOW commented Feb 5, 2020

Copy link
Copy Markdown

Is there any status update on this pull request?

@pks-t

pks-t commented Feb 5, 2020 via email

Copy link
Copy Markdown
Member

@extrawurst

Copy link
Copy Markdown

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

@extrawurst

Copy link
Copy Markdown

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

@ArekPiekarz

Copy link
Copy Markdown

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
Copy Markdown

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

@Pyenb

Pyenb commented Oct 10, 2024

Copy link
Copy Markdown

2024 and we're still here

@ethomson

ethomson commented Oct 10, 2024

Copy link
Copy Markdown
Member

@Pyenb What do you want hook support to look like? Are these the APIs that you want?

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.

9 participants