christiangalsterer/stash-filehooks-plugin

File hook plugin prevents new local branches to be pushed to the remote

Closed this issue · 6 comments

Hello,

The File Hooks Plugin version 3.0 is preventing new local branches to be pushed to the remote if the file name and/or file size hook are enabled:

git push -u origin feature/syee_local_branch_test
Total 0 (delta 0), reused 0 (delta 0)
remote: Communication breakdown with Bitbucket.
To ssh://dev-bitbucket/test/syee_test_repo_3.git
! [remote rejected] feature/syee_local_branch_test -> feature/syee_local_branch_test (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@dev-bitbucket/test/syee_test_repo_3.git'

If the File Name and File Size Hooks are disabled, the push succeeds:

git push -u origin feature/syee_local_branch_test
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create pull request for feature/syee_local_branch_test:
<cut>

Sylvia

Can you please share the configuration of the hook and also the relevant parts of the Bitbucket log file.
Which version of BB are you using?

Does the new commit contain changes which match the hook configuration or have you just created a new branch but without actual changes, but where a previous commit would match the configuration? In the latter case this might be than the same as #1.

File Hook Plugin version 3.0
Bitbucket Server version 5.1

The error is seen:

  • if the new branch has no commits
  • if the new branch has commits:
    ** has changes that does not match the hook configuration
    ** has changes that does match the hook configuration

Created a new repository, added a new file and pushed the changes.
Setup the following hooks (note that the error occurs if there is at least one file hook plugin enabled):

  • File Size Hook Enabled: Include .*txt Size: 10
  • File Name Hook Enabled: Inlcude .*png

In my local workspace:

Test 1: Commit changes does not match the hook configuration

  • Create a new branch
  • Create file foo.bar and push

git push --set-upstream origin feature/syee_no_match
Counting objects: 3, done.
Delta compression using up to 24 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 276 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Communication breakdown with Bitbucket.
To ssh://dev-bitbucket/test/syee_test_repo_4.git
! [remote rejected] feature/syee_no_match -> feature/syee_no_match (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@dev-bitbucket/test/syee_test_repo_4.git'

Logs attached no_match_log.txt

Test 2: Commit changes matches the hook configuration

  • Create a new branch
  • Create file foo.txt and push
    git push --set-upstream origin feature/syee_yes_match
    Counting objects: 3, done.
    Delta compression using up to 24 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 273 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    remote: Communication breakdown with Bitbucket.
    To ssh://dev-bitbucket/test/syee_test_repo_4.git
    ! [remote rejected] feature/syee_yes_match -> feature/syee_yes_match (pre-receive hook declined)
    error: failed to push some refs to 'ssh://git@dev-bitbucket/test/syee_test_repo_4.git

Logs attached yes_match_log.txt

Thanks for sharing the detailed information. I was trying to reproduce this but without luck.
Looking at the stack trace and where the exceptions occur, it looks like a little bit that you repository is corrupt in some way and/or some history rewriting tock place.

Can you try with a different/new repository as well to see if it happens there as well?

I created a new repository and was able to reproduce the issue when pushing a new branch with commits to the upstream.

Test Details

Bitbucket Server v5.1.0
File Hooks Plugin v3.0.0
File Size Hook Enabled: Include .*txt Size: 10

Test 1: Commit changes on new branch matches the hook configuration

  • Create a new branch
  • Updated hello.txt to exceed the file size limit
  • Push the new branch and file to the upstream. Receive error:
    remote: Communication breakdown with Bitbucket.
    To ssh://dev-bitbucket/test_project/syee_test_filehook_plugin.git
    ! [remote rejected] feature/syee_match_1 -> feature/syee_match_1 (pre-receive hook declined)
    error: failed to push some refs to 'ssh://git@dev-bitbucket/test_project/syee_test_filehook_plugin.git'

Log file match_log.txt

Test 2: Commit changes on new branch does not match the hook configuration

  • Create a new branch
  • Create file world.sh
  • Push the new branch and file to the upstream. Receive error:
    remote: Communication breakdown with Bitbucket.
    To ssh://dev-bitbucket/test_project/syee_test_filehook_plugin.git
    ! [remote rejected] feature/syee_nomatch_1 -> feature/syee_nomatch_1 (pre-receive hook declined)
    error: failed to push some refs to 'ssh://git@dev-bitbucket/test_project/syee_test_filehook_plugin.git'

Log file nomatch_log.txt

Thanks!

ar613 commented

This problem didn't exist in Bitbucket Server 4.14.1 so there may have been a change in the API, although I don't see anything relevant in their documentation. I have opened a PR with a potential fix.

ar613 commented

Also worth mentioning, the 4.14.1 server I tried it on has Git 2.9.3 and the 5.1.0 has 2.9.4. I don't see anything obvious in the 2.9.4 release notes though.