Git hook for mirrored repo?

stack overflow post with my question

I’d like to add a hook to a mirrored repo - is there a way to do this? Or is there another workaround that can avoid webhooks?

Thanks!
Matt

I am not sure I understand, Gitlab repo mirror is to set sync between two VCS systems. You cannot setup GitLab repo mirror between GitLab and local clone.
If you have the mirror between GitLab and another VCS I don’t understand how could you “manually” run git pull there.

You might need to explain the setup properly.

In general you can just wirte a GitLab CI pipeline that will do what you want.

Thanks for your reply.

“You cannot setup GitLab repo mirror between GitLab and local clone.”

I was actually able to do this without issue. However when updates were made to the local clone no hooks were run.

Will look further into the CI pipeline. Am new to these so not sure if it will be able to do what I’m looking for: the hook I’d like to run runs a script to set file permissions for the files in the repo.


PS: It’s worth mentioning that you were right in that the clone did not work. The ‘local clone’ I mention above is not actually a clone in that it wasn’t created with git clone .... Instead I did:

git init 
git config receive.denyCurrentBranch updateInstead
git remote add origin ${REPO_PATH}
git pull origin master

You need to use Server-side hook, for your purpose I think post-receive is the one you need.

1 Like

Ah, brilliant!

Will give this a shot today.

Thank you.

Alas, my “local” copy of the repo is being updated as expected, but the post-receive hook does not fire. It’s chmodded/named correctly, and running git hook run post-receive works as expected.

Thanks again for your help.

I’ve managed to solve the problem with a CI/CD pipeline that rsyncs the files and then ssh’s to the remote server and runs the permissions update.