Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - post-receive not running on windows

I am running XAMPP server on my Windows Server 2008 R2. I am running Git 64bit version 2.16.1.windows.1 I would like to use post-receive hook to update my website after i do pa push from my client.

I created a bare project MyProject.git on server and cloned it to MyProject.

My hook is:

#!C:/Program\ Files/Git/usr/bin/sh.exe 
echo "Hook got triggered.." > hooks.txt
exec powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\hooks\post-receive.ps1"

Powershell script is:

cd "C:/xampp/htdocs/webapp/myProject/"
git pull origin master
exec git-update-server-info

I searched similar questions without any luck for solution of to problem.

If i run the script manually in powershell it runs ok. Based on my log the hook inst even firing.

The Git on Apache looks like it's configured correctly, because i can push to remote without problems and if i do a pull on the server in MyProject folder, the files that i get from repo are correct.

What am i missing?

EDIT:

I fixed my hook to:

#!C:/Program\ Files/Git/usr/bin/sh.exe
echo "Hook got triggered.."
exec powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\hooks\post-receive.ps1"

And my powershell script to:

cd "C:/xampp/htdocs/webapp/myProject/"
unset GIT_DIR
git pull origin master
exec git-update-server-info

Response when i push to remote is:

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 296 bytes | 296.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To http://git.mysite.com/myProject.git
  999aeb1..cf0df6f  master -> master

There is no "Hook got triggered.." response.

EDIT2: I chaneged my hook to:

#!C:/Program\ Files/Git/usr/bin/sh.exe
echo "Hook got triggered.."
cd "C:/xampp/htdocs/webapp/drajv-tecaj/"
unset GIT_DIR
git pull origin master

The script runs correctly if executed manually usin bash. But the script is still not running after i do a push on client.

EDIT3 Pasting my config for virtual host, that I'm pushing to:

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/webapp"
    ServerName git.mysite.com
    <Directory "C:/xampp/htdocs/webapp">
        Options +ExecCGI +Indexes +FollowSymLinks
        Require all granted
    </Directory>
    <Directory "C:/Program Files/Git/mingw64/libexec/git-core/">
        Require all granted 
    </Directory>
    SetEnv GIT_PROJECT_ROOT C:/xampp/htdocs/webapp
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git "C:/Program Files/Git/mingw64/libexec/git-core/git-http-backend.exe/"
    ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
                    info/refs | \
                    objects/(info/[Apache Git server on Windows^/]+ | \
                             [0-9a-f]{2}/[0-9a-f]{38} | \
                             pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                    git-(upload|receive)-pack))$" \
                    "C:/Program Files/Git/mingw64/libexec/git-core/git-http-backend.exe/$1"
</VirtualHost>
like image 719
Nomeaning25 Avatar asked Jan 30 '18 10:01

Nomeaning25


1 Answers

As seen in "git post-receive not working correctly", you would need to unset GIT_DIR for your pull to work correctly from within a hook.

cd "C:/xampp/htdocs/webapp/myProject/"
unset GIT_DIR
git pull origin master
exec git-update-server-info
like image 159
VonC Avatar answered Nov 04 '22 11:11

VonC