0

I have a Bonobo git server installed on a Windows Server 2016. It is deployed in IIS and accesible on url myserver/git. Next I want to enaeble automatic deployment. In the Git Server bare repository folder I find the hooks folder and add a post-receive script:

#!/bin/sh
cd E:/public/root/myFirstRepo
git pull

This works fine when I run it as my personal user. But when its used by IIS after a commit it gives:

git: 'pull' is not a git command. See 'git --help'.

Am I using the correct git?

#!/bin/sh
git --exec-path

Personal user: C:\Program Files\Git\mingw64/libexec/git-core

IIS user: /libexec/git-core

So lets change the script to use an absolute git path:

#!/bin/sh
cd E:/public/root/myFirstRepo
"C:/Program Files/Git/mingw64/libexec/git-core/git" pull

fatal: Not a git repository: '.'

This might be because im already in a git repo, namely the bare server repo and it might confuse git? So lets try to ignore any present enviroment.

#!/bin/sh
cd E:/public/root/myFirstRepo
env -i "C:/Program Files/Git/mingw64/libexec/git-core/git" pull

However this seems to break git bash for windows:

error: cannot spawn sh: No such file or directory

Ok, so lets try and use the git -C flag: explicity saying what folder to operate on.

#!/bin/sh
"C:/Program Files/Git/mingw64/libexec/git-core/git" -C "E:/public/root/myFirstRepo" pull

Still:

fatal: Not a git repository: '.'

At this point im out of ideas. My question is basically: How to properly set up a git server post-recieve script in windows enviroment?

  • You already have a cloned repo at E:/public/root/myFirstRepo, don't you? – niglesias Jul 3 '17 at 19:38
  • Yes and git pull works in that repo when running as my personal user – Anders Jul 4 '17 at 11:48
  • And where is your Git Server bare repository folder? – niglesias Jul 5 '17 at 18:12
  • E:/public/custom/bonobo.git.server/Repositories/... – Anders Jul 6 '17 at 7:43
0

I was attempting to do the same thing on a Windows 2012 instance. After working on it for a while I was able to get the post-receive hook to update a local repository. Assuming you have Bonobo Git server and Git installed, here are the steps. I used the paths from the initial post.

  1. Create the local repo with git clone http(s)://username:password#myserver/Bonobo.Git.Server/.git

you need to include a username and password so it's stored locally. This will be necessary for the hook operations. It's a bit of a security issue, but I assume this server won't routinely be accessed outside the admin.

  1. Add the IIS_IUSRS account to the newly created git repository. Right click the directory and add the user account. Give it write permission. I actually gave full control.

  2. Create the post-receive file (no extension) in the hooks directory for the repository. Use the correct path to Git executable, not the Bonobo Git.

!/Git/sh

cd E:\public\root\myFirstRepo\

"c:\Program Files/Git/mingw64/libexec/git-core/git" --git-dir=E:\public\root\myFirstRepo\.git stash

"c:\Program Files/Git/mingw64/libexec/git-core/git" --git-dir=E:\public\root\myFirstRepo\.git pull

There will be a few warning initially, but once you push files to the remote server, the hook script should update them accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.