gitx / gitx

The best fork of the best lightweight, visual git client for macOS.
Other
805 stars 76 forks source link

gitx appears to ignore pre-commit hook when git configured for a different core.hooksPath #228

Open stepheneb opened 3 years ago

stepheneb commented 3 years ago

Am using gitx built from the latest commit on the master branch: https://github.com/gitx/gitx/commit/d0bddcc47

I setup a git pre-commit hook to check for occurrences of debugger statements in javascript.

When this pre-commit hook is located in the default location: .git/hooks/pre-commit it runs properly in both gitx and the git cli.

I wanted to keep track of the git hooks in a directory managed by git so I moved the pre-commit hook here: .githooks/pre-commit.

I then set the git configuration to use that new directory:

$ git config core.hooksPath .githooks

The pre-commit hook is run correctly when using the git cli.

However no warning is now displayed when committing a javascript file with a debugger statement using gitx.

Am not yet sure if this is a bug in gitx or one of the libraries it pulls in.

Any tips on where to look for this bug are welcome.

The repo where this occurs: https://github.com/stepheneb/cfa-own-electron (this is a large repo). If helpful I can create a minimal repo to demonstrate the issue.

file: .githooks/pre-commit

#!/bin/sh

FILES='(js)'
FORBIDDEN='(debugger)'
GREP_COLOR='4;5;37;41'

if [[ $(git diff --cached --name-only | grep -E $FILES) ]]; then
  git diff --cached --name-only | grep -E $FILES | \
  xargs grep --color --with-filename -n -E $FORBIDDEN && \
  printf "\nLooks like you are trying to commit something you shouldn't.  Please fix your diff, or run 'git commit --no-verify' to skip this check, if you must." && \
  exit 1
fi

exit 0
stepheneb commented 3 years ago

My notes investigating the issue:

This section of code: https://github.com/gitx/gitx/blob/master/Classes/git/PBGitIndex.m#L356-L381

Includes:

BOOL success = [self.repository executeHook:@"pre-commit" error:&error];

executeHook is defined here: https://github.com/gitx/gitx/blob/master/Classes/git/PBGitRepository.m#L1118-L1181

Is there other existing code that reads from an existing git configuration file that I could adapt to use here?

hannesa2 commented 2 years ago

I'm happy to approve a pull request when you'll create one

brian-watkins commented 2 years ago

I submitted a fix for this in #307.