Diff shows a_path even though the file is added
When a file is added, I think that a_path should be None and b_path should be equal to the name of the added file. This is the case when we create a diff setting create_patch=True. However, since by default this is False, diff returns a_path and b_path equals to the name of the added file. If you want to test it:
mkdir test
cd test
git init
touch asd.txt
git add asd.txt
git commit -m "add asd"
cd ..
import git
repo = git.Repo('test/')
diffs = repo.head.commit.diff(git.NULL_TREE)
for diff in diffs:
print(diff.a_path)
print(diff.b_path)
print(diff.change_type)
this will return the following output:
asd.txt
asd.txt
A
how is it possible that, if the file is added, a_path is not None?
PS: this works also if the previous commit is not NULL_TREE, already tried.
Thanks a lot for letting us know, I just reproduced the issue! This is not the first issue discovered related to the diffing logic/code.
Note that this behavior is currently contrary to the documentation: https://gitpython.readthedocs.io/en/stable/reference.html#git.diff.Diff This lead to quite a bit of confusion for us when trying to use this function.
@vidartf Thanks for letting me know! Maybe you can find the time to provide a PR adjusting the docs so that it becomes what you would have wanted to see. Generally, the diff implementation is confusing to many, and I am not quite sure if it's the API itself, the docs, or an incorrect implementation