alexcouper / captainhook

Git hook scripts
BSD 3-Clause "New" or "Revised" License
54 stars 14 forks source link

Fix bug with blocked branch in Python 3 #117

Closed browniebroke closed 7 years ago

browniebroke commented 7 years ago

Currently, the check to block branches doesn't work on Python 3:

Traceback (most recent call last):
[...]
  File "/.../captainhook/checkers/block_branches.py", line 16, in run
    current_branch = bash('git symbolic-ref HEAD').value().decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'

The value returned by bash.value() is already decoded as UTF-8.

In Python 2, all of this work:

>>> b"test".decode('utf-8')
u'test'
>>> "test".decode('utf-8')
u'test'
>>> u"test".decode('utf-8')
u'test'
>>> "test".decode('utf-8').decode('utf-8')
u'test'

Whereas in Python 3:

>>> b"test".decode('utf-8')
'test'
>>> "test".decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'
>>> b"test".decode('utf-8').decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'