1

I installed Bonobo Git Server on Windows 2008 R2 Server machine. I created a repository and put post-receive.bat file in D:\Inetpub\Bonobo.Git.Server\App_Data\Repositories\REPO\hooks directory.

This is the content of the file:

#!/D/Inetpub/Bonobo.Git.Server/App_Data/Git/sh.exe

BINPATH="/D/Inetpub/Bonobo.Git.Server/App_Data/Git/"
REPOPATH="/D/Inetpub/Bonobo.Git.Server/App_Data/Repositories/REPO/"
GIT="${BINPATH}git"

# Change working directory to the repo root
cd $REPOPATH

read oldrev
read newrev
read refname

branch=$($GIT rev-parse --symbolic --abbrev-ref $refname)

if [ "master" == "$branch" ]; then
    echo "receive $branch $refname" >> "${REPOPATH}hookstest.log"
fi

If I execute this file from shell and type "whatever whatever master", then the file "receive master master" is added to hookstest.log. However, when I push changes to REPO the file is not updated, just as if it wasn't executed.

I have no idea where to look for errors that occurred. Most of the linux tutorials mention that the file must have +x flag. This obviously does not exist on Windows, but I checked and the user that runs Bonobo Git Server in IIS has execution rights on the batch file.

I was also hesitating about the name of the file, so I copied it and removed .bat extension. That did not help either. Any idea how I can get the hook working on the Windows Server?

EDIT

As suggested by @crashmstr I created a batch file (one with extension and one without) that contained:

date /t >> D:\Inetpub\Bonobo.Git.Server\App_Data\Repositories\REPO\testhooks.txt

This did not work either, even though the file was created, when I executed the file manually.

Michal B.
  • 5,676
  • 6
  • 42
  • 70
  • 1
    Try removing the `.bat ` extension. – Lasse V. Karlsen May 05 '17 at 12:01
  • Try reading till the end. That's where I wrote that I already tried that... – Michal B. May 05 '17 at 12:04
  • Unless that is being run by Git Bash or similar shell, windows won't run that (and certainly not as a batch file). You *may* need to write your hook using windows batch commands. – crashmstr May 05 '17 at 12:04
  • Related: [How to write Git Server Hooks on Windows platform?](http://stackoverflow.com/questions/29512578/how-to-write-git-server-hooks-on-windows-platform) – crashmstr May 05 '17 at 12:06
  • @crashmstr: I tried simple batch commands, but they did not get executed on push either (with or without extension). Regarding the related link. I tried that, but I am not sure if I understood the guy correctly. Anyway, still no results... – Michal B. May 05 '17 at 12:19
  • 1. Is it executable, like 777 or 755? 2. Is its name exactly `post-receive`? 3. Is it deployed at `.git/hooks/` of REPO to which you push your commits? – ElpieKay May 05 '17 at 12:41
  • @ElpieKay: as I said, it is on Windows machine, so I cannot change these flags. It is not at .git/hooks. In Bonobo Git Server it is by default in App_Data\Repositories\REPO\hooks – Michal B. May 05 '17 at 13:21
  • @MichalB. I think the flags could be changed via sh.exe. I use git for windows which has a bash shell. Sorry I don't know about the difference of git between win7/win10 and win 2008 server. – ElpieKay May 05 '17 at 15:09

2 Answers2

2

Using the latest version of Bonobo (a bit later than 6.1, but nothing in this area has changed), I have just created a file called 'pre-receive' in the hooks directory of the repo.

This file had no extension on the filename, and contained just the following:

#!/bin/sh
echo "xx" > here.txt

When I push a commit to this repo, the file "here.txt" is written to the top of the repo folder.

If this hadn't worked, then I would have run ProcMon from SysInternals, and set the path filter to include "here.txt" (and perhaps "pre-receive") and checked why these files were not being written / read.

Watching "here.txt" being written with ProcMon shows that it's being written by a copy of sh.exe which is in \App_Data\Git\sh.exe. I'm not quite sure who and what is getting from '#!/bin/sh' to \App_Data\Git\sh.exe but it seems to work.

Will Dean
  • 39,055
  • 11
  • 90
  • 118
  • I got it working. I think the problem with writing to a file was different, but I am not really sure why it was failing. Some other stack overflow post helped me. I will post the working file with all details tomorrow. – Michal B. May 06 '17 at 15:50
2

I am not sure what was the problem. In the end I got it working by creating a file D:\Inetpub\Bonobo.Git.Server\App_Data\Repositories\REPO\hooks\post-receive (no extension) with the following content:

#!/D/Inetpub/Bonobo.Git.Server/App_Data/Git/sh.exe

echo "BEGIN post-receive script"

APPPATH="/D/Inetpub/Bonobo.Git.Server/App_Data"
SVN="/D/csvn/bin/svn"

REPOPATH="$APPPATH/Repositories/REPO"
SVNSYNCPATH="$APPPATH/SVN-sync"
GIT="$APPPATH/Git/git"

mapping["master"]="trunk"
mapping["develop"]="development"

# Change working directory to the repo root
cd $REPOPATH

read oldrev newrev refname    

echo "oldrev - $oldrev"
echo "newrev - $newrev"
echo "refname - $refname"

branch=$($GIT rev-parse --symbolic --abbrev-ref $refname)
echo "branch - $branch"
echo ""

if [ "master" == "$branch" ]; then
    result=($($GIT diff $oldrev $newrev --name-status))
    echo "Detected $((${#result[@]}/2)) changes:"

    idx=0
    while [ $idx -lt ${#result[@]} ]
    do      
        status=${result[$idx]}
        filename=${result[$(($idx+1))]}
        echo -n "$status - $filename "

        case $status in
            "A")
                echo "added"
                ;;
            "M")
                echo "updated"
                ;;
            "D")
                echo "deleted"
                ;;
            "R")
                echo "renamed"
                ;;
            "C")
                echo "copied"
                ;;
            *)
                echo "unknown status"
                ;;
        esac

        idx=$(($idx+2))
    done
fi
echo ""

echo "END post-receive script"
Michal B.
  • 5,676
  • 6
  • 42
  • 70