Githook problem

<oXygen/> general issues.
GHogarth
Posts: 16
Joined: Tue Aug 27, 2019 10:55 pm

Githook problem

Post by GHogarth » Tue Jan 07, 2020 11:42 pm

Has anyone worked with githooks as part of their commit to a github repo?
The following script works when I run it from Git BASH or a command window, but seems to be ignored when I commit from inside oXygen.

Code: Select all

#!/bin/sh
set -x

# In order to run this pre-commit hook the user will need the following setup
# 1. The DITA-OT command utility needs to be added to the path
#    In Windows, typically this path is: "C:\DEV\DITA-OT\dita-ot-3.4\bin"
# 2. Git needs to be installed on your computer. (https://git-scm.com/download/)
# 3. Run 'git config core.hooksPath .githooks' in the repo folder to add the Git symlink. 
#    There is no confirmation.
# 3. Run 'chmod +x .githooks/pre-commit' in the repo folder to add the Git symlink. 
#    There is no confirmation.

# Populate all the .DITA* files for this commit
ditafiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.dita*')

# Get the absolute path of the `.git/hooks` directory
export GIT_HOOKS=`cd "\`dirname "\\\`readlink "$0" || echo $0\\\`"\`" && pwd`

# Loop over the files, find their directory, and generate the README within that directory
for arg in $ditafiles; do
    BASE_DIRECTORY=$(echo "$arg" | cut -d "/" -f1)

    # Set the absolute path of the build directory
    export BUILD_FILES="$GIT_HOOKS/../$BASE_DIRECTORY"

    # Now that we have the base path to the project we can run the DITA command to generate that specific README
    dita --input=$BUILD_FILES/README.ditamap --format=markdown -Dchunk=to-content --output=$BUILD_FILES/docs/
done

# Exit with status of last command
exit 0

alex_jitianu
Posts: 733
Joined: Wed Nov 16, 2005 11:11 am

Re: Githook problem

Post by alex_jitianu » Thu Jan 09, 2020 10:40 am

Hello,

Are you by any chance on Windows? The Oxygen's Git plugin is based on the JGit library which does support Git hooks (well, not alll of them, but pre-commit is supported). If you are running on Windows though, you need to:

1. Install Cygwin. You'll need to nstall the Git packages in Cygwin too, because the hook scripts want to execute git command.
2. Add the Cygwin bin folder (e.g. cygwin64\system\bin) to the Windows PATH environment variable.


Best regards,
Alex

GHogarth
Posts: 16
Joined: Tue Aug 27, 2019 10:55 pm

Re: Githook problem

Post by GHogarth » Thu Jan 09, 2020 6:03 pm

Yes, Win 10. Thanks! :)

GHogarth
Posts: 16
Joined: Tue Aug 27, 2019 10:55 pm

Re: Githook problem

Post by GHogarth » Thu Jan 09, 2020 9:04 pm

Thanks Alex.
No luck.
I've installed cygwin, installed git in that, and set the Java_Home variable in the path (user path, not system path, if that makes a difference) Installed java version is 11.
Running the following in a Git Bash window works.

Code: Select all

git add . 
git commit -m "bash commit"
As this is basically the commands generated from the other code sample above, I'm stumped.

alex_jitianu
Posts: 733
Joined: Wed Nov 16, 2005 11:11 am

Re: Githook problem

Post by alex_jitianu » Fri Jan 10, 2020 5:28 pm

Hello,

I tried to use your script as a pre-commit hook, myself. I've started Oxygen from the command line launcher because I've noticed that if the pre-commit hook uses echo command then I will see its output inside Oxygen's console. When I committed from Oxygen, what appeared in the console was just this line:

Code: Select all

Buildfile: \cygdrive\d\projects\oxygen\frameworks\dita\DITA-OT3.x\build.xml does not exist!
I've noticed that the dita script has some logic to identify when it's being executed in cygwin context, but I can't actually say what it's doing in there. I've made another small test:
- the dita script was added in my path, like we've previously discussed
- I've started a cygwin console
- I've execute the command:

Code: Select all

dita --input=README.ditamap --format=markdown -Dchunk=to-content --output=docs/
I've received the same output:

Code: Select all

Buildfile: \cygdrive\d\projects\eXml\frameworks\dita\DITA-OT3.x\build.xml does not exist!
Error: Error: Build failed
So it would appear that the dita launcher doesn't work inside a cygwin environment... I will investigate it a bit more, but it might help if you also ask a question about running dita inside cygwin on dita-users@groups.io .


Best regards,
Alex

GHogarth
Posts: 16
Joined: Tue Aug 27, 2019 10:55 pm

Re: Githook problem

Post by GHogarth » Fri Jan 10, 2020 6:38 pm

Thanks. Query posted. Will let you know what I hear back.

Post Reply