-->

Can I send out of band data along with a commit?

2019-05-01 06:36发布

问题:

I wish to integrate a remote git repository with an RTC server, by using their RESTful interface to attach a link to gitweb for a commit associated with a particular task.

Ideally this will be done with a post-receive hook on the git server, but the processing user that git runs as is not allowed a user account to authenticate to RTC.

The best solution I can think of is to somehow pass an authentication token (Acquired from RTC in the form of cookies.txt) along with the git push (But not have it part of the commit).

The alternative would be a post-push hook on each client repository but that has its own problems (Including that there is no such hook).

回答1:

With git version 2.10 and higher, you can use git --push-option <string> to pass the given string value to the server, which passes them to the pre-receive as well as the post-receive hook. git push documentation.

The number of push options given on the command line of git push --push-option=... can be read from the environment variable GIT_PUSH_OPTION_COUNT, and the options themselves are found in GIT_PUSH_OPTION_0, GIT_PUSH_OPTION_1,…​ If it is negotiated to not use the push options phase, the environment variables will not be set. If the client selects to use push options, but doesn’t transmit any, the count variable will be set to zero, GIT_PUSH_OPTION_COUNT=0.git hook documentation