gnustavo / Git-Hooks

Framework for implementing Git (and Gerrit) hooks
http://search.cpan.org/dist/Git-Hooks/
41 stars 17 forks source link

CheckWhitespace validates existing commits when pushing new branch #41

Closed boudekerk closed 7 years ago

boudekerk commented 7 years ago

Hi,

we're seeing issues with the CheckWhitespace plugin where it's validating existing commits, for example when pushing a new branch. See the following reproduction path: Create an existing commit:

HOOK=/data/git/bin/githooks.pl
CWD=$(pwd)
git init git-hooks-issue-remote
cd git-hooks-issue-remote
git checkout -b new-branch
cd ..
git clone file://${CWD}/git-hooks-issue-remote git-hooks-issue-local
cd git-hooks-issue-local
echo "Whitespace after this      " > README && git add README &&  git commit -m"Commit with trailing whitespace" README
git push

Set up the hook:

cd ../git-hooks-issue-remote/
git config --local --add githooks.plugin CheckWhitespace
ln -sf ${HOOK} ${CWD}/git-hooks-issue-remote/.git/hooks/pre-receive

Push a new branch:

cd ../git-hooks-issue-local
git checkout -b test-branch
git push -u origin test-branch

Expected result:

$ git push -u origin test-branch
Total 0 (delta 0), reused 0 (delta 0)
To file:///tmp/git-hooks-issue-remote
 * [new branch]      test-branch -> test-branch
Branch test-branch set up to track remote branch test-branch from origin.

Actual result:

$ git push -u origin test-branch
Total 0 (delta 0), reused 0 (delta 0)
remote: 
remote: [Git::Hooks::CheckWhitespace] whitespace errors in the changed files in refs/heads/test-branch:
remote: 
remote:   README:1: trailing whitespace.
remote:   +Whitespace after this      
remote: 
To file:///tmp/git-hooks-issue-remote
 ! [remote rejected] test-branch -> test-branch (pre-receive hook declined)
error: failed to push some refs to 'file:///tmp/git-hooks-issue-remote'

NB. In the past we reported a similar issue with the CheckJira plugin: https://github.com/gnustavo/Git-Hooks/issues/31

boudekerk commented 7 years ago

We also see this with merges, like in https://github.com/gnustavo/Git-Hooks/issues/26.

Let us know if you'd like us to create a separate issue and/or reproduction path.

gnustavo commented 7 years ago

Hi. I think I just fixed this on a9ce24a. I'll make a new release soon.

Thanks!

gnustavo commented 7 years ago

I just released v2.1.7. Please, check it out and tell me if it works for you.

boudekerk commented 7 years ago

Seems to work like a charm. Thanks!