Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send arguments from git push

Tags:

git

We're using a git post-receive hook to auto-minify our JS and sync our local and remote dev databases.

This is generally desirable, but occasionally not.

Is there anyway to pass an argument to the post-receive hook from git push so this can be disabled when required?

Thanks!

like image 424
Nicky Hajal Avatar asked Jul 08 '10 20:07

Nicky Hajal


People also ask

What is U flag in git push?

-u : The -u flag creates a tracking reference for every branch that you successfully push onto the remote repository. The local branch you push is automatically linked with the remote branch. This allows you to use commands such as git pull without any arguments.

When should I use git push?

git push is most commonly used to publish an upload local changes to a central repository. After a local repository has been modified a push is executed to share the modifications with remote team members.

What is the difference between push and commit?

Commit - committing is the process which records changes in the repository. Think of it as a snapshot of the current status of the project. Commits are done locally. Push - pushing sends the recent commit history from your local repository up to GitHub.


3 Answers

Git version 2.10 (released Sep 2, 2016) added --push-option to git push:

-o
--push-option

Transmit the given string to the server, which passes them to the pre-receive as well as the post-receive hook. The given string must not contain a NUL or LF character.

like image 181
Jonathon Reinhart Avatar answered Oct 05 '22 08:10

Jonathon Reinhart


If you keep the post-receive hook, you could decide to run the script based on the ref name of each file.

This hook [...] takes no arguments, but for each ref to be updated it receives on standard input a line of the format:

<old-value> SP <new-value> SP <ref-name> LF

where:

  • <old-value> is the old object name stored in the ref,
  • <new-value> is the new object name to be stored in the ref and
  • <ref-name> is the full name of the ref.

So you could check the branch name from the ref-name, and for some branches, decide not to run your script.

like image 24
VonC Avatar answered Oct 05 '22 06:10

VonC


I would do this in another way and keep one branch that has the receive-deploy action and another branch which does not.

like image 29
Daenyth Avatar answered Oct 05 '22 08:10

Daenyth