Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-commit-to-branch on CI #265

Closed
hectorv opened this issue Feb 19, 2018 · 4 comments
Closed

no-commit-to-branch on CI #265

hectorv opened this issue Feb 19, 2018 · 4 comments
Labels

Comments

@hectorv
Copy link

hectorv commented Feb 19, 2018

As a safety net, we've started running pre-commit on CI, e.g.

git diff --name-only "$GIT_COMMIT"^..."$GIT_COMMIT" | xargs pre-commit run --files

one of our projects uses no-commit-to-branch and we just noticed this behavior on CI:

Don't commit to branch...................................................Failed
hookid: no-commit-to-branch

Traceback (most recent call last):
  File "/var/lib/jenkins/.cache/pre-commit/repoVUdrA6/py_env-python2.7/bin/no-commit-to-branch", line 11, in <module>
    load_entry_point('pre-commit-hooks==1.1.0', 'console_scripts', 'no-commit-to-branch')()
  File "/var/lib/jenkins/.cache/pre-commit/repoVUdrA6/py_env-python2.7/local/lib/python2.7/site-packages/pre_commit_hooks/no_commit_to_branch.py", line 22, in main
    return int(is_on_branch(args.branch))
  File "/var/lib/jenkins/.cache/pre-commit/repoVUdrA6/py_env-python2.7/local/lib/python2.7/site-packages/pre_commit_hooks/no_commit_to_branch.py", line 10, in is_on_branch
    branch = cmd_output('git', 'symbolic-ref', 'HEAD')
  File "/var/lib/jenkins/.cache/pre-commit/repoVUdrA6/py_env-python2.7/local/lib/python2.7/site-packages/pre_commit_hooks/util.py", line 28, in cmd_output
    raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
pre_commit_hooks.util.CalledProcessError: (('git', 'symbolic-ref', 'HEAD'), 0, 128, u'', u'fatal: ref HEAD is not a symbolic ref\n')

most likely this is not really an issue with pre-commit but with the way our Jenkins jobs are set up (?). I worked around this by using SKIP=no-commit-to-branch pre-commit run but just thought I would let you know.

@asottile
Copy link
Member

Thanks for the report! Looks like this hook false-positives when not on a branch (as is likely in CI).

I'll add a quick check for that :)

@asottile
Copy link
Member

This has been released as part of v1.2.1!

@JulianVolodia
Copy link

Hi @asottile I try to understand how no-commit-to-branch should work duing CI on BitBucket.

I have 2 pipelines. Test and deploy.
For any PR - test is running.
For merges to develop - test and then deploy.

I struggle when have no-commit-to-branch hook on test pipeline. It blocking commits to develop/master but likely dislike this too.

https://github.com/pre-commit/pre-commit-hooks#no-commit-to-branch says only about branches but --no-ff merges are commits and pipelines think they are.

Do You have any thoughts about how this workflow with specific hook should be done?

Thanks in advance for any response.

@asottile
Copy link
Member

asottile commented Mar 8, 2021

@JulianVolodia your question is unrelated to this issue -- in the future I'd encourage you to create a new issue for unrelated things

if it doesn't apply in some scenario you can always utilize SKIP

(locking because off-topic)

@pre-commit pre-commit locked as off-topic and limited conversation to collaborators Mar 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants