githooks

getting “fatal: not a git repository: '.'” when using post-update hook to execute 'git pull' on another repo

偶尔善良 提交于 2019-11-27 06:20:13
I'm new to git so I apologize (and please correct me) if I misuse terminology here, but I'll do my best. I'm trying to set up a bare git repo (hub) and a development site working copy (prime) on a web server. I've tried to pattern it after this article . I want the development working copy to be updated whenever the hub repo is pushed to. I'm under the impression that the proper hook for this is post-update , which I have created like so: #!/bin/sh whoami cd /path/to/working-copy/ RET=`git pull` echo $RET Update When I push changes from my local repo to the bare hub I get the following output

git: empty arguments in post-receive hook

拜拜、爱过 提交于 2019-11-27 05:47:06
问题 I'm writing post-receive hook basing on the post-receive-email script from the contrib dir, but it seems that the oldrev and newrev arguments are empty. The script looks like this: #!/bin/bash oldrev=$(git rev-parse $1) newrev=$(git rev-parse $2) The script runs on push, but all $1 , $2 , $oldrev and $newrev are empty. Should I configure something to get it running? (The repository was created by gitolite if it does matter) 回答1: The post-receive hook doesn't take any arguments. Quoth the

update package.json version automatically

与世无争的帅哥 提交于 2019-11-27 04:57:39
问题 Before I do a small release and tag it, I'd like to update the package.json to reflect the new version of the program. Is there a way to edit the file package.json automatically? Would using a git pre-release hook help? 回答1: npm version is probably the correct answer. Just to give an alternative I recommend grunt-bump. It is maintained by one of the guys from angular.js. Usage: grunt bump >> Version bumped to 0.0.2 grunt bump:patch >> Version bumped to 0.0.3 grunt bump:minor >> Version bumped

How to capture a git commit message and run an action

一个人想着一个人 提交于 2019-11-27 04:29:01
问题 I'm new to git and I want to be able to capture the commit message after a push to the origin/master and run a bash script (on the server) based on what the string contains. For example, if my git commit message says: [email] my commit message If the commit message contains [email] then do a specified action, otherwise, don't do it. Here's a sample bash script I'm thinking of using in the post-receive hook: #!/bin/bash MESSAGE= #commit message variable? if [[ "$MESSAGE" == *[email]* ]]; then

why it is not possible to git add .git/hooks/my-hook

谁说胖子不能爱 提交于 2019-11-27 03:52:11
问题 I would like to have some hooks always present in a clone of a given repository. Is there a way to add a file in .git/hooks in the repository? Thanks 回答1: It is possible to define your own hooks in a git template , but even there, those hooks would be non-executable ones. I.e. the user would still have to activate them (rename or activate the executable bit) once the repo is cloned. That way, said user won't have any unwanted script executed without his/her full knowledge and explicit

Can a Git hook automatically add files to the commit?

不问归期 提交于 2019-11-27 03:19:22
I'd like to add an automatically generated file to the same commit using a pre- or post-commit hook in Git, dependent on the files that were modified in that commit. How would I go about this? I've tried this as a pre-commit hook, but no luck: #!/bin/sh files=`git diff --cached --name-status` re="<files of importance>" if [[ $files =~ $re ]] then echo "Creating files" exec bundle exec create_my_files exec git add my_files exec git commit --amend -C HEAD fi This successfully adds them to the repository, but does not add them to the commit. I've also tried using the last two exec lines in a post

Validate if commit exists

为君一笑 提交于 2019-11-27 03:16:22
问题 How to validate whether the commit with given sha exists in current branch? There are many ways to parse outputs, but I need optimal way which returns boolean (for usage in bash script). e.g. sha=$1 if [ -z `git magic --validate $sha` ]; then echo "Invalid commit sha: $sha" exit 1 fi 回答1: The rev-list | grep method works fine; there's the tiniest bit of overhead because git has to print out all the SHA1s for grep to see, but it's not really a big deal. You can also do it with git merge-base

Git push error pre-receive hook declined

余生颓废 提交于 2019-11-27 03:14:31
I have run gitlabhq rails server on virtual machine, following 1-6 steps from this tutorial https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md and starts rails server executing command sudo -u git -H bundle exec rails s -e production . After that I created user, using admin tools and created new project under this user. Then I'm trying to push the existing project to this repo as always. But in the last step, git push origin master fails with the error [remote rejected] master -> master (pre-receive hook declined) Additional info: 1) I haven't activated user

How to run post-receive hook on GitHub

大城市里の小女人 提交于 2019-11-27 01:20:06
问题 how to run a post-receive hook in GitHub?. I know that there is the web-one but I want to write a custom script and do not want to receive a post from github. 回答1: The post-receive hook of Github are actually only "WebHooks" , to communicate with a web server whenever the repository is pushed to. For security reason, you cannot run anything on the GitHub server side. When a push is made to your repository, we'll POST to your URL with a payload of JSON-encoded data about the push and the

How to execute a command right after a fetch or pull command in git?

Deadly 提交于 2019-11-27 00:43:12
问题 I cloned the GHC (Glasgow Haskell Compiler) repository. In order to build the compiler, you need several libraries, all of them are available as git repositories too. In order to ease ones live, the GHC hackers included a script sync-all that, when executed, updates all the dependent repositories. Now to my question: How can I make git execute ./sync-all pull after I did a git pull automatically? I heard something about using hooks, but I don't really know, what I have to do. 回答1: If you need