GIT ignores commit-msg hook - linux

Recently I migrated from opensuse to centos and after that GIT has started to ignore my custom commit-msg hook. It simply doesn't execute it. (I checked it by add small piece of code to "add_ChangeId" function )
Hook generates Change-Id hash for every commit
GIT version: 1.8.1.2
File is located in following location: .git/hooks/
For debugging purposes I even have set 0777 permissions to the whole .git directory
Here is the full text of commit-msg file - http://pastebin.com/zmYNi0ED

timoras you are gold. Then I tried to execute script using sh .git/hooks/scriptname it worked, but when tried to call it using .git/hooks/scriptname and shell returned that I haven't permissions to execute it.
After that I looked at fstab, and found out that have forgot to add exec flag to the partition where this file was located.
Now everything works.
One more time thanks timoras!

Related

Execute a script after every git push

There is a server running and has a git instance on it. I want a script to run everytime a user does git push to the server. I want my script to be executed then git push to continue.
Any work arounds?
You've tagged this GitHub so I'm assuming that you are referring to public GitHub and not GitHub enterprise.
You cannot run a script "server-side" on GitHub's servers because that would obviously be a massive vulnerability but you can set up a web hook to trigger a script on another server.
Basically whenever someone does a push, a specific URL will be sent data about the push. You can then trigger a script from this. For more information on web hooks, see the GitHub API docs.
I am not sure If you want a scipt to run prior to push or after. So here is my answer for pre-push. But if you want post-push (i.e after push) you have to change the pre-push hooks accordingly to check if pushed successfully and then you can do post push thing.
As suggested by #Travis, git hooks is the one that you are looking for. So to execute a script pre-push, you have to do is to create a pre-push file in the .git/hooks. So in this case put your bunch of code in the pre-post script file .git/hooks/pre-push and save it. Then make it executable by chmod +x .git/hooks/pre-push. After you done with this successfully you will be able to see the script gets executed each time you do run push command.
PS: Please note that I haven't tested this whole but expected to work in this way.
In Short, assuming you(Linux user) are in the project directory
vim .git/hooks/pre-push # then add your code and save the file
# Also put the shebang on top to identify the interpreter
chmod +x .git/hooks/pre-push # make it executable
You should look into git hooks:
8.3 Customizing Git - Git Hooks
and, another site regarding this technology:
githooks.com

Setting up and testing a pre-commit hook in SVN running on Linux machine which I access remotely

I'm gonna try to be as forthcoming as I can about my problem.
I'm on a Windows computer. The SVN repository is on a Linux machine.
I access the Linux machine remotely, using Putty and logging in as root. Everything is done through the command line.
Now, I have to set up a pre-commit hook that won't allow special characters like [éáú] on source code files. In order to do that, I set out to find out how to setup a pre-commit hook.
Here's what I've done:
Found a script
Went to the hooks folder in the repository. Removed the extension of the file pre-commit.tmpl
Pasted the script there and saved
Ran the chmod command on file pre-commit.tmpl
Then I tried commiting a change to the repository and I got:
Commit blocked by pre-commit hook (exit code 255) with no output
Alright, I figured something was wrong in how I set up the pre-commit file, so I removed the script and added a simple echo "hello world".
Now the commit goes through, but the echo message doesn't show up at all. If I put exit 1 at the end of the script, I get error code 1 and the echo message still doesn't show up.
I have literally searched high and low on the internet and have found no solution to my problem.
What I need:
An explanation as to why the echo messages are not showing up
If possible, a step-by-step on how to set up and test a simple script
For example, I've seen a lot of scripts where there's something like this:
#!/bin/bash
REPOS="$1"
TXN="$2"
What am I supposed to put in REPOS and in TXN? I assume in REPOS I should put the repository path? What about TXN?
Any help is appreciated.
Cheers
Billet of the pre-commit hook (*Nix-adopted)
Always failing
#!/bin/bash
echo You failed 1>&2
exit 1
commit sample
>svn commit -m "Changes"
Sending Folder1\Folder2\Folder3
Sending Folder4
svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
You failed
Note correct redirection of output in echo
About $REPO and $TXN (already linked) SVN Book chapter have full explanation
The command-line arguments passed to the hook program, in order, are:
Repository path
Commit transaction name
because these parameters are needed for most often used in pre-commit hooks commands, like svnlook

