Detecting source of a push in a pre-receive hook
From: Chris Packham <hidden>
Date: 2026-01-20 20:46:04
Hi Git, At $dayjob we're moving from a mix of plain git repositories on a server accessed via ssh with a secondary Gerrit server tacked on the side for code review to using the Gerrit server as the primary source of truth. So that people don't have to update origin.url for all their local repositories, we're using the Gerrit replication plugin to keep the old server in sync (and will likely do so for the foreseeable future). We have installed a pre-receive hook for the migrated repositories on the old server that rejects pushes from anyone except the user that the replication runs as. For various reasons we also have a CI system that pushes some things (mostly tags but some automated merge commits as well) that runs as the same user. We'd really like to be able to have the pre-receive hook reject pushes from the CI system but allow them from the Gerrit server. Does the pre-receive hook have any way of knowing the source of a push operation? Thanks, Chris