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

Existance of patchdescr.tmpl causes TypeError #87

Closed
tyhoff opened this issue Nov 24, 2020 · 1 comment
Closed

Existance of patchdescr.tmpl causes TypeError #87

tyhoff opened this issue Nov 24, 2020 · 1 comment

Comments

@tyhoff
Copy link

tyhoff commented Nov 24, 2020

Issue:

Having a patchdescr.tmpl causes stg new to fail with a Python exception.

$ stg new test
Error: Unhandled exception:
Traceback (most recent call last):
  File "/Users/tyler/miniforge3/envs/memfault/lib/python3.6/site-packages/stgit/main.py", line 188, in _main
    ret = command.func(parser, options, args)
  File "/Users/tyler/miniforge3/envs/memfault/lib/python3.6/site-packages/stgit/commands/new.py", line 87, in func
    edit=(not options.save_template and options.message is None),
  File "/Users/tyler/miniforge3/envs/memfault/lib/python3.6/site-packages/stgit/commands/common.py", line 471, in update_commit_data
    cd = cd.set_message(cd.message + tmpl)
TypeError: can't concat str to bytes

Current environment:

$ stg --version
Stacked GIT 0.23-45-gb4eb-dirty
git version 2.24.3 (Apple Git-128)
Python version 3.6.9 | packaged by conda-forge | (default, Mar  6 2020, 19:19:02)
[GCC Clang 9.0.1 ]

I've also re-produced this issue with brew install stgitwhich uses python@3.9, as well as on an older version of stgit 0.22.

Fix

The fix should just be to use cd.message_str instead of cd.message.

diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 1fd50ce..b39f7a3 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -466,7 +466,7 @@ def update_commit_data(cd, message=None, author=None, sign_str=None, edit=False)
     if edit:
         tmpl = templates.get_template('patchdescr.tmpl')
         if tmpl:
-            cd = cd.set_message(cd.message + tmpl)
+            cd = cd.set_message(cd.message_str + tmpl)
         cd = cd.set_message(edit_bytes(cd.message, '.stgit-new.txt'))

     return cd

After patching this, using a template stored in .git/patchdescr.tmpl works again.

I apologize in advance for not putting up a fix myself.

jpgrayson added a commit that referenced this issue Dec 7, 2020
When a user-provided patchdescr.tmpl is present, `stg new` would crash
with a TypeError due to a str/bytes mismatch.

Repairs #87.

Signed-off-by: Peter Grayson <pete@jpgrayson.net>
@jpgrayson
Copy link
Collaborator

Thanks for this issue report and proposed fix! I've pushed the repair along with a new test for this problem in 93c9073.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants