top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

GIT Pre-push hook error

+1 vote
402 views

I am trying to write a pre-push git hook to check the validity of a JIRA issue in perl . pre-push perl script executes fine and i get a desired output when the perl script is executed through the windows command prompt .
However , executing git command " git push origin master" to invoke the pre-push hook results in an error " illegal division by zero in warnings.pm" . Any clue on the behavioural difference when the script is executed via windows command prompt versus when invoked by GIT push command.

posted Jul 8, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
What line number is reported in the error message?what are the exact contents of your warnings.pm? (Is there more than one "warnings.pm" file on your system?)

1 Answer

0 votes

Supposedly, when a hook script is executed by Git, it's being run using a port of a POSIX shell, bash, and not Windows shell (cmd.exe) -- hence I imagine there might be behavioral differences:
* Different environment.
* Git comes with its of minimal Perl installation, so if you have another one installed (like ActiveState Perl or Strawberry Perl etc), the latter might be picked when you perform your trial runs while the former is used by Git when running your hook.
* Push hooks run with the same credentials Git process serving the push operation is using; these might well be different from those you're logged in with while developing.

Where to go from there -- try to re-create as close an environment to that seen by your hook when it's being spawned by Git:
* Do your trial runs using Perl which comes with Git itself
* Do that in that "Git bash" window (accessible via the Git's Windows Start Menu entry) rather than in cmd.exe.
* Run Git bash with the same credentials used by your Git server process. If it runs with the LOCAL SYSTEM credentials, one trick to get the shell with appropriate credentials is to run psexec -s ... (available as part of the Sysinternals package).

answer Jul 8, 2013 by anonymous
Similar Questions
+2 votes

In coreboot we try to check for whitespace errors before committing. Of course a pre-commit hook is the way to go, but unfortunately it is not so simple (at least for me) as the following requirements exist.

  1. Only the files actually committed should be checked. That means running git commit -a, abort that and then running git commit some/file should only check some/file for whitespace errors.

  2. There are certain files that are allowed to have whitespace errors. In our case these are *.patch and *.diff files which by design seem to contain whitespace error.

Currently the whole tree is checked, which takes a lot of time. I tried to come up with a patch, but failed so far. Best would be to have

$ git diff --check --only-committed-files --exclude "*patch$"

where I could not find a way for the last to switches.

Currently, I would use

$ git diff-index --cached --name-only $against -- | grep -v patch$

and pass that list to some whitespace check program. Unfortunately that still does not fulfill the first requirement. What am I missing to solve this elegantly?

+5 votes

I read this page about git hook: http://git-scm.com/book/en/Customizing-Git-Git-Hooks and I still have some questions. I have a git server with some bare repos and I want create something like a continuos integration test so, I need to run a script when someone push on these repos. Main problem is that these repos are "bare" and doesn't contains any file. there is a way inside my script to "extract" files from a bare repo or i need to create a working copy?

If i create a separated working copy, how can i pull out this working copy inside my script? I tried something like this, but seems not working
cd /home/git/workingcopy/myawesomeappgit pull./run_test.sh

+1 vote

I'm using git 1.9.1 in Ubuntu 14.04.

I have a repository on github, a clone on my desktop and bare repo on a private server, in my desktop the remotes looks like this

all git@github.com:user/repo.git (fetch)
all git@github.com:user/repo.git (push)
all user@server.com:user/repo.git (push)
server user@server.com:user/repo.git (fetch)
server user@server.com:user/repo.git (push)
origin git@github.com:user/repo.git (fetch)
origin git@github.com:user/repo.git (push)

If I commit to master in my desktop and run 'git push all master', the github and the server repos are correctly updated, but if I run 'git status' the message says:

Your branch is ahead of 'origin/master' by 1 commit.
 (use "git push" to publish your local commits)

The message won't update unless I run git fetch or git push origin master. I'd expect the git status to give me a updated status message after calling 'git push all master'.

+1 vote

I wanted to avoid push if any of the files is deleted from the local git clone area. Can anyone please help me with that?

I am using Stash for repository management.

...