Skip to content

🐛 Relint 3.4.0 throws ValueError #133

@amureki

Description

@amureki

Bug Description

Hey there 👋 ,

I tried to update to 3.4.0, but it started to fail with a git config: diff.mnemonicprefix=true (makes diffs more informative, and I find it quite useful).

The default is false, but devs tend to change their configs. ;-)

So, for example, with diff.mnemonicPrefix=true, git diff --staged emits:

 diff --git c/sql/very-important-sql.sql i/sql/very-important-sql.sql

not:

 diff --git a/sql/very-important-sql.sql b/sql/very-important-sql.sql

And then parse_filenames(output) returns [], so zip([], [content], strict=True) raises ValueError: zip() argument 2 is longer than argument 1

Expected Behavior

I don't know what your preference would be. We either:

  • run git as:
 git -c diff.mnemonicPrefix=false diff --staged --unified=0 --no-color

or:

  • make the regex accept arbitrary prefixes:
 r"(?:\n|^)diff --git [^/]+\/.* [^/]+\/(.*)(?:\n|$)"

or maybe specifically:

 r"(?:\n|^)diff --git [abciow]\/.* [abciow]\/(.*)(?:\n|$)"

But the main note here is that relint should not be affected (breaking) when developers change their git config.

Version

3.4.0

Stack trace

relint...................................................................Failed
- hook id: relint
- exit code: 1

Linting files... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
  Traceback (most recent call last):
    File "/Users/x/.cache/prek/hooks/python-riKASiZavfmpHkWvpBpB/bin/relint", line 10, in <module>
      sys.exit(main())
               ~~~~^^
    File "/Users/x/.cache/prek/hooks/python-riKASiZavfmpHkWvpBpB/lib/python3.14/site-packages/relint/__main__.py", line 99, in main
      changed_content = parse_diff(output)
    File "/Users/x/.cache/prek/hooks/python-riKASiZavfmpHkWvpBpB/lib/python3.14/site-packages/relint/parse.py", line 213, in parse_diff
      for filename, content in split_diff_content_by_filename(output).items():
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
    File "/Users/x/.cache/prek/hooks/python-riKASiZavfmpHkWvpBpB/lib/python3.14/site-packages/relint/parse.py", line 91, in split_diff_content_by_filename
      for filename, content in zip(filenames, split_content, strict=True):
                               ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ValueError: zip() argument 2 is longer than argument 1

Steps to Reproduce

Have diff.mnemonicprefix=true set in your git config.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions