How does the git server hook obtain the commit information of the git client?
怪我咯
怪我咯 2017-05-17 10:03:16
0
2
829

There are three hooks on the git server side

pre-receive: 推送接受前
update: 推送更新中
post-receive: 推送接受后

I want to execute a script in post-receive and need to know the branch name pushed when the client pushes. However, after consulting a lot of information
, there is no mention of how the hooks script obtains client push information.

For example, git client a pushes some updates of branch hotfix1.2.3 to git server b. I want to execute a script in the hooks of git server b based on the branch name of this push behavior, which is hotfix1.2.3. . How to do it?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
PHPzhong

According to the content of the Server-side Hooks link, you can know that post-receive, like pre-receive, will get 3 parameters before execution:
<old-value> <new-value> <ref-name>

The script takes no parameters, but each ref that is being pushed is passed to the script on a separate line on standard input in the following format:
<old-value> <new-value> <ref-name>

b6b36c697eb2d24302f89aa22d9170dfe609855b 85baa88c22b52ddd24d71f05db31f4e46d579095 refs/heads/master

such as
b6b36c697eb2d24302f89aa22d9170dfe609855b 85baa88c22b52ddd24d71f05d b31f4e46d579095 refs/heads/master

ref-name和相应的hash值,就可以根据git相应的命令得到对应的信息.如git log refs/heads/master

So now that I know🎜.🎜
刘奇

https://git-scm.com/book/zh/v...

Different Hooks will carry different parameters in the input stream,

pre-receive
When processing push operations from the client, the first script to be called is pre-receive. It gets a series of pushed references from standard input. If it exits with a non-zero value, all push content will not be accepted. You can use this hook to prevent non-fast-forward updates to references, or to control access to all references and files modified by the push.

update
The update script is very similar to the pre-receive script, except that it will be run once for each branch to be updated. If the pusher is pushing content to multiple branches at the same time, pre-receive is only run once, in contrast to update, which is run once for each pushed branch. It does not read content from standard input, but takes three parameters: the name of the reference (branch), the SHA-1 value of the content pointed to by the reference before the push, and the SHA-1 value of the content the user intends to push. If the update script exits with a non-zero value, only the corresponding reference will be rejected; the rest will still be updated.

post-receive
The post-receive hook is run after the entire process is completed and can be used to update other system services or notify users. It accepts the same standard input data as pre-receive. Its uses include posting to a mailing list, notifying a continuous integration server, or updating a ticket-tracking system - you can even analyze commit information to determine whether a ticket is a problem. Should be turned on, modified or turned off. This script cannot kill the push process, but the client will remain connected until it finishes running, so use it with caution if you want to do anything else, as it will take you a long time.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template