5

When using JGit do a push to remote which is on the same server.

1) if the remote was configured with file:// or /path/to/git/remote, the pre-receive hook won't be executed.

2) if the remote was configured with ssh://, the pre-receive hook will be executed.

If doing the same push using the Git command line, pre-receive hook will always be executed.

I don't understand why this is happening.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
foolhunger
  • 345
  • 2
  • 12

2 Answers2

1

JGit doesn't support all hooks; when you push via ssh: the remote server's git implementation is performing the git hook support. When you use JGit to push to a local repository it's just updating the local contents of the repository. (I'm not even sure if pushing to a local repository with a native git client will execute a pre-receive since it's not running git upload-pack and therefore not doing a receive.

AlBlue
  • 23,254
  • 14
  • 71
  • 91
  • 1
    pushing over file:// using native git client can trigger the pre-receive hook, while JGit won't – foolhunger Jul 13 '15 at 09:11
  • See [this bugzilla](https://bugs.eclipse.org/bugs/show_bug.cgi?id=299315) for how far hooks in JGit are implemented – Rüdiger Herrmann Feb 04 '16 at 09:57
  • As @foolhunger has said, when JGit pushes to local file remotes it seems the remote repositiory's pre-receive hooks aren't triggered. If you want to test hooks, you will have to set up a remote on a VM or another PC. You can add the remote via: `git remote add origin user@machine:/git-repo-dir` – patch May 23 '18 at 10:05
0

jGit has support for PreReceiveHooks, but you need to implement this hook - it is not read from hook directory.

https://download.eclipse.org/jgit/site/5.0.1.201806211838-r/apidocs/org/eclipse/jgit/transport/PreReceiveHook.html

MariuszS
  • 30,646
  • 12
  • 114
  • 155