About git getting flow parameters through the shell

Source: Internet
Author: User
Tags git hooks

When using Server-side git Hooks a while ago, you need to get git-submitted information, and here's a simple summary of how to get the parameters that git passes.

Git 传递参数 标准输入流 passes the submitted information in or out of the form.

Get parameter information

The git hooks update executable will be executed when it has been pushed, but not yet updated to the remote repository, to get the data pushed up and analyze whether to accept the push.

Git will pass three parameters and receive the following method:

1
2
3
4
5
#!/bin/sh

Refname="# The name of the ref being updated,
oldrev="# The oldobject name stored in the ref,
newrev="# and thenew object name to being stored in the ref.
Get standard input stream information

git hooks post-receive executables are executed after the entire push cycle is complete and are typically used for event notification.

Unlike update executables , git passes parameters to a file in the form of a standard input stream, with the post-receive following data format:

1
<old-value> sp <new-value> sp <ref-name> LF

The Receive method is as follows:

1
2
3
#!/bin/sh

Read OldValue newvalue RefName

Here three variables are used to receive the standard input stream parameters, if the parameter is more than three, starting from the third argument, all subsequent parameters will be assigned to the last refName variable.

Gets the status code returned

In the executable file, if it encounters exit <num> an exit execution, Git gets the exit status code, and if it does, 0 it accepts the commit, otherwise it refuses to commit.

The way to get the exit status is that the $? System.exit(0); exit status code is in Java.

Bash Special Variables Summary

variables meaning
$n Arguments passed to the script or function. N is a number that represents the first few parameters.
For example, the first argument is that the $1 second argument is $2 , greater than 9 is to be written as a${10}
$? The exit state of the last command, or the return value of the function
$# The number of arguments passed to the script or function
$$ The current shell process ID. For Shell scripts, the process ID where these scripts are located
$ File name of the current script
$* All arguments passed to the script or function, all parameters wrapped in a double quote"$1 $2 … $n"
[email protected] All parameters passed to the script or function, each of which is wrapped in double quotation marks"$1" "$2" … "$n"
$_ Last parameter of previous command
$! Process ID of the background command after execution

About git getting flow parameters through the shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.