How to make current directory a git working directory

I've written multiple *.cpp files in the location ~/Code/CPLUS before I know the existence of git.
Now I want to use git for version control.
I created a folder ~/git_repo/, and in this folder, I ran git init command. When I tried to run the command git add my_first_c.cpp under the path ~/Code/CPLUS, the following message appeared:
fatal: Not a git repository (or any of the parent directories): .git
Then I typed git init ~/git_repo/ under the path ~/Code/CPLUS, the same error still appeared when git status was typed.
If I type git init under the path ~/Code/CPLUS, the add and commit can be executed. The only problem is that .git is stored in ~/Code/CPLUS/, while I'd like it be stored in ~/git_repo.
My question is how to make the folder ~/Code/CPLUS a working directory while the repo info is stored in ~/git_repo/? And my machine has no GUI.
You could try exporting the variables export GIT_WORK_TREE=~/git_repo/ and export GIT_DIR=../Code/CPLUS from terminal (or in your ~/.bashrc) so Git uses these.
Thanks #Alariva , the suggested solution indeed solved this question. With .git created in ~/git_repo/, typing git --git-dir=/abs/path/to/repo/git_repo/.git add my_first_c.cpp works.
The solution comes from this post.

Autorun Bash Script after Login to Sync Git Repos

I have already a gitupdate.sh that I found on the internet.
My problem now is how to make the script run automatically every time I log into my Ubuntu 14.04 computer.
I have tried adding this line to .bashrc
sh '/path/to/git/repo/gitupdate.sh'
The problem here is the script is executed not in the context or path of the repo thus the script runs in a folder that is not initialized with git. (I don't actually know what folder bashrc run on)
What want to do is that the update script to be run by Ubuntu in the context of the path so the script will not fail. And also show the running script in a Terminal window that will not automatically close.
And the ultimate goal, is to be able automatically upon login, that git cloned repos to be synced with the public repos.
Try
(cd repo && bash /path/to/gitupdate.sh)
Just open the gitupdate.sh and at the beginning of the file just add the command to go to the selected direcotry. For example:
cd /var/test

gitolite hook after git push doesn't work

I tried to search to find a solution.
but, I can't.
I installed gitolite. And it works well.
I can git clone on the local machine, and change gitolite-admin repo too.
But I want to use gitolite hooking.
followed this manual
http://sitaramc.github.com/gitolite/hooks.html
custom hooks
You can supply your own, custom, hook scripts if you wish. Install
gitolite as usual, then:
go to ~/.gitolite/hooks/common on the server and put your new hook
there now run "gl-setup" again You can use this procedure to install
new hooks as well as to update hooks that you had previously
installed.
So I tried to hook some basic shell script.
I put bash shell script on
~/.gitolite/hooks/common
and named it
update
update script file's owner is git, and excutable.
the shell script is like this..
#!/bin/bash
touch /tmp/$GL_REPO
and I execute
gl-setup mypubkey.pub
and then,
On my local git folder,
I modified some file, commit and push to gitolite server.
push works well. every file uploaded to the gitolite's repo.
but, hooking doesn't seems to occur. Nothing happened.
on the server's tmp directory, no file is created.
Did I forget something?
any comments plz...
You should realize that (from the "using hooks" page you mention in your question=:
The update hook is used in all repos and is critical to gitolite's access control
In other words, you cannot directly use an "update" script.
You must use the "hook chaining" feature of gitolite, in order to call your own update hook after the one of gitolite:
To run your own 'update' hook, just put it in a file called update.secondary and install it as a hook.
Gitolite's update hook will automatically chain to it, taking care to pass it the same 3 arguments the original update hook received from git.
In the end, the OP Jinbom Heo, rather than using "gitolite hook chaining", went with another hook:
I put post-receive file in /var/gitolite/hooks/common/ folder. And it works.
The doc "Where do I put my hooks" suggest rather to put those under the "user" location (~/.gitolite/hooks/common):
But the system location works too.
( /var/gitolite/hooks/common/ means, by the way, the OP chose the root method installation or the package one, with the default paths /usr/local/bin, /var/gitolite/conf, /var/gitolite/hooks)

Resources