difflame icon indicating copy to clipboard operation
difflame copied to clipboard

Deleting an empty file causes an unhandled exception

Open joanise opened this issue 1 year ago • 0 comments

Hi! This is a really cool tool, I just found out about it reading a question on StackOverflow. Trying to use it on one of my projects, however, I found it didn't work, and I have now figured out why: if a commit deletes an empty file, the script aborts with an unhandled exception.

To reproduce:

touch empty
git add empty
git commit -m empty
git rm empty
git commit -m rm-empty
./difflame.py HEAD^ HEAD

Output:

fatal: no such path empty in 2dbfc2d38350b66b673c0bc841c3b10349dd44ef
Traceback (most recent call last):
  File "C:\Users\me\sandboxes\difflame\difflame.py", line 1156, in <module>
    process_diff_output(diff_output, treeish1, treeish2)
  File "C:\Users\me\sandboxes\difflame\difflame.py", line 991, in process_diff_output
    diff_file_object.process(reverse)
  File "C:\Users\me\sandboxes\difflame\difflame.py", line 320, in process
    final_file_blame = self.getFinalFileBlame(reverse)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\sandboxes\difflame\difflame.py", line 244, in getFinalFileBlame
    return self.get_blame_info_hunk(False, reverse).split("\n")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\sandboxes\difflame\difflame.py", line 307, in get_blame_info_hunk
    return run_git_blame(git_blame_opts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\sandboxes\difflame\difflame.py", line 80, in run_git_blame
    return run_git_command(args)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\sandboxes\difflame\difflame.py", line 66, in run_git_command
    result = subprocess.check_output(command)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\miniconda3\Lib\subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\miniconda3\Lib\subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'blame', '--no-progress', '--line-porcelain', '2dbfc2d38350b66b673c0bc841c3b10349dd44ef', '--', 'empty']' returned non-zero exit status 128.

By contrast, deleting a non-empty file does not cause any errors.

Use case: in Python repos, it's common to have an empty __init__.py file to make a directory a module, and I faced this problem over a commit that deleted such a module.

joanise avatar Jul 25 '24 18:07 joanise