rugged icon indicating copy to clipboard operation
rugged copied to clipboard

"object not found - no match for id" in pre-receive hook

Open JoyceBabu opened this issue 5 years ago • 1 comments

If I try to lookup the new commit hash from a pre-receive hook, I am getting the following error

object not found - no match for id

The lookup works correctly, when executed from the update hook.

But If I execute git show <new_hash> from the pre-receive hook, it is showing the diff.

I believe the following difference in the documentation for pre-commit and update hooksexplains why it is unavailable inpre-commit` hook.

pre-commit: Just before starting to update refs on the remote repository, the pre-receive hook is invoked.

update: Just before updating the ref on the remote repository, the update hook is invoked.

But still, why can't rugged access the received commit, even though the git executable is able to do it?

JoyceBabu avatar Apr 21 '20 17:04 JoyceBabu

Did anyone ever find an answer to this? It appears the git command line can access new objects in a pre-receive state but for some reason Rugged can't... I could really use a workaround.

EDIT: For visitors of the future, I found the solution thanks to the GitLab gitaly documentation on object quarantine. This should help you on your way:

alternates = []
alternates << ENV['GIT_OBJECT_DIRECTORY'] if ENV.key?('GIT_OBJECT_DIRECTORY')
alternates.concat(ENV['GIT_ALTERNATE_OBJECT_DIRECTORIES'].split(?:)) if ENV.key?('GIT_ALTERNATE_OBJECT_DIRECTORIES')
Rugged::Repository.bare(bare_path, alternates)

Multiple alternates are checked by Rugged in order until one is found containing the object. My env vars looked like this:

"GIT_OBJECT_DIRECTORY"=>"/var/opt/gitlab/git-data/repositories/@hashed/31/48/31489056e0916d59fe3add79e63f095af3ffb81604691f21cad442a85c7be617.git/./objects/tmp_objdir-incoming-wvkj1E",
"GIT_ALTERNATE_OBJECT_DIRECTORIES"=>"/var/opt/gitlab/git-data/repositories/@hashed/31/48/31489056e0916d59fe3add79e63f095af3ffb81604691f21cad442a85c7be617.git/./objects",

Rapsey avatar Mar 02 '25 03:03 Rapsey